Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CrCirpp Class Reference

Cox-Ingersoll-Ross ++ credit model class. More...

#include <qle/models/crcirpp.hpp>

+ Inheritance diagram for CrCirpp:
+ Collaboration diagram for CrCirpp:

Public Member Functions

 CrCirpp (const QuantLib::ext::shared_ptr< CrCirppParametrization > &parametrization)
 
Real zeroBond (Real t, Real T, Real y) const
 
Real survivalProbability (Real t, Real T, Real y) const
 
Real densityForwardMeasure (Real x, Real t)
 
Real cumulativeForwardMeasure (Real x, Real t)
 
Real density (Real x, Real t)
 
Real cumulative (Real x, Real t)
 
Real zeroBondOption (Real eval_t, Real expiry_T, Real maturity_tau, Real strike_k, Real y_t, Real w)
 
Handle< DefaultProbabilityTermStructure > defaultCurve (std::vector< Date > dateGrid=std::vector< Date >()) const
 
const QuantLib::ext::shared_ptr< CrCirppParametrizationparametrization () const
 
const QuantLib::ext::shared_ptr< StochasticProcessstateProcess () const
 
Real A (Real t, Real T) const
 
Real B (Real t, Real T) const
 
void update () override
 
void generateArguments () override
 
- Public Member Functions inherited from LinkableCalibratedModel
 LinkableCalibratedModel ()
 
void update () override
 
virtual void calibrate (const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >(), const std::vector< bool > &fixParameters=std::vector< bool >())
 Calibrate to a set of market instruments (usually caps/swaptions) More...
 
virtual void calibrate (const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &, OptimizationMethod &method, const EndCriteria &endCriteria, const Constraint &constraint=Constraint(), const std::vector< Real > &weights=std::vector< Real >(), const std::vector< bool > &fixParameters=std::vector< bool >())
 for backward compatibility More...
 
Real value (const Array &params, const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &)
 
Real value (const Array &params, const std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > &)
 for backward compatibility More...
 
const QuantLib::ext::shared_ptr< Constraint > & constraint () const
 
EndCriteria::Type endCriteria () const
 Returns end criteria result. More...
 
const Array & problemValues () const
 Returns the problem values. More...
 
Array params () const
 Returns array of arguments on which calibration is done. More...
 
virtual void setParams (const Array &params)
 
virtual void setParam (Size idx, const Real value)
 

Private Attributes

QuantLib::ext::shared_ptr< CrCirppParametrizationparametrization_
 
QuantLib::ext::shared_ptr< CrCirppStateProcessstateProcess_
 

Additional Inherited Members

virtual void generateArguments ()
 
- Protected Attributes inherited from LinkableCalibratedModel
std::vector< QuantLib::ext::shared_ptr< Parameter > > arguments_
 
QuantLib::ext::shared_ptr< Constraintconstraint_
 
EndCriteria::Type endCriteria_
 
Array problemValues_
 

Detailed Description

Cox-Ingersoll-Ross ++ credit model class.

This class implements the Cox-Ingersoll-Ross model defined by

\[ \lambda(t) = y(t) + \psi (t) \\ dy(t) = a(\theta - y(t)) dt + \sigma \, \sqrt{y(t)} \, dW \]

Definition at line 48 of file crcirpp.hpp.

Constructor & Destructor Documentation

◆ CrCirpp()

CrCirpp ( const QuantLib::ext::shared_ptr< CrCirppParametrization > &  parametrization)

Definition at line 42 of file crcirpp.cpp.

45
46 // FIXME hardcoded discretisation schema
48 QuantLib::ext::make_shared<CrCirppStateProcess>(this, CrCirppStateProcess::Discretization::BrigoAlfonsi);
49 QL_REQUIRE(stateProcess_ != NULL, "stateProcess has null pointer in CrCirpp ctor!");
50
51 arguments_.resize(4);
52 arguments_[0] = parametrization_->parameter(0);
53 arguments_[1] = parametrization_->parameter(1);
54 arguments_[2] = parametrization_->parameter(2);
55 arguments_[3] = parametrization_->parameter(3);
56 registerWith(parametrization_->termStructure());
57}
QuantLib::ext::shared_ptr< CrCirppParametrization > parametrization_
Definition: crcirpp.hpp:77
QuantLib::ext::shared_ptr< CrCirppStateProcess > stateProcess_
Definition: crcirpp.hpp:78
const QuantLib::ext::shared_ptr< CrCirppParametrization > parametrization() const
Definition: crcirpp.hpp:88
std::vector< QuantLib::ext::shared_ptr< Parameter > > arguments_

