QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
g2.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) 2004 Mike Parker
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file g2.hpp
22 \brief Two-factor additive Gaussian Model G2++
23*/
24
25#ifndef quantlib_two_factor_models_g2_h
26#define quantlib_two_factor_models_g2_h
27
31#include <utility>
32
33namespace QuantLib {
34
35 //! Two-additive-factor gaussian model class.
36 /*! This class implements a two-additive-factor model defined by
37 \f[
38 dr_t = \varphi(t) + x_t + y_t
39 \f]
40 where \f$ x_t \f$ and \f$ y_t \f$ are defined by
41 \f[
42 dx_t = -a x_t dt + \sigma dW^1_t, x_0 = 0
43 \f]
44 \f[
45 dy_t = -b y_t dt + \sigma dW^2_t, y_0 = 0
46 \f]
47 and \f$ dW^1_t dW^2_t = \rho dt \f$.
48
49 \bug This class was not tested enough to guarantee
50 its functionality.
51
52 \ingroup shortrate
53 */
54 class G2 : public TwoFactorModel,
55 public AffineModel,
57 public:
59 Real a = 0.1,
60 Real sigma = 0.01,
61 Real b = 0.1,
62 Real eta = 0.01,
63 Real rho = -0.75);
64
65 ext::shared_ptr<ShortRateDynamics> dynamics() const override;
66
67 Real discountBond(Time now, Time maturity, Array factors) const override {
68 QL_REQUIRE(factors.size()>1,
69 "g2 model needs two factors to compute discount bond");
70 return discountBond(now, maturity, factors[0], factors[1]);
71 }
72
74
76 Real strike,
77 Time maturity,
78 Time bondMaturity) const override;
79
80 Real swaption(const Swaption::arguments& arguments,
81 Rate fixedRate,
82 Real range,
83 Size intervals) const;
84
85 DiscountFactor discount(Time t) const override { return termStructure()->discount(t); }
86
87 Real a() const { return a_(0.0); }
88 Real sigma() const { return sigma_(0.0); }
89 Real b() const { return b_(0.0); }
90 Real eta() const { return eta_(0.0); }
91 Real rho() const { return rho_(0.0); }
92
93 protected:
94 void generateArguments() override;
95
96 Real A(Time t, Time T) const;
97 Real B(Real x, Time t) const;
98
99 private:
100 class Dynamics;
101 class FittingParameter;
102
103 Real sigmaP(Time t, Time s) const;
104
110
112
113 Real V(Time t) const;
114
115 class SwaptionPricingFunction;
116 };
117
119 public:
122 ext::shared_ptr<StochasticProcess1D>(new OrnsteinUhlenbeckProcess(a, sigma)),
123 ext::shared_ptr<StochasticProcess1D>(new OrnsteinUhlenbeckProcess(b, eta)),
124 rho),
125 fitting_(std::move(fitting)) {}
126 Rate shortRate(Time t, Real x, Real y) const override { return fitting_(t) + x + y; }
127
128 private:
130 };
131
132 //! Analytical term-structure fitting parameter \f$ \varphi(t) \f$.
133 /*! \f$ \varphi(t) \f$ is analytically defined by
134 \f[
135 \varphi(t) = f(t) +
136 \frac{1}{2}(\frac{\sigma(1-e^{-at})}{a})^2 +
137 \frac{1}{2}(\frac{\eta(1-e^{-bt})}{b})^2 +
138 \rho\frac{\sigma(1-e^{-at})}{a}\frac{\eta(1-e^{-bt})}{b},
139 \f]
140 where \f$ f(t) \f$ is the instantaneous forward rate at \f$ t \f$.
141 */
143 private:
144 class Impl final : public Parameter::Impl {
145 public:
147 Real a,
148 Real sigma,
149 Real b,
150 Real eta,
151 Real rho)
153 rho_(rho) {}
154
155 Real value(const Array&, Time t) const override {
156 Rate forward = termStructure_->forwardRate(t, t,
159 Real temp1 = sigma_*(1.0-std::exp(-a_*t))/a_;
160 Real temp2 = eta_*(1.0-std::exp(-b_*t))/b_;
161 Real value = 0.5*temp1*temp1 + 0.5*temp2*temp2 +
162 rho_*temp1*temp2 + forward;
163 return value;
164 }
165
166 private:
169 };
170 public:
172 Real a,
173 Real sigma,
174 Real b,
175 Real eta,
176 Real rho)
177 : TermStructureFittingParameter(ext::shared_ptr<Parameter::Impl>(
179 b, eta, rho))) {}
180 };
181
182}
183
184
185#endif
186
Affine model class.
Definition: model.hpp:45
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
Dynamics(Parameter fitting, Real a, Real sigma, Real b, Real eta, Real rho)
Definition: g2.hpp:120
Parameter fitting_
Definition: g2.hpp:129
Rate shortRate(Time t, Real x, Real y) const override
Definition: g2.hpp:126
Real value(const Array &, Time t) const override
Definition: g2.hpp:155
Impl(Handle< YieldTermStructure > termStructure, Real a, Real sigma, Real b, Real eta, Real rho)
Definition: g2.hpp:146
Handle< YieldTermStructure > termStructure_
Definition: g2.hpp:167
Analytical term-structure fitting parameter .
Definition: g2.hpp:142
FittingParameter(const Handle< YieldTermStructure > &termStructure, Real a, Real sigma, Real b, Real eta, Real rho)
Definition: g2.hpp:171
Two-additive-factor gaussian model class.
Definition: g2.hpp:56
Parameter & sigma_
Definition: g2.hpp:106
Real discountBond(Time now, Time maturity, Array factors) const override
Definition: g2.hpp:67
Parameter & b_
Definition: g2.hpp:107
Parameter phi_
Definition: g2.hpp:111
Real b() const
Definition: g2.hpp:89
Real sigma() const
Definition: g2.hpp:88
Parameter & eta_
Definition: g2.hpp:108
Real swaption(const Swaption::arguments &arguments, Rate fixedRate, Real range, Size intervals) const
Definition: g2.cpp:218
Real sigmaP(Time t, Time s) const
Definition: g2.cpp:59
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
Definition: g2.cpp:79
void generateArguments() override
Definition: g2.cpp:53
Real V(Time t) const
Definition: g2.cpp:89
Real rho() const
Definition: g2.hpp:91
DiscountFactor discount(Time t) const override
Implied discount curve.
Definition: g2.hpp:85
Real a() const
Definition: g2.hpp:87
Parameter & rho_
Definition: g2.hpp:109
Real A(Time t, Time T) const
Definition: g2.cpp:102
ext::shared_ptr< ShortRateDynamics > dynamics() const override
Returns the short-rate dynamics.
Definition: g2.cpp:48
Real eta() const
Definition: g2.hpp:90
Parameter & a_
Definition: g2.hpp:105
Real B(Real x, Time t) const
Definition: g2.cpp:107
Shared handle to an observable.
Definition: handle.hpp:41
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
Arguments for swaption calculation
Definition: swaption.hpp:147
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
Class describing the dynamics of the two state variables.
Abstract base-class for two-factor models.
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
@ NoFrequency
null frequency
Definition: frequency.hpp:37
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real DiscountFactor
discount factor between dates
Definition: types.hpp:66
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.
Ornstein-Uhlenbeck process.
Swaption class.
Abstract two-factor interest rate model class.