/src/quantlib/ql/processes/gsrprocesscore.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 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 gsrprocesscore.hpp |
21 | | \brief Core computations for the gsr process in risk neutral |
22 | | and T-forward measure. |
23 | | \warning Results are cached for performance reasons, so if |
24 | | parameters change, you need to call flushCache() to |
25 | | avoid inconsistent results. |
26 | | */ |
27 | | |
28 | | #ifndef quantlib_gsr_process_core_hpp |
29 | | #define quantlib_gsr_process_core_hpp |
30 | | |
31 | | #include <ql/math/array.hpp> |
32 | | #include <ql/math/comparison.hpp> |
33 | | #include <map> |
34 | | |
35 | | namespace QuantLib::detail { |
36 | | |
37 | | class GsrProcessCore { |
38 | | public: |
39 | | GsrProcessCore(const Array& times, const Array& vols, const Array& reversions, Real T = 60.0); |
40 | | |
41 | | // conditional expectation, x0 dependent part |
42 | | Real expectation_x0dep_part(Time w, Real xw, Time dt) const; |
43 | | |
44 | | // conditional expectation, x0 independent part |
45 | | // in the risk neutral measure |
46 | | Real expectation_rn_part(Time w, Time dt) const; |
47 | | |
48 | | // conditional expectation, drift adjustment for |
49 | | // the T-forward measure |
50 | | Real expectation_tf_part(Time w, Time dt) const; |
51 | | |
52 | | // conditional variance |
53 | | Real variance(Time w, Time dt) const; |
54 | | |
55 | | // y(t) |
56 | | Real y(Time t) const; |
57 | | |
58 | | // G(t,w) |
59 | | Real G(Time t, Time w) const; |
60 | | |
61 | | // sigma |
62 | | Real sigma(Time t) const; |
63 | | |
64 | | // reversion |
65 | | Real reversion(Time t) const; |
66 | | |
67 | | // reset cache |
68 | | void flushCache() const; |
69 | | |
70 | | protected: |
71 | | const Array ×_, &vols_, &reversions_; |
72 | | |
73 | | private: |
74 | | int lowerIndex(Time t) const; |
75 | | int upperIndex(Time t) const; |
76 | | Real time2(Size index) const; |
77 | | Real cappedTime(Size index, Real cap = Null<Real>()) const; |
78 | | Real flooredTime(Size index, Real floor = Null<Real>()) const; |
79 | | Real vol(Size index) const; |
80 | | Real rev(Size index) const; |
81 | | bool revZero(Size index) const; |
82 | | |
83 | | mutable std::map<std::pair<Real, Real>, Real> cache1_, cache2a_, cache2b_, |
84 | | cache3_, cache5_; |
85 | | mutable std::map<Real, Real> cache4_; |
86 | | Time T_; |
87 | | mutable std::vector<bool> revZero_; |
88 | | }; // GsrProcessCore |
89 | | |
90 | | // inline definitions |
91 | | |
92 | 0 | inline Real GsrProcessCore::sigma(const Time t) const { |
93 | 0 | return vol(lowerIndex(t)); |
94 | 0 | } |
95 | | |
96 | 0 | inline Real GsrProcessCore::reversion(const Time t) const { |
97 | 0 | return rev(lowerIndex(t)); |
98 | 0 | } |
99 | | |
100 | | } // namespace QuantLib |
101 | | |
102 | | #endif |