| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2013, 2015 Peter Caspers |
| 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 | /*! \file gsrprocess.hpp |
| 21 | \brief GSR model process with piecewise volatilities and mean reversions, |
| 22 | the dynamic is expressed in some T-forward measure. |
| 23 | If a single value for the mean reversion is provided, it is assumed |
| 24 | constant. Results are cached for performance reasons, so if parameters |
| 25 | change you need to call flushCache() to avoid inconsistent results. |
| 26 | For a derivation of the formulas, see http://ssrn.com/abstract=2246013 |
| 27 | */ |
| 28 | |
| 29 | #ifndef quantlib_gsr_process_hpp |
| 30 | #define quantlib_gsr_process_hpp |
| 31 | |
| 32 | #include <ql/processes/forwardmeasureprocess.hpp> |
| 33 | #include <ql/processes/gsrprocesscore.hpp> |
| 34 | #include <ql/time/daycounter.hpp> |
| 35 | |
| 36 | namespace QuantLib { |
| 37 | |
| 38 | //! GSR stochastic process |
| 39 | /*! \ingroup processes */ |
| 40 | class GsrProcess : public ForwardMeasureProcess1D { |
| 41 | public: |
| 42 | GsrProcess(const Array& times, |
| 43 | const Array& vols, |
| 44 | const Array& reversions, |
| 45 | Real T = 60.0, |
| 46 | const Date& referenceDate = Null<Date>(), |
| 47 | DayCounter dc = DayCounter()); |
| 48 | //! \name StochasticProcess1D interface |
| 49 | //@{ |
| 50 | Real x0() const override; |
| 51 | Real drift(Time t, Real x) const override; |
| 52 | Real diffusion(Time t, Real) const override; |
| 53 | Real expectation(Time t0, Real x0, Time dt) const override; |
| 54 | Real stdDeviation(Time t0, Real x0, Time dt) const override; |
| 55 | Real variance(Time t0, Real, Time dt) const override; |
| 56 | Real time(const Date& d) const override; |
| 57 | //@} |
| 58 | //! \name ForwardMeasureProcess1D interface |
| 59 | void setForwardMeasureTime(Time t) override; |
| 60 | //@} |
| 61 | //! additional inspectors |
| 62 | Real sigma(Time t) const; |
| 63 | Real reversion(Time t) const; |
| 64 | Real y(Time t) const; |
| 65 | Real G(Time t, Time T, Real x) const; |
| 66 | //! reset cache |
| 67 | void flushCache() const; |
| 68 | |
| 69 | private: |
| 70 | void checkT(Time t) const; |
| 71 | const detail::GsrProcessCore core_; |
| 72 | Date referenceDate_; |
| 73 | DayCounter dc_; |
| 74 | }; |
| 75 | |
| 76 | // inline definitions |
| 77 | |
| 78 | inline void GsrProcess::setForwardMeasureTime(Time t) { |
| 79 | flushCache(); |
| 80 | ForwardMeasureProcess1D::setForwardMeasureTime(t); |
| 81 | } |
| 82 | |
| 83 | inline void GsrProcess::flushCache() const { |
| 84 | core_.flushCache(); |
| 85 | } |
| 86 | |
| 87 | } // namesapce QuantLib |
| 88 | |
| 89 | #endif |
| 90 | |