Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
defaultlossmodel.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 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#ifndef quantext_defaultlossmodel_hpp
20#define quantext_defaultlossmodel_hpp
21
22#include <ql/experimental/credit/defaultprobabilitykey.hpp>
23#include <ql/instruments/claim.hpp>
24#include <qle/models/basket.hpp>
25//#include <ql/experimental/credit/basket.hpp>
26
27#include <ql/utilities/null_deleter.hpp>
28
29/* Intended to replace LossDistribution in
30 ql/experimental/credit/lossdistribution, not sure its covering all the
31 functionality (see mthod below)
32*/
33
34namespace QuantExt {
35using namespace QuantLib;
36
37/*! Default loss model interface definition.
38Allows communication between the basket and specific algorithms. Intended to
39hold any kind of portfolio joint loss, latent models, top-down,....
40
41An inconvenience of this design as opposed to the full arguments/results
42is that when pricing several derivatives instruments on the same basket
43not all the pricing engines would point to the same loss model; thus when
44pricing a set of such instruments there might be some switching on the
45basket loss models, which might require recalculations (of the basket) or
46not depending on the pricing order.
47*/
48class DefaultLossModel : public Observable { // joint-? basket?-defaultLoss
49 /* Protection together with frienship to avoid the need of checking the
50 basket-argument pointer integrity. It is the responsibility of the basket
51 now; our only caller.
52 */
53 // RL: QuantExt version
54 friend class QuantExt::Basket;
55
56protected:
57 // argument basket:
58 // RL: QuantExt version
59 mutable RelinkableHandle<QuantExt::Basket> basket_;
60
62 //! \name Statistics
63 //@{
64 /* Non mandatory implementations, fails if client is not providing what
65 requested. */
66
67 /* Default implementation using the expectedLoss(Date) method.
68 Typically this method is called repeatedly with the same
69 date parameter which makes it innefficient. */
70 // RL: additional flag
71 virtual Real expectedTrancheLoss(const Date& d, Real recoveryRate = Null<Real>()) const {
72 QL_FAIL("expectedTrancheLoss Not implemented for this model.");
73 }
74 /*! Probability of the tranche losing the same or more than the
75 fractional amount given.
76
77 The passed lossFraction is a fraction of losses over the
78 tranche notional (not the portfolio).
79 */
80 virtual Probability probOverLoss(const Date& d, Real lossFraction) const {
81 QL_FAIL("probOverLoss Not implemented for this model.");
82 }
83 //! Value at Risk given a default loss percentile.
84 virtual Real percentile(const Date& d, Real percentile) const {
85 QL_FAIL("percentile Not implemented for this model.");
86 }
87 //! Expected shortfall given a default loss percentile.
88 virtual Real expectedShortfall(const Date& d, Real percentile) const {
89 QL_FAIL("eSF Not implemented for this model.");
90 }
91 //! Associated VaR fraction to each counterparty.
92 virtual std::vector<Real> splitVaRLevel(const Date& d, Real loss) const {
93 QL_FAIL("splitVaRLevel Not implemented for this model.");
94 }
95 //! Associated ESF fraction to each counterparty.
96 virtual std::vector<Real> splitESFLevel(const Date& d, Real loss) const {
97 QL_FAIL("splitESFLevel Not implemented for this model.");
98 }
99
100 // \todo Add splits by instrument position.
101
102 //! Full loss distribution.
103 virtual std::map<Real, Probability> lossDistribution(const Date&) const {
104 QL_FAIL("lossDistribution Not implemented for this model.");
105 }
106 //! Probability density of a given loss fraction of the basket notional.
107 virtual Real densityTrancheLoss(const Date& d, Real lossFraction) const {
108 QL_FAIL("densityTrancheLoss Not implemented for this model.");
109 }
110 /*! Probabilities for each of the (remaining) basket elements in the
111 pool to have defaulted by time d and at the same time be the Nth
112 defaulting name to default in the basket. This method is oriented to
113 default order dependent portfolio pricing (e.g. NTDs)
114 The probabilities ordering in the vector coincides with the
115 pool order.
116 */
117 virtual std::vector<Probability> probsBeingNthEvent(Size n, const Date& d) const {
118 QL_FAIL("probsBeingNthEvent Not implemented for this model.");
119 }
120 //! Pearsons' default probability correlation.
121 virtual Real defaultCorrelation(const Date& d, Size iName, Size jName) const {
122 QL_FAIL("defaultCorrelation Not implemented for this model.");
123 }
124 /*! Returns the probaility of having a given or larger number of
125 defaults in the basket portfolio at a given time.
126 */
127 virtual Probability probAtLeastNEvents(Size n, const Date& d) const {
128 QL_FAIL("probAtLeastNEvents Not implemented for this model.");
129 }
130 /*! Expected RR for name conditinal to default by that date.
131 */
132 virtual Real expectedRecovery(const Date&, Size iName, const DefaultProbKey&) const {
133 QL_FAIL("expected recovery Not implemented for this model.");
134 }
135 //@}
136
137 /*! Return single correlation number for one factor models. If not implemented or not applicable,
138 returns a \c Null<Real>().
139 */
140 virtual QuantLib::Real correlation() const {
141 return QuantLib::Null<QuantLib::Real>();
142 }
143
144 /*! Send a reference to the basket to allow the model to read the
145 problem arguments (contained in the basket)
146 */
147private: // can only be called from Basket
148 // RL: QuantExt version
150 /* After this; if the model modifies its internal status/caches (if
151 any) it should notify the prior basket to recognise that basket is
152 not in a calculated=true state. Since we dont know at this level if
153 the model keeps caches it is the children responsibility. Typically
154 this is done at the first call to calculate to the loss model, there
155 it notifies the basket. The old basket is still registered with us
156 until the basket takes in a new model....
157 ..alternatively both old basket and model could be forced reset here
158 */
159 // RL: QuantExt version
160 basket_.linkTo(QuantLib::ext::shared_ptr<QuantExt::Basket>(bskt, null_deleter()), false);
161 resetModel(); // or rename to setBasketImpl(...)
162 }
163 // the call order matters, which is the reason for the parent to be the
164 // sole caller.
165 //! Concrete models do now any updates/inits they need on basket reset
166 virtual void resetModel() = 0;
167};
168
169} // namespace QuantExt
170
171#endif
basket of issuers and related notionals
virtual Real defaultCorrelation(const Date &d, Size iName, Size jName) const
Pearsons' default probability correlation.
virtual Probability probOverLoss(const Date &d, Real lossFraction) const
virtual std::map< Real, Probability > lossDistribution(const Date &) const
Full loss distribution.
virtual void resetModel()=0
Concrete models do now any updates/inits they need on basket reset.
virtual Real expectedTrancheLoss(const Date &d, Real recoveryRate=Null< Real >()) const
virtual std::vector< Probability > probsBeingNthEvent(Size n, const Date &d) const
virtual Real expectedShortfall(const Date &d, Real percentile) const
Expected shortfall given a default loss percentile.
virtual QuantLib::Real correlation() const
RelinkableHandle< QuantExt::Basket > basket_
virtual Real expectedRecovery(const Date &, Size iName, const DefaultProbKey &) const
virtual Real percentile(const Date &d, Real percentile) const
Value at Risk given a default loss percentile.
virtual Real densityTrancheLoss(const Date &d, Real lossFraction) const
Probability density of a given loss fraction of the basket notional.
void setBasket(QuantExt::Basket *bskt)
virtual Probability probAtLeastNEvents(Size n, const Date &d) const
virtual std::vector< Real > splitVaRLevel(const Date &d, Real loss) const
Associated VaR fraction to each counterparty.
virtual std::vector< Real > splitESFLevel(const Date &d, Real loss) const
Associated ESF fraction to each counterparty.