Member Function Documentation

◆ zeroBond()

Real zeroBond ( Real  t,
Real  T,
Real  y 
) const

Definition at line 124 of file crcirpp.cpp.

124{ return A(t, T) * exp(-B(t, T) * y); }
Real A(Real t, Real T) const
Definition: crcirpp.cpp:93
Real B(Real t, Real T) const
Definition: crcirpp.cpp:109
CompiledFormula exp(CompiledFormula x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ survivalProbability()

Real survivalProbability ( Real  t,
Real  T,
Real  y 
) const

Definition at line 126 of file crcirpp.cpp.

126 {
127 Real P_Cir = zeroBond(t, T, y); // A(t,T) * exp(-B(t,T) * y);
128 if (parametrization_->shifted()) {
129 Probability SP_t = parametrization_->termStructure()->survivalProbability(t);
130 // std::cout<<" SP_t " << SP_t << std::endl;
131 Probability SP_T = parametrization_->termStructure()->survivalProbability(T);
132 // std::cout<<" SP_T " << SP_T << std::endl;
133 // std::cout<<" y0 " << parametrization_->y0(t) << std::endl;
134 Real A_bar = (SP_T * A(0, t) * exp(-B(0, t) * parametrization_->y0(t))) /
135 (SP_t * A(0, T) * exp(-B(0, T) * parametrization_->y0(t)));
136 // std::cout<<"A_bar " <<A_bar<< std::endl;
137 return A_bar * P_Cir;
138 } else
139 return P_Cir;
140}
Real zeroBond(Real t, Real T, Real y) const
Definition: crcirpp.cpp:124
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ densityForwardMeasure()

Real densityForwardMeasure ( Real  x,
Real  t 
)

Definition at line 176 of file crcirpp.cpp.

176 {
177
178 Real kappa = parametrization_->kappa(t);
179 Real theta = parametrization_->theta(t);
180 Real sigma = parametrization_->sigma(t);
181 Real y0 = parametrization_->y0(t);
182 Real sigma2 = sigma * sigma;
183
184 Real h = sqrt(kappa * kappa + 2.0 * sigma2);
185 Real rho = 2 * h / (sigma2 * (exp(h * t) - 1));
186 // q(t,s) in Brigo-Mercuri in (3.28)
187 Real c = 2 * (rho + (kappa + h) / sigma2 + 0.0); // 0.0 stands for the B term which is neglectible
188 // degrees of freedom
189 Real df = 4 * kappa * theta / (sigma2);
190 // non-central parameter
191 // delta(t,s) in Brigo-Mercurio in (3.28)
192 Real ncp = 4 * (rho * rho * y0 * exp(h * t)) / c;
193
194 return c * nccs(df, ncp, c * x, false);
195}
RandomVariable sqrt(RandomVariable x)
+ Here is the call graph for this function:

◆ cumulativeForwardMeasure()

Real cumulativeForwardMeasure ( Real  x,
Real  t 
)

Definition at line 198 of file crcirpp.cpp.

198 {
199
200 Real kappa = parametrization_->kappa(t);
201 Real theta = parametrization_->theta(t);
202 Real sigma = parametrization_->sigma(t);
203 Real y0 = parametrization_->y0(t);
204 Real sigma2 = sigma * sigma;
205 Real h = sqrt(kappa * kappa + 2.0 * sigma2);
206 Real rho = 2 * h / (sigma2 * (exp(h * t) - 1));
207
208 // q(t,s) in Brigo-Mercurii (3.28)
209 Real c = 2 * (rho + (kappa + h) / sigma2 + 0.0); // 0.0 stands for the B term which is neglectible
210 // degrees of freedom
211 Real df = 4 * kappa * theta / (sigma2);
212 // non-central parameter
213 // delta(t,s) in Brigo-Mercurio in (3.28)
214 Real ncp = 4 * (rho * rho * y0 * exp(h * t)) / c;
215
216 return c * nccs(df, ncp, c * x, true);
217}
+ Here is the call graph for this function:

◆ density()

Real density ( Real  x,
Real  t 
)

Definition at line 142 of file crcirpp.cpp.

142 {
143
144 Real kappa = parametrization_->kappa(t);
145 Real theta = parametrization_->theta(t);
146 Real sigma = parametrization_->sigma(t);
147 Real y0 = parametrization_->y0(t);
148 Real sigma2 = sigma * sigma;
149
150 Real c = 4 * kappa / (sigma2 * (1 - exp(-kappa * t)));
151 // degrees of freedom
152 Real df = 4 * kappa * theta / (sigma2);
153 // non-central parameter
154 Real ncp = c * y0 * exp(-kappa * t);
155
156 return c * nccs(df, ncp, c * x, false);
157}
+ Here is the call graph for this function:

◆ cumulative()

Real cumulative ( Real  x,
Real  t 
)

Definition at line 159 of file crcirpp.cpp.

159 {
160
161 Real kappa = parametrization_->kappa(t);
162 Real theta = parametrization_->theta(t);
163 Real sigma = parametrization_->sigma(t);
164 Real y0 = parametrization_->y0(t);
165 Real sigma2 = sigma * sigma;
166
167 Real c = 4 * kappa / (sigma2 * (1 - exp(-kappa * t)));
168 // degrees of freedom
169 Real df = 4 * kappa * theta / (sigma2);
170 // non-central parameter
171 Real ncp = c * y0 * exp(-kappa * t);
172
173 return c * nccs(df, ncp, c * x, true);
174}
+ Here is the call graph for this function:

◆ zeroBondOption()

Real zeroBondOption ( Real  eval_t,
Real  expiry_T,
Real  maturity_tau,
Real  strike_k,
Real  y_t,
Real  w 
)

Definition at line 220 of file crcirpp.cpp.

221 {
222
223 Real value = 0.0;
224 Real kappa = parametrization_->kappa(eval_t);
225 Real theta = parametrization_->theta(eval_t);
226 Real sigma = parametrization_->sigma(eval_t);
227 Real y0 = parametrization_->y0(eval_t);
228 Real sigma2 = sigma * sigma;
229
230 Real h = sqrt(kappa * kappa + 2.0 * sigma2);
231 Real rho = 2.0 * h / (sigma2 * (exp(h * (expiry_T - eval_t)) - 1.0));
232 Real Psi = (kappa + h) / sigma2;
233
234 Probability SP_T;
235 Probability SP_tau;
236 if (parametrization_->shifted()) {
237 SP_T = parametrization()->termStructure()->survivalProbability(expiry_T);
238 SP_tau = parametrization()->termStructure()->survivalProbability(maturity_tau);
239 } else {
240 SP_T = survivalProbability(0.0, expiry_T, y0);
241 SP_tau = survivalProbability(0.0, maturity_tau, y0);
242 }
243
244 Real r_hat = 1.0 / B(expiry_T, maturity_tau) *
245 (log(A(expiry_T, maturity_tau) / strike_k) -
246 log((SP_T * A(0.0, maturity_tau) * exp(-B(0.0, maturity_tau) * y0)) /
247 (SP_tau * A(0.0, expiry_T) * exp(-B(0.0, expiry_T) * y0))));
248
249 Real denom = rho + Psi + B(expiry_T, maturity_tau);
250 Real df = 4.0 * kappa * theta / sigma2;
251 Real ncp = 2.0 * rho * rho * y_t * exp(h * (expiry_T - eval_t)) / denom;
252 QL_REQUIRE(std::isfinite(df) && df > 0, "CrCirpp::zeroBondOption(): illegal df="
253 << df << ", kappa=" << kappa << ", theta= " << theta
254 << ", sigma=" << sigma);
255
256 value += nccs(df, ncp, 2 * r_hat * denom, true) * SP_tau;
257
258 denom = rho + Psi;
259 // df unchanged
260 ncp = 2 * rho * rho * y_t * exp(h * (expiry_T - eval_t)) / denom;
261
262 value -= nccs(df, ncp, 2 * r_hat * denom, true) * SP_T * strike_k;
263
264 if (w < 0.0) {
265 // PUT via put-call-paritiy
266 // C - P = S_M(T) - S_M(t)*K
267 // P = C - S_M(T) + S_M(t)*K
268 value -= SP_tau - SP_T * strike_k;
269 }
270
271 return value;
272}
Real survivalProbability(Real t, Real T, Real y) const
Definition: crcirpp.cpp:126
Real value(const Array &params, const std::vector< QuantLib::ext::shared_ptr< CalibrationHelper > > &)
CompiledFormula log(CompiledFormula x)
+ Here is the call graph for this function:

◆ defaultCurve()

Handle< DefaultProbabilityTermStructure > defaultCurve ( std::vector< Date >  dateGrid = std::vector<Date>()) const

Definition at line 59 of file crcirpp.cpp.

59 {
60 if (parametrization_->shifted()) {
61 QL_REQUIRE(!parametrization_->termStructure().empty(), "default curve not set");
62 QL_REQUIRE(dateGrid.size() == 0, "dateGrid without effect for shifted model");
63 return parametrization_->termStructure();
64 } else {
65 // build one on the fly
66 Date today = Settings::instance().evaluationDate();
67 std::vector<Real> survivalProbabilities(1, 1.0);
68 std::vector<Date> dates;
69 DayCounter tsDayCounter = Actual365Fixed();
70 if (dateGrid.size() > 0) {
71 QL_REQUIRE(dateGrid.front() == today, "front date must be today");
72 dates = dateGrid;
73 } else {
74 dates.push_back(today);
75 // up to one year in monthly steps
76 for (Size i = 1; i <= 12; i++)
77 dates.push_back(today + i * Months);
78 // starts in year two annually
79 for (Size i = 2; i <= 10; i++)
80 dates.push_back(today + i * Years);
81 }
82 for (Size i = 1; i < dates.size(); i++) {
83 Real t = tsDayCounter.yearFraction(today, dates[i]);
84 survivalProbabilities.push_back(survivalProbability(0.0, t, parametrization_->y0(t)));
85 }
86 QuantLib::ext::shared_ptr<DefaultProbabilityTermStructure> defaultCurve(
87 new InterpolatedSurvivalProbabilityCurve<LogLinear>(dates, survivalProbabilities, tsDayCounter));
88 defaultCurve->enableExtrapolation();
89 return Handle<DefaultProbabilityTermStructure>(defaultCurve);
90 }
91}
Handle< DefaultProbabilityTermStructure > defaultCurve(std::vector< Date > dateGrid=std::vector< Date >()) const
Definition: crcirpp.cpp:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parametrization()

const QuantLib::ext::shared_ptr< CrCirppParametrization > parametrization ( ) const

Definition at line 88 of file crcirpp.hpp.

88 {
89 return parametrization_;
90}
+ Here is the caller graph for this function:

◆ stateProcess()

const QuantLib::ext::shared_ptr< StochasticProcess > stateProcess ( ) const

Definition at line 92 of file crcirpp.hpp.

92 {
93 QL_REQUIRE(stateProcess_ != NULL, "stateProcess has null pointer in CIR++ stateProcess!");
94 return stateProcess_;
95}

◆ A()

Real A ( Real  t,
Real  T 
) const

Definition at line 93 of file crcirpp.cpp.

93 {
94 Real kappa = parametrization_->kappa(t);
95 Real theta = parametrization_->theta(t);
96 Real sigma = parametrization_->sigma(t);
97 Real sigma2 = sigma * sigma;
98 Real h = sqrt(kappa * kappa + 2.0 * sigma2);
99
100 Real nominator = 2.0 * h * exp((kappa + h) * (T - t) / 2.0);
101 Real denominator = 2.0 * h + (kappa + h) * (exp((T - t) * h) - 1.0);
102 Real exponent = 2.0 * kappa * theta / sigma2;
103
104 Real value = std::pow((nominator / denominator), exponent);
105
106 return value;
107}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ B()

Real B ( Real  t,
Real  T 
) const

Definition at line 109 of file crcirpp.cpp.

109 {
110
111 Real kappa = parametrization_->kappa(t);
112 Real sigma = parametrization_->sigma(t);
113 Real sigma2 = sigma * sigma;
114 Real h = sqrt(kappa * kappa + 2.0 * sigma2);
115
116 Real nominator = 2.0 * (exp((T - t) * h) - 1.0);
117 Real denominator = 2.0 * h + (kappa + h) * (exp((T - t) * h) - 1.0);
118
119 Real value = nominator / denominator;
120
121 return value;
122}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

void update ( )
override

observer and linked calibrated model interface

Definition at line 81 of file crcirpp.hpp.

81 {
82 notifyObservers();
83 parametrization_->update();
84}
+ Here is the caller graph for this function:

◆ generateArguments()

void generateArguments ( )
overridevirtual

Reimplemented from LinkableCalibratedModel.

Definition at line 86 of file crcirpp.hpp.

86{ update(); }
void update() override
Definition: crcirpp.hpp:81
+ Here is the call graph for this function:

Member Data Documentation

◆ parametrization_

QuantLib::ext::shared_ptr<CrCirppParametrization> parametrization_
private

Definition at line 77 of file crcirpp.hpp.

◆ stateProcess_

QuantLib::ext::shared_ptr<CrCirppStateProcess> stateProcess_
private

Definition at line 78 of file crcirpp.hpp.