1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2006 Mark Joshi 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 #ifndef quantlib_longstaff_schwartz_exercise_strategy_hpp 21 #define quantlib_longstaff_schwartz_exercise_strategy_hpp 22 23 #include <ql/methods/montecarlo/exercisestrategy.hpp> 24 #include <ql/models/marketmodels/callability/marketmodelbasissystem.hpp> 25 #include <ql/models/marketmodels/callability/exercisevalue.hpp> 26 #include <ql/utilities/clone.hpp> 27 28 namespace QuantLib { 29 30 class MarketModelDiscounter; 31 32 class LongstaffSchwartzExerciseStrategy 33 : public ExerciseStrategy<CurveState> { 34 public: 35 LongstaffSchwartzExerciseStrategy( 36 const Clone<MarketModelBasisSystem>& basisSystem, 37 const std::vector<std::vector<Real> >& basisCoefficients, 38 const EvolutionDescription& evolution, 39 const std::vector<Size>& numeraires, 40 const Clone<MarketModelExerciseValue>& exercise, 41 const Clone<MarketModelExerciseValue>& control); 42 std::vector<Time> exerciseTimes() const; 43 std::vector<Time> relevantTimes() const; 44 void reset(); 45 bool exercise(const CurveState& currentState) const; 46 void nextStep(const CurveState& currentState); 47 #if defined(QL_USE_STD_UNIQUE_PTR) 48 std::unique_ptr<ExerciseStrategy<CurveState> > clone() const; 49 #else 50 std::auto_ptr<ExerciseStrategy<CurveState> > clone() const; 51 #endif 52 private: 53 Clone<MarketModelBasisSystem> basisSystem_; 54 std::vector<std::vector<Real> > basisCoefficients_; 55 Clone<MarketModelExerciseValue> exercise_; 56 Clone<MarketModelExerciseValue> control_; 57 std::vector<Size> numeraires_; 58 // work variable 59 Size currentIndex_; 60 Real principalInNumerairePortfolio_, newPrincipal_; 61 std::vector<Time> exerciseTimes_, relevantTimes_; 62 std::valarray<bool> isBasisTime_, isRebateTime_, isControlTime_; 63 std::valarray<bool> isExerciseTime_; 64 std::vector<MarketModelDiscounter> rebateDiscounters_; 65 std::vector<MarketModelDiscounter> controlDiscounters_; 66 mutable std::vector<std::vector<Real> > basisValues_; 67 std::vector<Size> exerciseIndex_; 68 }; 69 70 } 71 72 73 #endif 74