QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
extendedcoxingersollross.hpp
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
25#ifndef quantlib_extended_cox_ingersoll_ross_hpp
26#define quantlib_extended_cox_ingersoll_ross_hpp
27
28#include <ql/models/shortrate/onefactormodels/coxingersollross.hpp>
29#include <utility>
30
31namespace QuantLib {
32
34
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
79
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
104
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:149
time grid class
Definition: timegrid.hpp:43
@ 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.