/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ #include #include #include #include namespace QuantLib { namespace { class ArithmeticASOPathPricer : public PathPricer { public: ArithmeticASOPathPricer(Option::Type type, DiscountFactor discount) : type_(type), discount_(discount) {} Real operator()(const Path& path) const { Size n = path.length(); QL_REQUIRE(n > 1, "the path cannot be empty"); Real averageStrike; if (path.timeGrid().mandatoryTimes()[0]==0.0) { // include initial fixing averageStrike = std::accumulate(path.begin(),path.end(),0.0)/n; } else { averageStrike = std::accumulate(path.begin()+1,path.end(),0.0)/(n-1); } return discount_ * PlainVanillaPayoff(type_, averageStrike)(path.back()); } private: Option::Type type_; DiscountFactor discount_; }; class GeometricASOPathPricer : public PathPricer { public: GeometricASOPathPricer(Option::Type type, DiscountFactor discount) : type_(type), discount_(discount) {} Real operator()(const Path& path) const { Size n = path.length(); QL_REQUIRE(n>1, "the path cannot be empty"); Size fixings = n-1; if (path.timeGrid().mandatoryTimes()[0]==0.0) fixings = n; Real averageStrike = 1.0; Real maxValue = QL_MAX_REAL; Real product = 1.0; if (path.timeGrid().mandatoryTimes()[0]==0.0) product = path.front(); for (Size i=1; i& dividendYield, const Handle& riskFreeRate, const Handle& volatility, const std::vector