1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2008 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_square_root_andersen_hpp 21 #define quantlib_square_root_andersen_hpp 22 23 #include <ql/models/marketmodels/evolvers/marketmodelvolprocess.hpp> 24 25 namespace QuantLib 26 { 27 28 29 /*! 30 Displaced diffusion LMM with uncorrelated vol process. Called "Shifted BGM" with Heston vol by Brace in "Engineering BGM." 31 Vol process is an external input. 32 33 */ 34 class SquareRootAndersen : public MarketModelVolProcess 35 { 36 public: 37 SquareRootAndersen(Real meanLevel, 38 Real reversionSpeed, 39 Real volVar, 40 Real v0, 41 const std::vector<Real>& evolutionTimes, 42 Size numberSubSteps_, 43 Real w1, 44 Real w2, 45 Real cutPoint = 1.5); 46 47 virtual Size variatesPerStep(); 48 virtual Size numberSteps(); 49 50 virtual void nextPath(); 51 virtual Real nextstep(const std::vector<Real>& variates); 52 virtual Real stepSd() const ; 53 54 virtual const std::vector<Real>& stateVariables() const; 55 virtual Size numberStateVariables() const; 56 57 private: 58 59 void DoOneSubStep(Real& v, Real variate, Size j); 60 61 Real theta_; // mean level 62 63 Real k_; // reversion speed 64 Real epsilon_; // volvar 65 66 Real v0_; // initial value of instantaneous variance 67 Size numberSubSteps_; // sub steps per evolution time 68 69 70 std::vector<Real> dt_; // time step lengths 71 std::vector<Real> eMinuskDt_; // exp( - k * dt) 72 73 Real w1_; // weights to use for computing variance across step 74 Real w2_; 75 Real PsiC_; // cut-off between two types of evolution 76 77 //! evolving values 78 Real v_; 79 Size currentStep_; 80 Size subStep_; 81 std::vector<Real> vPath_; 82 83 mutable std::vector<Real> state_; 84 85 }; 86 87 } 88 89 #endif 90