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

#include <qle/models/gaussianlhplossmodel.hpp>

+ Inheritance diagram for GaussianLHPLossModel:
+ Collaboration diagram for GaussianLHPLossModel:

Public Types

typedef GaussianCopulaPolicy copulaType
 

Public Member Functions

 GaussianLHPLossModel (const Handle< Quote > &correlQuote, const std::vector< Handle< QuantLib::RecoveryRateQuote > > &quotes)
 
 GaussianLHPLossModel (Real correlation, const std::vector< Real > &recoveries)
 
 GaussianLHPLossModel (const Handle< Quote > &correlQuote, const std::vector< Real > &recoveries)
 
void update () override
 
Real expectedTrancheLoss (const Date &d, Real recoveryRate=Null< Real >()) const override
 
Real probOverLoss (const Date &d, Real remainingLossFraction) const override
 
Real expectedShortfall (const Date &d, Probability perctl) const override
 Returns the ESF as an absolute amount (rather than a fraction) More...
 
Real percentile (const Date &d, Real perctl) const override
 Value at Risk given a default loss percentile. More...
 
Probability averageProb (const Date &d) const
 
Real averageRecovery (const Date &d) const
 

Protected Member Functions

Real percentilePortfolioLossFraction (const Date &d, Real perctl) const
 
Real expectedRecovery (const Date &d, Size iName, const DefaultProbKey &ik) const override
 
- Protected Member Functions inherited from DefaultLossModel
 DefaultLossModel ()
 
virtual Real expectedShortfall (const Date &d, Real percentile) const
 Expected shortfall given a default loss percentile. More...
 
virtual std::vector< Real > splitVaRLevel (const Date &d, Real loss) const
 Associated VaR fraction to each counterparty. More...
 
virtual std::vector< Real > splitESFLevel (const Date &d, Real loss) const
 Associated ESF fraction to each counterparty. More...
 
virtual std::map< Real, Probability > lossDistribution (const Date &) const
 Full loss distribution. More...
 
virtual Real densityTrancheLoss (const Date &d, Real lossFraction) const
 Probability density of a given loss fraction of the basket notional. More...
 
virtual std::vector< Probability > probsBeingNthEvent (Size n, const Date &d) const
 
virtual Real defaultCorrelation (const Date &d, Size iName, Size jName) const
 Pearsons' default probability correlation. More...
 
virtual Probability probAtLeastNEvents (Size n, const Date &d) const
 
virtual QuantLib::Real correlation () const
 

Private Member Functions

void resetModel () override
 Concrete models do now any updates/inits they need on basket reset. More...
 
Real expectedTrancheLossImpl (Real remainingNot, Real prob, Real averageRR, Real attachLimit, Real detachLimit) const
 

Private Attributes

Real sqrt1minuscorrel_
 
Handle< Quote > correl_
 
std::vector< Handle< QuantLib::RecoveryRateQuote > > rrQuotes_
 
Real beta_
 
BivariateCumulativeNormalDistribution biphi_
 

Static Private Attributes

static CumulativeNormalDistribution const phi_ = CumulativeNormalDistribution()
 

Additional Inherited Members

- Protected Attributes inherited from DefaultLossModel
RelinkableHandle< QuantExt::Basketbasket_
 

Detailed Description

Portfolio loss model with analytical expected tranche loss for a large homogeneous pool with Gaussian one-factor copula. See for example "The Normal Inverse Gaussian Distribution for Synthetic CDO pricing.", Anna Kalemanova, Bernd Schmid, Ralf Werner, Journal of Derivatives, Vol. 14, No. 3, (Spring 2007), pp. 80-93. http://www.defaultrisk.com/pp_crdrv_91.htm

It can be used to price a credit derivative or to provide risk metrics of a portfolio.

Definition at line 62 of file gaussianlhplossmodel.hpp.

Member Typedef Documentation

◆ copulaType

typedef GaussianCopulaPolicy copulaType

Definition at line 64 of file gaussianlhplossmodel.hpp.

Constructor & Destructor Documentation

◆ GaussianLHPLossModel() [1/3]

GaussianLHPLossModel ( const Handle< Quote > &  correlQuote,
const std::vector< Handle< QuantLib::RecoveryRateQuote > > &  quotes 
)

◆ GaussianLHPLossModel() [2/3]

GaussianLHPLossModel ( Real  correlation,
const std::vector< Real > &  recoveries 
)

Definition at line 46 of file gaussianlhplossmodel.cpp.

