QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
extendedcoxingersollross.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) 2021 Magnus Mencke
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 extendedcoxingersollross.hpp
22 \brief Extended Cox-Ingersoll-Ross model
23*/
24
25#ifndef quantlib_extended_cox_ingersoll_ross_hpp
26#define quantlib_extended_cox_ingersoll_ross_hpp
27
29#include <utility>
30
31namespace QuantLib {
32
33 //! Extended Cox-Ingersoll-Ross model class.
34 /*! This class implements the extended Cox-Ingersoll-Ross model
35 defined by
36 \f[
37 r(t) = \varphi(t)+y(t)
38 \f]
39 where \f$ \varphi(t) \f$ is the deterministic time-dependent
40 parameter used for term-structure fitting and \f$ y_t \f$ is a standard CIR process.
41
42 \bug this class was not tested enough to guarantee
43 its functionality.
44
45 \ingroup shortrate
46 */
49 public:
52 Real theta = 0.1,
53 Real k = 0.1,
54 Real sigma = 0.1,
55 Real x0 = 0.05,
56 bool withFellerConstraint = true);
57
58 ext::shared_ptr<Lattice> tree(const TimeGrid& grid) const override;
59
60 ext::shared_ptr<ShortRateDynamics> dynamics() const override;
61
63 Real strike,
64 Time maturity,
65 Time bondMaturity) const override;
66
67 protected:
68 void generateArguments() override;
69 Real A(Time t, Time T) const override;
70
71 private:
72 class Dynamics;
73 class FittingParameter;
74
76 };
77
78 //! Short-rate dynamics in the extended Cox-Ingersoll-Ross model
79 /*! The short-rate is here
80 \f[
81 r(t) = \varphi(t) + y(t)
82 \f]
83 where \f$ \varphi(t) \f$ is the deterministic time-dependent
84 parameter used for term-structure fitting and \f$ y_t \f$ is a standard CIR process
85 with dynamics
86 \f[
87 dy(t)=k(\theta-y(t))dt+\sigma \sqrt{y(t)}dW(t)
88 \f]
89 */
92 public:
94 : CoxIngersollRoss::Dynamics(theta, k, sigma, x0), phi_(std::move(phi)) {}
95
96 Real variable(Time t, Rate r) const override { return r - phi_(t); }
97 Real shortRate(Time t, Real y) const override { return y + phi_(t); }
98
99 private:
101 };
102
103 //! Analytical term-structure fitting parameter \f$ \varphi(t) \f$.
104 /*! \f$ \varphi(t) \f$ is analytically defined by
105 \f[
106 \varphi(t) = f(t) -
107 \frac{2k\theta(e^{th}-1)}{2h+(k+h)(e^{th}-1)} -
108 \frac{4 x_0 h^2 e^{th}}{(2h+(k+h)(e^{th}-1))^1},
109 \f]
110 where \f$ f(t) \f$ is the instantaneous forward rate at \f$ t \f$
111 and \f$ h = \sqrt{k^2 + 2\sigma^2} \f$.
112 */
115 private:
116 class Impl final : public Parameter::Impl {
117 public:
120 x0_(x0) {}
121
122 Real value(const Array&, Time t) const override {
123 Rate forwardRate =
124 termStructure_->forwardRate(t, t, Continuous, NoFrequency);
125 Real h = std::sqrt(k_*k_ + 2.0*sigma_*sigma_);
126 Real expth = std::exp(t*h);
127 Real temp = 2.0*h + (k_+h)*(expth-1.0);
128 Real phi = forwardRate -
129 2.0*k_*theta_*(expth - 1.0)/temp -
130 x0_*4.0*h*h*expth/(temp*temp);
131 return phi;
132 }
133
134 private:
137 };
138 public:
141 : TermStructureFittingParameter(ext::shared_ptr<Parameter::Impl>(
143 termStructure, theta, k, sigma, x0))) {}
144 };
145
146 // inline definitions
147
148 inline ext::shared_ptr<OneFactorModel::ShortRateDynamics>
150 return ext::shared_ptr<ShortRateDynamics>(
151 new Dynamics(phi_, theta(), k() , sigma(), x0()));
152 }
153
156 }
157
158}
159
160
161#endif
1-D array used in linear algebra.
Definition: array.hpp:52
Dynamics of the short-rate under the Cox-Ingersoll-Ross model
Cox-Ingersoll-Ross model class.
Short-rate dynamics in the extended Cox-Ingersoll-Ross model.
Dynamics(Parameter phi, Real theta, Real k, Real sigma, Real x0)
Real shortRate(Time t, Real y) const override
Compute short rate from state variable.
Real variable(Time t, Rate r) const override
Compute state variable from short rate.
Impl(Handle< YieldTermStructure > termStructure, Real theta, Real k, Real sigma, Real x0)
Analytical term-structure fitting parameter .
FittingParameter(const Handle< YieldTermStructure > &termStructure, Real theta, Real k, Real sigma, Real x0)
Extended Cox-Ingersoll-Ross model class.
Real discountBondOption(Option::Type type, Real strike, Time maturity, Time bondMaturity) const override
ext::shared_ptr< Lattice > tree(const TimeGrid &grid) const override
Return by default a trinomial recombining tree.
ext::shared_ptr< ShortRateDynamics > dynamics() const override
returns the short-rate dynamics
Real A(Time t, Time T) const override
Shared handle to an observable.
Definition: handle.hpp:41
Base class for model parameter implementation.
Definition: parameter.hpp:41
Base class for model arguments.
Definition: parameter.hpp:38
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
Cox-Ingersoll-Ross model.
const DefaultType & t
@ 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 Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< YieldTermStructure > r