QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
hullwhite.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) 2001, 2002, 2003 Sadruddin Rejeb
5 Copyright (C) 2006 Chiara Fornarola
6 Copyright (C) 2007 StatPro Italia srl
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file hullwhite.hpp
23 \brief Hull & White (HW) model
24*/
25
26#ifndef quantlib_hull_white_hpp
27#define quantlib_hull_white_hpp
28
30#include <utility>
31
32namespace QuantLib {
33
34 //! Single-factor Hull-White (extended %Vasicek) model class.
35 /*! This class implements the standard single-factor Hull-White model
36 defined by
37 \f[
38 dr_t = (\theta(t) - \alpha r_t)dt + \sigma dW_t
39 \f]
40 where \f$ \alpha \f$ and \f$ \sigma \f$ are constants.
41
42 \test calibration results are tested against cached values
43
44 \bug When the term structure is relinked, the r0 parameter of
45 the underlying Vasicek model is not updated.
46
47 \ingroup shortrate
48 */
50 public:
52 Real a = 0.1, Real sigma = 0.01);
53
54 ext::shared_ptr<Lattice> tree(const TimeGrid& grid) const override;
55
56 ext::shared_ptr<ShortRateDynamics> dynamics() const override;
57
59 Real strike,
60 Time maturity,
61 Time bondMaturity) const override;
62
64 Real strike,
65 Time maturity,
66 Time bondStart,
67 Time bondMaturity) const override;
68
69 /*! Futures convexity bias (i.e., the difference between
70 futures implied rate and forward rate) calculated as in
71 G. Kirikos, D. Novak, "Convexity Conundrums", Risk
72 Magazine, March 1997.
73
74 \note t and T should be expressed in yearfraction using
75 deposit day counter, F_quoted is futures' market price.
76 */
77 static Rate convexityBias(Real futurePrice,
78 Time t,
79 Time T,
80 Real sigma,
81 Real a);
82
83 static std::vector<bool> FixedReversion() {
84 std::vector<bool> c(2);
85 c[0] = true; c[1] = false;
86 return c;
87 }
88
89 protected:
90 void generateArguments() override;
91
92 Real A(Time t, Time T) const override;
93
94 private:
95 class Dynamics;
96 class FittingParameter;
97
99 };
100
101 //! Short-rate dynamics in the Hull-White model
102 /*! The short-rate is here
103 \f[
104 r_t = \varphi(t) + x_t
105 \f]
106 where \f$ \varphi(t) \f$ is the deterministic time-dependent
107 parameter used for term-structure fitting and \f$ x_t \f$ is the
108 state variable following an Ornstein-Uhlenbeck process.
109 */
111 public:
114 ext::shared_ptr<StochasticProcess1D>(new OrnsteinUhlenbeckProcess(a, sigma))),
115 fitting_(std::move(fitting)) {}
116
117 Real variable(Time t, Rate r) const override { return r - fitting_(t); }
118 Real shortRate(Time t, Real x) const override { return x + fitting_(t); }
119
120 private:
122 };
123
124 //! Analytical term-structure fitting parameter \f$ \varphi(t) \f$.
125 /*! \f$ \varphi(t) \f$ is analytically defined by
126 \f[
127 \varphi(t) = f(t) + \frac{1}{2}[\frac{\sigma(1-e^{-at})}{a}]^2,
128 \f]
129 where \f$ f(t) \f$ is the instantaneous forward rate at \f$ t \f$.
130 */
133 private:
134 class Impl final : public Parameter::Impl {
135 public:
138
139 Real value(const Array&, Time t) const override {
140 Rate forwardRate =
141 termStructure_->forwardRate(t, t, Continuous, NoFrequency);
142 Real temp = a_ < std::sqrt(QL_EPSILON) ?
143 Real(sigma_*t) :
144 Real(sigma_*(1.0 - std::exp(-a_*t))/a_);
145 return (forwardRate + 0.5*temp*temp);
146 }
147
148 private:
151 };
152 public:
154 Real a, Real sigma)
155 : TermStructureFittingParameter(ext::shared_ptr<Parameter::Impl>(
157 };
158
159
160 // inline definitions
161
162 inline ext::shared_ptr<OneFactorModel::ShortRateDynamics>
164 return ext::shared_ptr<ShortRateDynamics>(
165 new Dynamics(phi_, a(), sigma()));
166 }
167
168}
169
170
171#endif
172
1-D array used in linear algebra.
Definition: array.hpp:52
Shared handle to an observable.
Definition: handle.hpp:41
Short-rate dynamics in the Hull-White model.
Definition: hullwhite.hpp:110
Dynamics(Parameter fitting, Real a, Real sigma)
Definition: hullwhite.hpp:112
Real shortRate(Time t, Real x) const override
Compute short rate from state variable.
Definition: hullwhite.hpp:118
Real variable(Time t, Rate r) const override
Compute state variable from short rate.
Definition: hullwhite.hpp:117
Real value(const Array &, Time t) const override
Definition: hullwhite.hpp:139
Handle< YieldTermStructure > termStructure_
Definition: hullwhite.hpp:149
Impl(Handle< YieldTermStructure > termStructure, Real a, Real sigma)
Definition: hullwhite.hpp:136
Analytical term-structure fitting parameter .
Definition: hullwhite.hpp:132
FittingParameter(const Handle< YieldTermStructure > &termStructure, Real a, Real sigma)
Definition: hullwhite.hpp:153
Single-factor Hull-White (extended Vasicek) model class.
Definition: hullwhite.hpp:49
static Rate convexityBias(Real futurePrice, Time t, Time T, Real sigma, Real a)
Definition: hullwhite.cpp:133
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
Definition: hullwhite.cpp:89
void generateArguments() override
Definition: hullwhite.cpp:85
ext::shared_ptr< Lattice > tree(const TimeGrid &grid) const override
Return by default a trinomial recombining tree.
Definition: hullwhite.cpp:43
ext::shared_ptr< ShortRateDynamics > dynamics() const override
returns the short-rate dynamics
Definition: hullwhite.hpp:163
Real A(Time t, Time T) const override
Definition: hullwhite.cpp:75
static std::vector< bool > FixedReversion()
Definition: hullwhite.hpp:83
Base class describing the short-rate dynamics.
Ornstein-Uhlenbeck process class.
Base class for model parameter implementation.
Definition: parameter.hpp:41
Base class for model arguments.
Definition: parameter.hpp:38
1-dimensional stochastic process
Term-structure consistent model class.
Definition: model.hpp:73
const Handle< YieldTermStructure > & termStructure() const
Definition: model.hpp:77
Deterministic time-dependent parameter used for yield-curve fitting.
Definition: parameter.hpp:145
time grid class
Definition: timegrid.hpp:43
Vasicek model class
Definition: vasicek.hpp:42
Real sigma() const
Definition: vasicek.hpp:57
Real a() const
Definition: vasicek.hpp:54
const DefaultType & t
@ 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
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< YieldTermStructure > r
Vasicek model class.