QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
hullwhiteprocess.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2006, 2007 Banca Profilo S.p.A.
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/hullwhiteprocess.hpp>
21
22namespace QuantLib {
23
25 Real a,
26 Real sigma)
27 : process_(new OrnsteinUhlenbeckProcess(
28 a, sigma, h->forwardRate(0.0,0.0,Continuous,NoFrequency))),
29 h_(h), a_(a), sigma_(sigma) {
30 QL_REQUIRE(a_ >= 0.0, "negative a given");
31 QL_REQUIRE(sigma_ >= 0.0, "negative sigma given");
32 }
33
35 return process_->x0();
36 }
37
39 Real alpha_drift = sigma_*sigma_/(2*a_)*(1-std::exp(-2*a_*t));
40 Real shift = 0.0001;
41 Real f = h_->forwardRate(t, t, Continuous, NoFrequency);
42 Real fup = h_->forwardRate(t+shift, t+shift, Continuous, NoFrequency);
43 Real f_prime = (fup-f)/shift;
44 alpha_drift += a_*f+f_prime;
45 return process_->drift(t, x) + alpha_drift;
46 }
47
49 return process_->diffusion(t, x);
50 }
51
53 return process_->expectation(t0, x0, dt)
54 + alpha(t0 + dt) - alpha(t0)*std::exp(-a_*dt);
55 }
56
58 return process_->stdDeviation(t0, x0, dt);
59 }
60
62 return process_->variance(t0, x0, dt);
63 }
64
66 Real alfa = a_ > QL_EPSILON ?
67 Real((sigma_/a_)*(1 - std::exp(-a_*t))) :
68 sigma_*t;
69 alfa *= 0.5*alfa;
70 alfa += h_->forwardRate(t, t, Continuous, NoFrequency);
71 return alfa;
72 }
73
75 return a_;
76 }
77
79 return sigma_;
80 }
81
84 Real a,
85 Real sigma)
86 : process_(new OrnsteinUhlenbeckProcess(
87 a, sigma, h->forwardRate(0.0,0.0,Continuous,NoFrequency))),
88 h_(h), a_(a), sigma_(sigma) {}
89
91 return process_->x0();
92 }
93
95 Real alpha_drift = sigma_*sigma_/(2*a_)*(1-std::exp(-2*a_*t));
96 Real shift = 0.0001;
97 Real f = h_->forwardRate(t, t, Continuous, NoFrequency);
98 Real fup = h_->forwardRate(t+shift, t+shift, Continuous, NoFrequency);
99 Real f_prime = (fup-f)/shift;
100 alpha_drift += a_*f+f_prime;
101 return process_->drift(t, x) + alpha_drift - B(t, T_)*sigma_*sigma_;
102 }
103
105 return process_->diffusion(t, x);
106 }
107
109 Time dt) const {
110 return process_->expectation(t0, x0, dt)
111 + alpha(t0 + dt) - alpha(t0)*std::exp(-a_*dt)
112 - M_T(t0, t0+dt, T_);
113 }
114
116 Time dt) const {
117 return process_->stdDeviation(t0, x0, dt);
118 }
119
121 return process_->variance(t0, x0, dt);
122 }
123
125 Real alfa = a_ > QL_EPSILON ?
126 Real((sigma_/a_)*(1 - std::exp(-a_*t))) :
127 sigma_*t;
128 alfa *= 0.5*alfa;
129 alfa += h_->forwardRate(t, t, Continuous, NoFrequency);
130
131 return alfa;
132 }
133
135 if (a_ > QL_EPSILON) {
136 Real coeff = (sigma_*sigma_)/(a_*a_);
137 Real exp1 = std::exp(-a_*(t-s));
138 Real exp2 = std::exp(-a_*(T-t));
139 Real exp3 = std::exp(-a_*(T+t-2.0*s));
140 return coeff*(1-exp1)-0.5*coeff*(exp2-exp3);
141 } else {
142 // low-a algebraic limit
143 Real coeff = (sigma_*sigma_)/2.0;
144 return coeff*(t-s)*(2.0*T-t-s);
145 }
146 }
147
149 return a_ > QL_EPSILON ?
150 Real(1/a_ * (1-std::exp(-a_*(T-t)))) :
151 T-t;
152 }
153
155 return a_;
156 }
157
159 return sigma_;
160 }
161}
162
Shared handle to an observable.
Definition: handle.hpp:41
Handle< YieldTermStructure > h_
HullWhiteForwardProcess(const Handle< YieldTermStructure > &h, Real a, Real sigma)
Real diffusion(Time t, Real x) const override
returns the diffusion part of the equation, i.e.
Real stdDeviation(Time t0, Real x0, Time dt) const override
Real M_T(Real s, Real t, Real T) const
Real drift(Time t, Real x) const override
returns the drift part of the equation, i.e.
ext::shared_ptr< QuantLib::OrnsteinUhlenbeckProcess > process_
Real expectation(Time t0, Real x0, Time dt) const override
Real B(Time t, Time T) const
Real x0() const override
returns the initial value of the state variable
Real variance(Time t0, Real x0, Time dt) const override
Handle< YieldTermStructure > h_
Real diffusion(Time t, Real x) const override
returns the diffusion part of the equation, i.e.
Real stdDeviation(Time t0, Real x0, Time dt) const override
Real drift(Time t, Real x) const override
returns the drift part of the equation, i.e.
ext::shared_ptr< QuantLib::OrnsteinUhlenbeckProcess > process_
HullWhiteProcess(const Handle< YieldTermStructure > &h, Real a, Real sigma)
Real expectation(Time t0, Real x0, Time dt) const override
Real x0() const override
returns the initial value of the state variable
Real variance(Time t0, Real x0, Time dt) const override
Ornstein-Uhlenbeck process class.
@ NoFrequency
null frequency
Definition: frequency.hpp:37
#define QL_EPSILON
Definition: qldefines.hpp:178
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