Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crcirppstateprocess.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <boost/make_shared.hpp>
20#include <ql/math/distributions/chisquaredistribution.hpp>
21#include <ql/math/distributions/normaldistribution.hpp>
22#include <ql/processes/eulerdiscretization.hpp>
25
26namespace QuantExt {
27
30 : StochasticProcess(QuantLib::ext::shared_ptr<StochasticProcess::discretization>(new EulerDiscretization)), model_(model),
31 discretization_(disc) {}
32
33Size CrCirppStateProcess::size() const { return 2; }
34
36 Array res(size(), 0.0);
37 res[0] = model_->parametrization()->y0(0); // y0
38 res[1] = 1.0; // S(0,0) = 1
39 return res;
40}
41
42Array CrCirppStateProcess::drift(Time t, const Array& x) const {
43 QL_FAIL("not implemented");
44}
45
46Matrix CrCirppStateProcess::diffusion(Time t, const Array& x) const {
47 QL_FAIL("not implemented");
48}
49
50Array CrCirppStateProcess::evolve(Time t0, const Array& x0, Time dt, const Array& dw) const {
51 Array retVal(size());
52 Real kappa, theta, sigma, y0;
53 kappa = model_->parametrization()->kappa(t0);
54 theta = model_->parametrization()->theta(t0);
55 sigma = model_->parametrization()->sigma(t0);
56 y0 = model_->parametrization()->y0(t0);
57
58 const Real sdt = std::sqrt(dt);
59 switch (discretization_) {
60
61 case BrigoAlfonsi: {
62 // see D. Brigo and F. Mercurio. Interest Rate Models: Theory and Practice, 2nd
63 // Edition. Springer, 2006.
64 // Ensures non-negative values for \sigma^2 \leq 2*\kappa*\theta
65 Real temp = (1 - kappa / 2.0 * dt);
66 Real temp2 = temp * std::sqrt(x0[0]) + sigma * sdt * dw[0] / (2.0 * temp);
67 retVal[0] = temp2 * temp2 + (kappa * theta - sigma * sigma / 4) * dt;
68 break;
69 }
70 default:
71 QL_FAIL("unknown discretization schema");
72 }
73
74 // second element is S(0,i)
75 Real SM_ti = model_->defaultCurve()->survivalProbability(t0 + dt);
76 Real SM_ti_pre = model_->defaultCurve()->survivalProbability(t0);
77 Real Pcir_ti = model_->zeroBond(0, t0 + dt, y0);
78 Real Pcir_ti_pre = model_->zeroBond(0, t0, y0);
79 retVal[1] = x0[1] * SM_ti / SM_ti_pre * Pcir_ti_pre / Pcir_ti * exp(-x0[0] * dt);
80
81 return retVal;
82}
83
84} // namespace QuantExt
Cox-Ingersoll-Ross ++ credit model class.
Definition: crcirpp.hpp:48
Real zeroBond(Real t, Real T, Real y) const
Definition: crcirpp.cpp:124
Handle< DefaultProbabilityTermStructure > defaultCurve(std::vector< Date > dateGrid=std::vector< Date >()) const
Definition: crcirpp.cpp:59
const QuantLib::ext::shared_ptr< CrCirppParametrization > parametrization() const
Definition: crcirpp.hpp:88
Array drift(Time t, const Array &x) const override
Array evolve(Time t0, const Array &x0, Time dt, const Array &dw) const override
CrCirppStateProcess(CrCirpp *const model, CrCirppStateProcess::Discretization disc=CrCirppStateProcess::Discretization::BrigoAlfonsi)
Matrix diffusion(Time t, const Array &x) const override
Array initialValues() const override
const CrCirppStateProcess::Discretization discretization_
CIR++ credit model class.
CIR++ model state process.
CompiledFormula exp(CompiledFormula x)