/* -*- 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 PagodaPathPricer : public PathPricer { public: PagodaPathPricer(Real roof, Real fraction, DiscountFactor discount) : roof_(roof), fraction_(fraction), discount_(discount) {} Real operator()(const MultiPath& multiPath) const { Size numAssets = multiPath.assetNumber(); Size numSteps = multiPath.pathSize(); Real averageGain = 0.0; for (Size i = 1; i < numSteps; i++) { for (Size j = 0; j < numAssets; j++) { averageGain += multiPath[j].front() * (multiPath[j][i]/multiPath[j][i-1] - 1.0); } } averageGain /= numAssets; return discount_ * fraction_ * std::max(0.0, std::min(roof_, averageGain)); } private: Real roof_, fraction_; DiscountFactor discount_; }; } McPagoda::McPagoda( const std::vector& underlying, Real fraction, Real roof, const std::vector >& dividendYield, const Handle& riskFreeRate, const std::vector >& volatilities, const Matrix& correlation, const std::vector