Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
defaultableequityjumpdiffusionmodel.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 Quaternion Risk Management Ltd.
3
4 This file is part of ORE, a free-software/open-source library
5 for transparent pricing and risk analysis - http://opensourcerisk.org
6
7 ORE is free software: you can redistribute it and/or modify it
8 under the terms of the Modified BSD License. You should have received a
9 copy of the license along with this program.
10 The license is also available online at <http://opensourcerisk.org>
11
12 This program is distributed on the basis that it will form a useful
13 contribution to risk analytics and model standardisation, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
16*/
17
18/*! \file qle/models/defaultableequityjumpdiffusionmodel.hpp */
19
20#pragma once
21
25
26#include <ql/methods/finitedifferences/meshers/fdm1dmesher.hpp>
27#include <ql/patterns/lazyobject.hpp>
28#include <ql/quote.hpp>
29#include <ql/termstructures/defaulttermstructure.hpp>
30#include <ql/termstructures/volatility/equityfx/blackvoltermstructure.hpp>
31#include <ql/termstructures/yieldtermstructure.hpp>
32#include <ql/types.hpp>
33
34#include <boost/enable_shared_from_this.hpp>
35
36namespace QuantExt {
37
38using QuantLib::Handle;
39using QuantLib::Real;
40
41class DefaultableEquityJumpDiffusionModel;
42
44public:
46
48 const std::vector<Real>& stepTimes, const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equity,
49 const Handle<QuantLib::BlackVolTermStructure>& volatility,
50 const Handle<QuantLib::DefaultProbabilityTermStructure>& creditCurve, const Real p = 0.0, const Real eta = 1.0,
51 const bool staticMesher = false, const Size timeStepsPerYear = 24, const Size stateGridPoints = 100,
52 const Real mesherEpsilon = 1E-4, const Real mesherScaling = 1.5, const Real mesherConcentration = Null<Real>(),
53 const BootstrapMode mode = BootstrapMode::Alternating, const bool enforceFokkerPlanckBootstrap = false,
54 const bool calibrate = true, const bool adjustEquityVolatility = true, const bool adjustEquityForward = true);
55
56 Handle<DefaultableEquityJumpDiffusionModel> model() const;
57
58 //! \name ModelBuilder interface
59 //@{
60 void forceRecalculate() override;
61 bool requiresRecalibration() const override;
62 //@}
63
64private:
65 void performCalculations() const override;
66 bool calibrationPointsChanged(const bool updateCache) const;
67
68 // input data
69 std::vector<Real> stepTimes_;
70 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equity_;
71 Handle<BlackVolTermStructure> volatility_;
72 Handle<DefaultProbabilityTermStructure> creditCurve_;
73 Real p_, eta_;
85
86 bool forceCalibration_ = false;
87 QuantLib::ext::shared_ptr<MarketObserver> marketObserver_;
88
89 mutable std::vector<Real> cachedForwards_;
90 mutable std::vector<Real> cachedVariances_;
91
92 mutable RelinkableHandle<DefaultableEquityJumpDiffusionModel> model_;
93};
94
95class DefaultableEquityJumpDiffusionModel : public QuantLib::Observable,
96 public QuantLib::Observer,
97 public QuantLib::ext::enable_shared_from_this<DefaultableEquityJumpDiffusionModel> {
98public:
99 /* Jump-Diffusion model for a defaultable equity
100
101 dS / S(t^-) = (r(t) - q(t) + \eta h(t, S(t^-))) dt + \sigma(t) dW(t) - \eta dN(t)
102
103 with h(t, S(t)) = h0(t) (S(0)/S(t))^p and h0(t), sigma(t) piecewise flat w.r.t. a given time grid.
104
105 eta is a given, fixed model parameter (default loss fraction for the equity price)
106 p is a given, fixed model parameter
107 r(t) is the equity forecast curve
108 q(t) is the equity dividend curve
109 h(t,S) is calibrated to the given credit curve
110 \sigma(t) is calibrated to the given equity vol surface
111
112 Reference: Andersen, L., and Buffum, D.: Calibration and Implementation of Convertible Bond Models (2002)
113
114 If adjustEquityVolatility = false, the market equity volatitlies will be used without adjustment accounting
115 for the hazard rate h(t). This option is only available for p=0.
116
117 If adjustEquityForward = false, the equity drift wil not be adjusted by \eta h(t, S(t^-)).
118 */
119
120 DefaultableEquityJumpDiffusionModel(const std::vector<Real>& stepTimes, const std::vector<Real>& h0,
121 const std::vector<Real>& sigma,
122 const QuantLib::ext::shared_ptr<QuantExt::EquityIndex2>& equity,
123 const Handle<QuantLib::DefaultProbabilityTermStructure>& creditCurve,
124 const DayCounter& volDayCounter, const Real p = 0.0, const Real eta = 1.0,
125 const bool adjustEquityForward = true);
126
127 // inspectors for input data
128 const std::vector<Real>& stepTimes() const;
129 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equity() const;
130 Real totalBlackVariance() const;
131 const DayCounter& volDayCounter() const;
132 Handle<QuantLib::DefaultProbabilityTermStructure> creditCurve() const;
133 Real eta() const;
134 Real p() const;
135 bool adjustEquityForward() const;
136
137 Real timeFromReference(const Date& d) const;
138
139 // piecewise constant model parameters w.r.t. stepTimes()
140 const std::vector<Real>& h0() const;
141 const std::vector<Real>& sigma() const;
142
143 // inspectors for model functions
144 Real h(const Real t, const Real S) const;
145 Real h0(const Real t) const;
146 Real r(const Real t) const;
147 Real q(const Real t) const;
148 Real sigma(const Real t) const;
149
150 // annualised dividend yield over 0 <= s < t
151 Real dividendYield(const Real s, const Real t) const;
152
153 // bootstrap the model parameters
154 void bootstrap(const Handle<QuantLib::BlackVolTermStructure>& volatility, const bool staticMesher,
155 const Size timeStepsPerYear, const Size stateGridPoints = 100, const Real mesherEpsilon = 1E-4,
156 const Real mesherScaling = 1.5, const Real mesherConcentration = Null<Real>(),
159 const bool enforceFokkerPlanckBootstrap = false, const bool adjustEquityVolatility = true) const;
160
161 // Observer interface
162 void update() override;
163
164private:
165 QuantLib::Size getTimeIndex(const Real t) const;
166
167 // input data
168 std::vector<Real> stepTimes_;
169 mutable std::vector<Real> h0_, sigma_;
170 QuantLib::ext::shared_ptr<QuantExt::EquityIndex2> equity_;
171 Handle<DefaultProbabilityTermStructure> creditCurve_;
172 DayCounter volDayCounter_;
173 Real p_, eta_;
175
176 // mesher used to solve Fokker-Planck equation
177 mutable QuantLib::ext::shared_ptr<Fdm1dMesher> mesher_;
178
179 // input black variance at last time step
180 mutable Real totalBlackVariance_ = 1.0;
181
182 // step size to compute r, q with finite differences
183 static constexpr Real fh_ = 1E-4;
184};
185
186} // namespace QuantExt
bool requiresRecalibration() const override
if false is returned, the model does not require a recalibration
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equity_
Handle< DefaultableEquityJumpDiffusionModel > model() const
RelinkableHandle< DefaultableEquityJumpDiffusionModel > model_
Handle< QuantLib::DefaultProbabilityTermStructure > creditCurve() const
void bootstrap(const Handle< QuantLib::BlackVolTermStructure > &volatility, const bool staticMesher, const Size timeStepsPerYear, const Size stateGridPoints=100, const Real mesherEpsilon=1E-4, const Real mesherScaling=1.5, const Real mesherConcentration=Null< Real >(), const DefaultableEquityJumpDiffusionModelBuilder::BootstrapMode bootstrapMode=DefaultableEquityJumpDiffusionModelBuilder::BootstrapMode::Alternating, const bool enforceFokkerPlanckBootstrap=false, const bool adjustEquityVolatility=true) const
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equity_
QuantLib::ext::shared_ptr< QuantExt::EquityIndex2 > equity() const
equity index class for holding equity fixing histories and forwarding.
helper class for model builders that observes market ts
Model builder base class.