1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 3 /* 4 5 Copyright (C) 2008 Mark Joshi 6 7 This file is part of QuantLib, a free-software/open-source library 8 for financial quantitative analysts and developers - http://quantlib.org/ 9 10 QuantLib is free software: you can redistribute it and/or modify it 11 under the terms of the QuantLib license. You should have received a 12 copy of the license along with this program; if not, please email 13 <quantlib-dev@lists.sf.net>. The license is also available online at 14 <http://quantlib.org/license.shtml>. 15 16 This program is distributed in the hope that it will be useful, but WITHOUT 17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the license for more details. 19 */ 20 21 22 #ifndef quantlib_rate_pseudo_root_hpp 23 #define quantlib_rate_pseudo_root_hpp 24 25 // to be removed using forward declaration 26 27 28 #include <ql/models/marketmodels/driftcomputation/lmmdriftcalculator.hpp> 29 30 /*! Classes for computing derivative of the map taking rates one step 31 to the next with respect to a change in the pseudo-root. We do it both 32 numerically and analytically to provide an easy test of the analytic method. 33 This is useful for pathwise vegas. 34 35 Evolution is log Euler. 36 37 One is tested against the other in MarketModelTest::testPathwiseVegas 38 */ 39 40 namespace QuantLib 41 { 42 43 class RatePseudoRootJacobianNumerical 44 { 45 public: 46 RatePseudoRootJacobianNumerical(const Matrix& pseudoRoot, 47 Size aliveIndex, 48 Size numeraire, 49 const std::vector<Time>& taus, 50 const std::vector<Matrix>& pseudoBumps, 51 const std::vector<Spread>& displacements); 52 53 void getBumps(const std::vector<Rate>& oldRates, 54 const std::vector<Real>& oneStepDFs, // redundant info but saves time to pass in since will have been needed elsewhere 55 const std::vector<Rate>& newRates, // redundant info but saves time to pass in since will have been needed elsewhere 56 const std::vector<Real>& gaussians, 57 Matrix& B); // B as in page 95 of the GG paper, rows should be number rates long, one row for bump 58 59 private: 60 61 //! this data is always the same 62 Matrix pseudoRoot_; 63 Size aliveIndex_; 64 std::vector<Time> taus_; 65 std::vector<Matrix> pseudoBumped_; 66 std::vector<Spread> displacements_; 67 Size numberBumps_; 68 std::vector<LMMDriftCalculator> driftsComputers_; 69 Size factors_; 70 71 //! workspace variables 72 std::vector<Real> drifts_; 73 std::vector<Real> bumpedRates_; 74 75 }; 76 77 78 79 80 class RatePseudoRootJacobian 81 { 82 public: 83 RatePseudoRootJacobian(const Matrix& pseudoRoot, 84 Size aliveIndex, 85 Size numeraire, 86 const std::vector<Time>& taus, 87 const std::vector<Matrix>& pseudoBumps, 88 const std::vector<Spread>& displacements); 89 90 void getBumps(const std::vector<Rate>& oldRates, 91 const std::vector<Real>& oneStepDFs, // redundant info but saves time to pass in since will have been needed elsewhere 92 const std::vector<Rate>& newRates, // redundant info but saves time to pass in since will have been needed elsewhere 93 const std::vector<Real>& gaussians, 94 Matrix& B); // B as in page 95 of the GG paper, rows should be number rates long, one row for each bump 95 96 private: 97 98 //! this data does not change after construction 99 Matrix pseudoRoot_; 100 Size aliveIndex_; 101 std::vector<Time> taus_; 102 std::vector<Matrix> pseudoBumps_; 103 std::vector<Spread> displacements_; 104 Size numberBumps_; 105 Size factors_; 106 107 //! workspace variables 108 109 std::vector<Matrix> allDerivatives_; 110 // std::vector<Real> bumpedRates_; 111 Matrix e_; 112 std::vector<Real> ratios_; 113 114 }; 115 116 117 class RatePseudoRootJacobianAllElements 118 { 119 public: 120 RatePseudoRootJacobianAllElements(const Matrix& pseudoRoot, 121 Size aliveIndex, 122 Size numeraire, 123 const std::vector<Time>& taus, 124 const std::vector<Spread>& displacements); 125 126 void getBumps(const std::vector<Rate>& oldRates, 127 const std::vector<Real>& oneStepDFs, // redundant info but saves time to pass in since will have been needed elsewhere 128 const std::vector<Rate>& newRates, // redundant info but saves time to pass in since will have been needed elsewhere 129 const std::vector<Real>& gaussians, 130 std::vector<Matrix>& B); // one Matrix for each rate, the elements of the matrix are the derivatives of that rate with respect to each pseudo-root element 131 132 private: 133 134 //! this data does not change after construction 135 Matrix pseudoRoot_; 136 Size aliveIndex_; 137 std::vector<Time> taus_; 138 std::vector<Matrix> pseudoBumps_; 139 std::vector<Spread> displacements_; 140 Size factors_; 141 142 //! workspace 143 144 Matrix e_; 145 std::vector<Real> ratios_; 146 147 }; 148 149 } 150 151 #endif 152