1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2008 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis 5 6 This file is part of QuantLib, a free-software/open-source library 7 for financial quantitative analysts and developers - http://quantlib.org/ 8 9 QuantLib is free software: you can redistribute it and/or modify it 10 under the terms of the QuantLib license. You should have received a 11 copy of the license along with this program; if not, please email 12 <quantlib-dev@lists.sf.net>. The license is also available online at 13 <http://quantlib.org/license.shtml>. 14 15 This program is distributed in the hope that it will be useful, but WITHOUT 16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 FOR A PARTICULAR PURPOSE. See the license for more details. 18 */ 19 20 #include <ql/experimental/exoticoptions/mceverestengine.hpp> 21 22 namespace QuantLib { 23 EverestMultiPathPricer(Real notional,Real guarantee,DiscountFactor discount)24 EverestMultiPathPricer::EverestMultiPathPricer(Real notional, 25 Real guarantee, 26 DiscountFactor discount) 27 : notional_(notional), guarantee_(guarantee), discount_(discount) {} 28 operator ()(const MultiPath & multiPath) const29 Real EverestMultiPathPricer::operator()(const MultiPath& multiPath) const { 30 31 Size n = multiPath.pathSize(); 32 QL_REQUIRE(n>0, "the path cannot be empty"); 33 34 Size numAssets = multiPath.assetNumber(); 35 QL_REQUIRE(numAssets>0, "there must be some paths"); 36 37 // We search the yield min 38 Real minYield = multiPath[0].back() / multiPath[0].front() - 1.0; 39 for (Size j=1; j<numAssets; ++j) { 40 Rate yield = multiPath[j].back() / multiPath[j].front() - 1.0; 41 minYield = std::min(minYield, yield); 42 } 43 return (1.0 + minYield + guarantee_) * notional_ * discount_; 44 } 45 46 } 47 48