/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2002, 2003 Ferdinando Ametrano 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 PerformanceOptionPathPricer : public PathPricer { public: PerformanceOptionPathPricer( Option::Type type, Real moneyness, const std::vector& discounts) : discounts_(discounts), payoff_(type, moneyness) { QL_REQUIRE(moneyness>0.0, "moneyness less/equal zero not allowed"); } Real operator()(const Path& path) const { Size n = path.length(); QL_REQUIRE(n>1, "at least one option is required"); QL_REQUIRE(n==3, "only one option for the time being"); QL_REQUIRE(n==discounts_.size()+1, "discounts/options mismatch"); std::vector result(n-1); std::vector assetValue(n-1); assetValue[0] = path[1]; // removing first option result[0] = 0.0; for (Size i = 1 ; i < n-1; i++) { assetValue[i] = path[i+1]; result[i] = discounts_[i] * payoff_(assetValue[i]/assetValue[i-1]); } return result[1]; } private: std::vector discounts_; PlainVanillaPayoff payoff_; }; } McPerformanceOption::McPerformanceOption( Option::Type type, Real underlying, Real moneyness, const Handle& dividendYield, const Handle& riskFreeRate, const Handle& volatility, const std::vector