QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
gsrprocess.cpp
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#include <ql/processes/gsrprocess.hpp>
21#include <cmath>
22#include <utility>
23
24namespace QuantLib {
25
27 const Array& vols,
28 const Array& reversions,
29 const Real T,
30 const Date& referenceDate,
31 DayCounter dc)
32 : ForwardMeasureProcess1D(T), core_(times, vols, reversions, T), referenceDate_(referenceDate),
33 dc_(std::move(dc)) {
34 flushCache();
35 }
36
37 void GsrProcess::checkT(const Time t) const {
38 QL_REQUIRE(t <= getForwardMeasureTime() && t >= 0.0,
39 "t (" << t
40 << ") must not be greater than forward measure time ("
41 << getForwardMeasureTime() << ") and non-negative");
42 }
43
44 Real GsrProcess::time(const Date &d) const {
45 QL_REQUIRE(
47 "time can not be computed without reference date and day counter");
49 }
50
51 Real GsrProcess::x0() const { return 0.0; }
52
54 return core_.y(t) -
55 core_.G(t, getForwardMeasureTime()) * sigma(t) * sigma(t) -
56 reversion(t) * x;
57 }
58
60 checkT(t);
61 return sigma(t);
62 }
63
65 checkT(w + dt);
66 return core_.expectation_x0dep_part(w, xw, dt) +
69 }
70
71
72
74 return std::sqrt(variance(t0, x0, dt));
75 }
76
78 checkT(w + dt);
79 return core_.variance(w,dt);
80 }
81
82 Real GsrProcess::sigma(Time t) const { return core_.sigma(t); }
83
85
87 checkT(t);
88 return core_.y(t);
89 }
90
92 QL_REQUIRE(w >= t, "G(t,w) should be called with w ("
93 << w << ") not lesser than t (" << t << ")");
94 QL_REQUIRE(t >= 0.0 && w <= getForwardMeasureTime(),
95 "G(t,w) should be called with (t,w)=("
96 << t << "," << w << ") in Range [0,"
97 << getForwardMeasureTime() << "].");
98
99 return core_.G(t,w);
100 }
101
102
103}
1-D array used in linear algebra.
Definition: array.hpp:52
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
forward-measure 1-D stochastic process
Real variance(Time t0, Real, Time dt) const override
Definition: gsrprocess.cpp:77
Real G(Time t, Time T, Real x) const
Definition: gsrprocess.cpp:91
Real y(Time t) const
Definition: gsrprocess.cpp:86
GsrProcess(const Array &times, const Array &vols, const Array &reversions, Real T=60.0, const Date &referenceDate=Null< Date >(), DayCounter dc=DayCounter())
Definition: gsrprocess.cpp:26
Real diffusion(Time t, Real) const override
returns the diffusion part of the equation, i.e.
Definition: gsrprocess.cpp:59
Real stdDeviation(Time t0, Real x0, Time dt) const override
Definition: gsrprocess.cpp:73
void checkT(Time t) const
Definition: gsrprocess.cpp:37
void flushCache() const
reset cache
Definition: gsrprocess.hpp:83
const detail::GsrProcessCore core_
Definition: gsrprocess.hpp:71
Real reversion(Time t) const
Definition: gsrprocess.cpp:84
Real drift(Time t, Real x) const override
returns the drift part of the equation, i.e.
Definition: gsrprocess.cpp:53
Real time(const Date &d) const override
Definition: gsrprocess.cpp:44
Real sigma(Time t) const
additional inspectors
Definition: gsrprocess.cpp:82
Real expectation(Time t0, Real x0, Time dt) const override
Definition: gsrprocess.cpp:64
Real x0() const override
returns the initial value of the state variable
Definition: gsrprocess.cpp:51
template class providing a null value for a given type.
Definition: null.hpp:76
Real expectation_x0dep_part(Time w, Real xw, Time dt) const
Real expectation_rn_part(Time w, Time dt) const
Real expectation_tf_part(Time w, Time dt) const
Real G(Time t, Time w) const
Real variance(Time w, Time dt) const
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
STL namespace.