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
26 GsrProcess::GsrProcess(const Array& times,
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(
46 referenceDate_ != Null<Date>() && dc_ != DayCounter(),
47 "time can not be computed without reference date and day counter");
48 return dc_.yearFraction(d1: referenceDate_, d2: d);
49 }
50
51 Real GsrProcess::x0() const { return 0.0; }
52
53 Real GsrProcess::drift(Time t, Real x) const {
54 return core_.y(t) -
55 core_.G(t, w: getForwardMeasureTime()) * sigma(t) * sigma(t) -
56 reversion(t) * x;
57 }
58
59 Real GsrProcess::diffusion(Time t, Real) const {
60 checkT(t);
61 return sigma(t);
62 }
63
64 Real GsrProcess::expectation(Time w, Real xw, Time dt) const {
65 checkT(t: w + dt);
66 return core_.expectation_x0dep_part(w, xw, dt) +
67 core_.expectation_rn_part(w, dt) +
68 core_.expectation_tf_part(w, dt);
69 }
70
71
72
73 Real GsrProcess::stdDeviation(Time t0, Real x0, Time dt) const {
74 return std::sqrt(x: variance(t0, x0, dt));
75 }
76
77 Real GsrProcess::variance(Time w, Real, Time dt) const {
78 checkT(t: w + dt);
79 return core_.variance(w,dt);
80 }
81
82 Real GsrProcess::sigma(Time t) const { return core_.sigma(t); }
83
84 Real GsrProcess::reversion(Time t) const { return core_.reversion(t); }
85
86 Real GsrProcess::y(Time t) const {
87 checkT(t);
88 return core_.y(t);
89 }
90
91 Real GsrProcess::G(Time t, Time w, Real) const {
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}
104

source code of quantlib/ql/processes/gsrprocess.cpp

Morty Proxy This is a proxified and sanitized view of the page, visit original site.