QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
gsrprocesscore.hpp
Go to the documentation of this file.
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>
33#include <map>
34
35namespace QuantLib::detail {
36
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:
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_,
85 mutable std::map<Real, Real> cache4_;
87 mutable std::vector<bool> revZero_;
88}; // GsrProcessCore
89
90// inline definitions
91
92inline Real GsrProcessCore::sigma(const Time t) const {
93 return vol(lowerIndex(t));
94}
95
96inline Real GsrProcessCore::reversion(const Time t) const {
97 return rev(lowerIndex(t));
98}
99
100} // namespace QuantLib
101
102#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
template class providing a null value for a given type.
Definition: null.hpp:59
Real cappedTime(Size index, Real cap=Null< Real >()) const
Real expectation_x0dep_part(Time w, Real xw, Time dt) const
std::map< Real, Real > cache4_
Real expectation_rn_part(Time w, Time dt) const
Real flooredTime(Size index, Real floor=Null< Real >()) const
std::map< std::pair< Real, Real >, Real > cache2a_
Real expectation_tf_part(Time w, Time dt) const
std::map< std::pair< Real, Real >, Real > cache1_
bool revZero(Size index) const
std::map< std::pair< Real, Real >, Real > cache2b_
std::map< std::pair< Real, Real >, Real > cache3_
Real G(Time t, Time w) const
std::map< std::pair< Real, Real >, Real > cache5_
floating-point comparisons
const DefaultType & t
LinearInterpolation variance
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Real sigma