48 // g++ complains default value not seen as typename
49 GaussianCopulaPolicy::initTraits()),
50 sqrt1minuscorrel_(std::sqrt(1. - correlation)),
51 correl_(Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(correlation))), beta_(sqrt(correlation)),
53 for (Size i = 0; i < recoveries.size(); i++)
54 rrQuotes_.push_back(Handle<RecoveryRateQuote>(QuantLib::ext::make_shared<RecoveryRateQuote>(recoveries[i])));
55}
virtual QuantLib::Real correlation() const
std::vector< Handle< QuantLib::RecoveryRateQuote > > rrQuotes_
BivariateCumulativeNormalDistribution biphi_
RandomVariable sqrt(RandomVariable x)
+ Here is the call graph for this function:

◆ GaussianLHPLossModel() [3/3]

GaussianLHPLossModel ( const Handle< Quote > &  correlQuote,
const std::vector< Real > &  recoveries 
)

Definition at line 57 of file gaussianlhplossmodel.cpp.

58 : LatentModel<GaussianCopulaPolicy>(sqrt(correlQuote->value()), recoveries.size(),
59 // g++ complains default value not seen as typename
60 GaussianCopulaPolicy::initTraits()),
61 sqrt1minuscorrel_(std::sqrt(1. - correlQuote->value())), correl_(correlQuote), beta_(sqrt(correlQuote->value())),
62 biphi_(-sqrt(correlQuote->value())) {
63 registerWith(correl_);
64 for (Size i = 0; i < recoveries.size(); i++)
65 rrQuotes_.push_back(Handle<RecoveryRateQuote>(QuantLib::ext::make_shared<RecoveryRateQuote>(recoveries[i])));
66}
+ Here is the call graph for this function:

Member Function Documentation

◆ update()

void update ( )
override

Definition at line 73 of file gaussianlhplossmodel.hpp.

73 {
74 sqrt1minuscorrel_ = std::sqrt(1. - correl_->value());
75 beta_ = std::sqrt(correl_->value());
76 biphi_ = BivariateCumulativeNormalDistribution(-beta_);
77 // tell basket to notify instruments, etc, we are invalid
78 if (!basket_.empty())
79 basket_->notifyObservers();
80 }
RelinkableHandle< QuantExt::Basket > basket_

◆ resetModel()

void resetModel ( )
overrideprivatevirtual

Concrete models do now any updates/inits they need on basket reset.

Implements DefaultLossModel.

Definition at line 83 of file gaussianlhplossmodel.hpp.

83{}

◆ expectedTrancheLossImpl()

Real expectedTrancheLossImpl ( Real  remainingNot,
Real  prob,
Real  averageRR,
Real  attachLimit,
Real  detachLimit 
) const
private
Parameters
attachLimitas a fraction of the underlying live portfolio notional

Definition at line 68 of file gaussianlhplossmodel.cpp.

72 {
73
74 if (attachLimit >= detachLimit)
75 return 0.; // or is it an error?
76 // expected remaining notional:
77 if (remainingNot == 0.)
78 return 0.;
79
80 const Real one = 1.0 - 1.0e-12; // FIXME DUE TO THE INV CUMUL AT 1
81 const Real k1 = std::min(one, attachLimit / (1.0 - averageRR)) + QL_EPSILON;
82 const Real k2 = std::min(one, detachLimit / (1.0 - averageRR)) + QL_EPSILON;
83
84 if (prob > 0) {
85 const Real ip = InverseCumulativeNormal::standard_value(prob);
86 const Real invFlightK1 = (ip - sqrt1minuscorrel_ * InverseCumulativeNormal::standard_value(k1)) / beta_;
87 const Real invFlightK2 = (ip - sqrt1minuscorrel_ * InverseCumulativeNormal::standard_value(k2)) / beta_;
88
89 return remainingNot * (detachLimit * phi_(invFlightK2) - attachLimit * phi_(invFlightK1) +
90 (1. - averageRR) * (biphi_(ip, -invFlightK2) - biphi_(ip, -invFlightK1)));
91 } else
92 return 0.0;
93}
static CumulativeNormalDistribution const phi_
+ Here is the caller graph for this function:

◆ expectedTrancheLoss()

Real expectedTrancheLoss ( const Date &  d,
Real  recoveryRate = Null<Real>() 
) const
overridevirtual

Reimplemented from DefaultLossModel.

Definition at line 94 of file gaussianlhplossmodel.hpp.

