QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 {
36
37namespace detail {
38
40 public:
41 GsrProcessCore(const Array& times, const Array& vols, const Array& reversions, Real T = 60.0);
42
43 // conditional expectation, x0 dependent part
44 Real expectation_x0dep_part(Time w, Real xw, Time dt) const;
45
46 // conditional expectation, x0 independent part
47 // in the risk neutral measure
48 Real expectation_rn_part(Time w, Time dt) const;
49
50 // conditional expectation, drift adjustment for
51 // the T-forward measure
52 Real expectation_tf_part(Time w, Time dt) const;
53
54 // conditional variance
55 Real variance(Time w, Time dt) const;
56
57 // y(t)
58 Real y(Time t) const;
59
60 // G(t,w)
61 Real G(Time t, Time w) const;
62
63 // sigma
64 Real sigma(Time t) const;
65
66 // reversion
67 Real reversion(Time t) const;
68
69 // reset cache
70 void flushCache() const;
71
72 protected:
74
75 private:
76 int lowerIndex(Time t) const;
77 int upperIndex(Time t) const;
78 Real time2(Size index) const;
79 Real cappedTime(Size index, Real cap = Null<Real>()) const;
80 Real flooredTime(Size index, Real floor = Null<Real>()) const;
81 Real vol(Size index) const;
82 Real rev(Size index) const;
83 bool revZero(Size index) const;
84
85 mutable std::map<std::pair<Real, Real>, Real> cache1_, cache2a_, cache2b_,
87 mutable std::map<Real, Real> cache4_;
89 mutable std::vector<bool> revZero_;
90}; // GsrProcessCore
91
92// inline definitions
93
94inline Real GsrProcessCore::sigma(const Time t) const {
95 return vol(lowerIndex(t));
96}
97
98inline Real GsrProcessCore::reversion(const Time t) const {
99 return rev(lowerIndex(t));
100}
101
102} // namespace detail
103
104} // namespace QuantLib
105
106#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:76
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
Definition: any.hpp:35