1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 Copyright (C) 2006, 2007 Ferdinando Ametrano 5 Copyright (C) 2006 Chiara Fornarola 6 Copyright (C) 2006, 2007 StatPro Italia srl 7 Copyright (C) 2006 Katiuscia Manzoni 8 9 This file is part of QuantLib, a free-software/open-source library 10 for financial quantitative analysts and developers - http://quantlib.org/ 11 12 QuantLib is free software: you can redistribute it and/or modify it 13 under the terms of the QuantLib license. You should have received a 14 copy of the license along with this program; if not, please email 15 <quantlib-dev@lists.sf.net>. The license is also available online at 16 <http://quantlib.org/license.shtml>. 17 18 This program is distributed in the hope that it will be useful, but WITHOUT 19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20 FOR A PARTICULAR PURPOSE. See the license for more details. 21 */ 22 23 24 #ifndef quantlib_exp_corr_flat_vol_hpp 25 #define quantlib_exp_corr_flat_vol_hpp 26 27 #include <ql/models/marketmodels/marketmodel.hpp> 28 #include <ql/models/marketmodels/evolutiondescription.hpp> 29 #include <ql/math/matrix.hpp> 30 #include <ql/math/interpolation.hpp> 31 #include <ql/termstructures/yieldtermstructure.hpp> 32 #include <ql/handle.hpp> 33 #include <vector> 34 35 namespace QuantLib { 36 37 class PiecewiseConstantCorrelation; 38 39 class FlatVol : public MarketModel { 40 public: 41 FlatVol( 42 const std::vector<Volatility>& volatilities, 43 const ext::shared_ptr<PiecewiseConstantCorrelation>& corr, 44 const EvolutionDescription& evolution, 45 Size numberOfFactors, 46 const std::vector<Rate>& initialRates, 47 const std::vector<Spread>& displacements); 48 //! \name MarketModel interface 49 //@{ 50 const std::vector<Rate>& initialRates() const; 51 const std::vector<Spread>& displacements() const; 52 const EvolutionDescription& evolution() const; 53 Size numberOfRates() const; 54 Size numberOfFactors() const; 55 Size numberOfSteps() const; 56 const Matrix& pseudoRoot(Size i) const; 57 //@} 58 private: 59 Size numberOfFactors_, numberOfRates_, numberOfSteps_; 60 std::vector<Rate> initialRates_; 61 std::vector<Spread> displacements_; 62 EvolutionDescription evolution_; 63 std::vector<Matrix> pseudoRoots_; 64 }; 65 66 class FlatVolFactory : public MarketModelFactory, 67 public Observer { 68 public: 69 FlatVolFactory(Real longTermCorrelation, 70 Real beta, 71 // this is just to make it work---it 72 // should be replaced with something 73 // else (such as some kind of volatility 74 // structure) 75 const std::vector<Time>& times, 76 const std::vector<Volatility>& vols, 77 // this is OK 78 const Handle<YieldTermStructure>& yieldCurve, 79 // this might have a structure 80 Spread displacement); 81 ext::shared_ptr<MarketModel> create(const EvolutionDescription&, 82 Size numberOfFactors) const; 83 void update(); 84 private: 85 Real longTermCorrelation_, beta_; 86 // <to be changed> 87 std::vector<Time> times_; 88 std::vector<Volatility> vols_; 89 Interpolation volatility_; 90 // </to be changed> 91 Handle<YieldTermStructure> yieldCurve_; 92 Spread displacement_; 93 }; 94 95 96 // inline definitions 97 initialRates() const98 inline const std::vector<Rate>& FlatVol::initialRates() const { 99 return initialRates_; 100 } 101 displacements() const102 inline const std::vector<Spread>& FlatVol::displacements() const { 103 return displacements_; 104 } 105 evolution() const106 inline const EvolutionDescription& FlatVol::evolution() const { 107 return evolution_; 108 } 109 numberOfRates() const110 inline Size FlatVol::numberOfRates() const { 111 return initialRates_.size(); 112 } 113 numberOfFactors() const114 inline Size FlatVol::numberOfFactors() const { 115 return numberOfFactors_; 116 } 117 numberOfSteps() const118 inline Size FlatVol::numberOfSteps() const { 119 return numberOfSteps_; 120 } 121 pseudoRoot(Size i) const122 inline const Matrix& FlatVol::pseudoRoot(Size i) const { 123 QL_REQUIRE(i<numberOfSteps_, 124 "the index " << i << " is invalid: it must be less than " 125 "number of steps (" << numberOfSteps_ << ")"); 126 return pseudoRoots_[i]; 127 } 128 } 129 130 #endif 131