94 {
95 // can calls to Basket::remainingNotional(d) be cached?<<<<<<<<<<<<<
96 const Real remainingfullNot = basket_->remainingNotional(d);
97 Real averageRR = recoveryRate != Null<Real>() ? recoveryRate : averageRecovery(d);
98 Probability prob = averageProb(d);
99 Real remainingAttachAmount = basket_->remainingAttachmentAmount();
100 Real remainingDetachAmount = basket_->remainingDetachmentAmount();
101
102 // const Real attach = std::min(remainingAttachAmount
103 // / remainingfullNot, 1.);
104 // const Real detach = std::min(remainingDetachAmount
105 // / remainingfullNot, 1.);
106 const Real attach = remainingAttachAmount / remainingfullNot;
107 const Real detach = remainingDetachAmount / remainingfullNot;
108
109 return expectedTrancheLossImpl(remainingfullNot, prob, averageRR, attach, detach);
110 }
Probability averageProb(const Date &d) const
Real expectedTrancheLossImpl(Real remainingNot, Real prob, Real averageRR, Real attachLimit, Real detachLimit) const
Real averageRecovery(const Date &d) const
+ Here is the call graph for this function:

◆ probOverLoss()

Real probOverLoss ( const Date &  d,
Real  remainingLossFraction 
) const
overridevirtual

The passed remainingLossFraction is in live tranche units, not portfolio as a fraction of the remaining(live) tranche (i.e. a_remaining=0% and det_remaining=100%)

Reimplemented from DefaultLossModel.

Definition at line 95 of file gaussianlhplossmodel.cpp.

95 {
96 // these test goes into basket<<<<<<<<<<<<<<<<<<<<<<<<<
97 QL_REQUIRE(remainingLossFraction >= 0., "Incorrect loss fraction.");
98 QL_REQUIRE(remainingLossFraction <= 1., "Incorrect loss fraction.");
99
100 Real remainingAttachAmount = basket_->remainingAttachmentAmount();
101 Real remainingDetachAmount = basket_->remainingDetachmentAmount();
102 // live unerlying portfolio loss fraction (remaining portf fraction)
103
104 const Real remainingBasktNot = basket_->remainingNotional(d);
105 const Real attach = std::min(remainingAttachAmount / remainingBasktNot, 1.);
106 const Real detach = std::min(remainingDetachAmount / remainingBasktNot, 1.);
107
108 Real portfFract = attach + remainingLossFraction * (detach - attach);
109
110 Real averageRR = averageRecovery(d);
111 Real maxAttLossFract = (1. - averageRR);
112 if (portfFract > maxAttLossFract)
113 return 0.;
114
115 // for non-equity losses add the probability jump at zero tranche
116 // losses (since this method returns prob of losing more or
117 // equal to)
118 if (portfFract <= QL_EPSILON)
119 return 1.;
120
121 Probability prob = averageProb(d);
122
123 Real ip = InverseCumulativeNormal::standard_value(prob);
124 Real invFlightK =
125 (ip - sqrt1minuscorrel_ * InverseCumulativeNormal::standard_value(portfFract / (1. - averageRR))) / beta_;
126
127 return phi_(invFlightK); // probOver
128}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expectedShortfall()

Real expectedShortfall ( const Date &  d,
Probability  perctl 
) const
override

Returns the ESF as an absolute amount (rather than a fraction)

Definition at line 130 of file gaussianlhplossmodel.cpp.

130 {
131 // loss as a fraction of the live portfolio
132 Real ptflLossPerc = percentilePortfolioLossFraction(d, perctl);
133 Real remainingAttachAmount = basket_->remainingAttachmentAmount();
134 Real remainingDetachAmount = basket_->remainingDetachmentAmount();
135
136 const Real remainingNot = basket_->remainingNotional(d);
137 const Real attach = std::min(remainingAttachAmount / remainingNot, 1.);
138 const Real detach = std::min(remainingDetachAmount / remainingNot, 1.);
139
140 if (ptflLossPerc >= detach - QL_EPSILON)
141 return remainingNot * (detach - attach); // equivalent
142
143 Real maxLossLevel = std::max(attach, ptflLossPerc);
144 Probability prob = averageProb(d);
145 Real averageRR = averageRecovery(d);
146
147 Real valA = expectedTrancheLossImpl(remainingNot, prob, averageRR, maxLossLevel, detach);
148 Real valB = // probOverLoss(d, maxLossLevel);//in live tranche units
149 // from fraction of basket notional to fraction of tranche notional
150 probOverLoss(d, std::min(std::max((maxLossLevel - attach) / (detach - attach), 0.), 1.));
151 return (valA + (maxLossLevel - attach) * remainingNot * valB) / (1. - perctl);
152}
Real percentilePortfolioLossFraction(const Date &d, Real perctl) const
Real probOverLoss(const Date &d, Real remainingLossFraction) const override
+ Here is the call graph for this function:

◆ percentilePortfolioLossFraction()

Real percentilePortfolioLossFraction ( const Date &  d,
Real  perctl 
) const
protected

Definition at line 154 of file gaussianlhplossmodel.cpp.

154 {
155 // this test goes into basket<<<<<<<<<<<<<<<<<<<<<<<<<
156 QL_REQUIRE(perctl >= 0. && perctl <= 1., "Percentile argument out of bounds.");
157
158 if (perctl == 0.)
159 return 0.; // portfl == attach
160 if (perctl == 1.)
161 perctl = 1. - QL_EPSILON; // portfl == detach
162
163 return (1. - averageRecovery(d)) * phi_((InverseCumulativeNormal::standard_value(averageProb(d)) +
164 beta_ * InverseCumulativeNormal::standard_value(perctl)) /
166}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expectedRecovery()

Real expectedRecovery ( const Date &  ,
Size  iName,
const DefaultProbKey &   
) const
overrideprotectedvirtual

Expected RR for name conditinal to default by that date.

Reimplemented from DefaultLossModel.

Definition at line 131 of file gaussianlhplossmodel.hpp.

131 {
132 return rrQuotes_[iName].currentLink()->value();
133 }

◆ percentile()

Real percentile ( const Date &  d,
Real  percentile 
) const
overridevirtual

Value at Risk given a default loss percentile.

Reimplemented from DefaultLossModel.

Definition at line 137 of file gaussianlhplossmodel.hpp.

137 {
138 const Real remainingNot = basket_->remainingNotional(d);
139 Real remainingAttachAmount = basket_->remainingAttachmentAmount();
140 Real remainingDetachAmount = basket_->remainingDetachmentAmount();
141 const Real attach = std::min(remainingAttachAmount / remainingNot, 1.);
142 const Real detach = std::min(remainingDetachAmount / remainingNot, 1.);
143 return remainingNot *
144 std::min(std::max(percentilePortfolioLossFraction(d, perctl) - attach, 0.), detach - attach);
145 }
+ Here is the call graph for this function:

◆ averageProb()

Probability averageProb ( const Date &  d) const

Definition at line 147 of file gaussianlhplossmodel.hpp.

147 { // not an overload of Deflossmodel ???<<<<<???
148 // weighted average by programmed exposure.
149 const std::vector<Probability> probs = basket_->remainingProbabilities(d); // use remaining basket
150 const std::vector<Real> remainingNots = basket_->remainingNotionals(d);
151 return std::inner_product(probs.begin(), probs.end(), remainingNots.begin(), 0.) /
152 basket_->remainingNotional(d);
153 }
+ Here is the caller graph for this function:

◆ averageRecovery()

Real averageRecovery ( const Date &  d) const

Definition at line 163 of file gaussianlhplossmodel.hpp.

164 {
165 const std::vector<Probability> probs = basket_->remainingProbabilities(d);
166 std::vector<Real> recoveries;
167 for (Size i = 0; i < basket_->remainingSize(); i++)
168 recoveries.push_back(rrQuotes_[i]->value());
169 std::vector<Real> notionals = basket_->remainingNotionals(d);
170 Real denominator = std::inner_product(notionals.begin(), notionals.end(), probs.begin(), 0.);
171 if (denominator == 0.)
172 return 0.;
173
174 std::transform(notionals.begin(), notionals.end(), probs.begin(), notionals.begin(), std::multiplies<Real>());
175
176 return std::inner_product(recoveries.begin(), recoveries.end(), notionals.begin(), 0.) / denominator;
177 }
+ Here is the caller graph for this function:

Member Data Documentation

◆ sqrt1minuscorrel_

Real sqrt1minuscorrel_
mutableprivate

Definition at line 181 of file gaussianlhplossmodel.hpp.

◆ correl_

Handle<Quote> correl_
private

Definition at line 183 of file gaussianlhplossmodel.hpp.

◆ rrQuotes_

std::vector<Handle<QuantLib::RecoveryRateQuote> > rrQuotes_
private

Definition at line 184 of file gaussianlhplossmodel.hpp.

◆ beta_

Real beta_
private

Definition at line 196 of file gaussianlhplossmodel.hpp.

◆ biphi_

BivariateCumulativeNormalDistribution biphi_
private

Definition at line 197 of file gaussianlhplossmodel.hpp.

◆ phi_

CumulativeNormalDistribution const phi_ = CumulativeNormalDistribution()
staticprivate

Definition at line 198 of file gaussianlhplossmodel.hpp.