Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
InhomogeneousPoolLossModel< copulaPolicy > Class Template Reference

Default loss distribution convolution for finite non homogeneous pool. More...

#include <qle/models/inhomogeneouspooldef.hpp>

+ Inheritance diagram for InhomogeneousPoolLossModel< copulaPolicy >:
+ Collaboration diagram for InhomogeneousPoolLossModel< copulaPolicy >:

Public Types

typedef copulaPolicy copulaType
 

Public Member Functions

 InhomogeneousPoolLossModel (const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > &copula, Size nBuckets, Real max=5., Real min=-5., Real nSteps=50)
 
Real expectedTrancheLoss (const Date &d, bool zeroRecovery=false) const
 
Real percentile (const Date &d, Real percentile) const
 Value at Risk given a default loss percentile. More...
 
Real expectedShortfall (const Date &d, Probability percentile) const
 

Protected Member Functions

Distribution lossDistrib (const Date &d, bool zeroRecovery=false) const
 
- Protected Member Functions inherited from DefaultLossModel
 DefaultLossModel ()
 
virtual Real expectedTrancheLoss (const Date &d, Real recoveryRate=Null< Real >()) const
 
virtual Probability probOverLoss (const Date &d, Real lossFraction) const
 
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 Real expectedRecovery (const Date &, Size iName, const DefaultProbKey &) const
 
virtual QuantLib::Real correlation () const
 

Protected Attributes

const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > copula_
 
Size nBuckets_
 
Real attach_
 
Real detach_
 
Real notional_
 
Real attachAmount_
 
Real detachAmount_
 
std::vector< Real > notionals_
 
- Protected Attributes inherited from DefaultLossModel
RelinkableHandle< QuantExt::Basketbasket_
 

Private Member Functions

void resetModel ()
 Concrete models do now any updates/inits they need on basket reset. More...
 

Private Attributes

const Real max_
 
const Real min_
 
const Real nSteps_
 
const Real delta_
 

Detailed Description

template<class copulaPolicy>
class QuantExt::InhomogeneousPoolLossModel< copulaPolicy >

Default loss distribution convolution for finite non homogeneous pool.

Definition at line 47 of file inhomogeneouspooldef.hpp.

Member Typedef Documentation

◆ copulaType

typedef copulaPolicy copulaType

Definition at line 53 of file inhomogeneouspooldef.hpp.

Constructor & Destructor Documentation

◆ InhomogeneousPoolLossModel()

InhomogeneousPoolLossModel ( const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > &  copula,
Size  nBuckets,
Real  max = 5.,
Real  min = -5.,
Real  nSteps = 50 
)

Definition at line 55 of file inhomogeneouspooldef.hpp.

59 : copula_(copula), nBuckets_(nBuckets), max_(max), min_(min), nSteps_(nSteps), delta_((max - min) / nSteps) {
60 QL_REQUIRE(copula->numFactors() == 1, "Inhomogeneous model not implemented for multifactor");
61 }
const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > copula_
+ Here is the call graph for this function:

Member Function Documentation

◆ resetModel()

void resetModel ( )
privatevirtual

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

Implements DefaultLossModel.

Definition at line 126 of file inhomogeneouspooldef.hpp.

126 {
127 // need to be capped now since the limit amounts might be over the
128 // remaining notional (think amortizing)
129 attach_ = std::min(basket_->remainingAttachmentAmount() / basket_->remainingNotional(), 1.);
130 detach_ = std::min(basket_->remainingDetachmentAmount() / basket_->remainingNotional(), 1.);
131 notional_ = basket_->remainingNotional();
132 notionals_ = basket_->remainingNotionals();
133 attachAmount_ = basket_->remainingAttachmentAmount();
134 detachAmount_ = basket_->remainingDetachmentAmount();
135
136 copula_->resetBasket(basket_.currentLink());
137}
RelinkableHandle< QuantExt::Basket > basket_

◆ lossDistrib()

Distribution lossDistrib ( const Date &  d,
bool  zeroRecovery = false 
) const
protected

Definition at line 139 of file inhomogeneouspooldef.hpp.

139 {
140 LossDistBucketing bucktLDistBuff(nBuckets_, detachAmount_);
141
142 std::vector<Real> lgd; // switch to a mutable cache member
143 // RL: additional option used to set set recovery rates to zero
144 std::vector<Real> recoveries =
145 zeroRecovery ? std::vector<Real>(copula_->recoveries().size(), 0.0) : copula_->recoveries();
146 std::transform(recoveries.begin(), recoveries.end(), std::back_inserter(lgd), [](Real x) { return 1.0 - x; });
147 std::transform(lgd.begin(), lgd.end(), notionals_.begin(), lgd.begin(), std::multiplies<Real>());
148 std::vector<Real> prob = basket_->remainingProbabilities(d);
149 for (Size iName = 0; iName < prob.size(); iName++)
150 prob[iName] = copula_->inverseCumulativeY(prob[iName], iName);
151
152 // integrate locally (1 factor).
153 // use explicitly a 1D latent model object?
154 // \todo Use a library integrator here and in the homogeneous case.
155 Distribution dist(nBuckets_, 0.0, detachAmount_);
156 // notional_);
157 std::vector<Real> mkft(1, min_ + delta_ / 2.);
158 for (Size i = 0; i < nSteps_; i++) {
159 std::vector<Real> conditionalProbs;
160 for (Size iName = 0; iName < notionals_.size(); iName++)
161 conditionalProbs.push_back(copula_->conditionalDefaultProbabilityInvP(prob[iName], iName, mkft));
162 Distribution d = bucktLDistBuff(lgd, conditionalProbs);
163 Real densitydm = delta_ * copula_->density(mkft);
164 // also, instead of calling the static method it could be wrapped
165 // through an inlined call in the latent model
166 for (Size j = 0; j < nBuckets_; j++) {
167 dist.addDensity(j, d.density(j) * densitydm);
168 dist.addAverage(j, d.average(j) * densitydm); // RL
169 }
170 mkft[0] += delta_;
171 }
172 return dist;
173}
+ Here is the caller graph for this function:

◆ expectedTrancheLoss()

Real expectedTrancheLoss ( const Date &  d,
bool  zeroRecovery = false 
) const

Definition at line 69 of file inhomogeneouspooldef.hpp.

69 {
70 Distribution dist = lossDistrib(d, zeroRecovery);
71 // RL: dist.trancheExpectedValue() using x = dist.average(i)
72 // FIXME: some remaining inaccuracy in dist.cumulativeDensity(detachAmount_)
73 Real expectedLoss = 0;
74 dist.normalize();
75 for (Size i = 0; i < dist.size(); i++) {
76 // Real x = dist.x(i) + dist.dx(i)/2; // in QL distribution.cpp
77 Real x = dist.average(i);
78 if (x < attachAmount_)
79 continue;
80 if (x > detachAmount_)
81 break;
82 expectedLoss += (x - attachAmount_) * dist.dx(i) * dist.density(i);
83 }
84 expectedLoss += (detachAmount_ - attachAmount_) * (1.0 - dist.cumulativeDensity(detachAmount_));
85 return expectedLoss;
86
87 return lossDistrib(d, zeroRecovery).cumulativeExcessProbability(attachAmount_, detachAmount_);
88 // This one if the distribution is over the whole loss structure:
89 // but it becomes very expensive
90 /*
91 return lossDistrib(d).trancheExpectedValue(
92 attachAmount_, detachAmount_);
93 */
94 }
Distribution lossDistrib(const Date &d, bool zeroRecovery=false) const
+ Here is the call graph for this function:

◆ percentile()

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

Value at Risk given a default loss percentile.

Reimplemented from DefaultLossModel.

Definition at line 95 of file inhomogeneouspooldef.hpp.

95 {
96 Real portfLoss = lossDistrib(d).confidenceLevel(percentile);
97 return std::min(std::max(portfLoss - attachAmount_, 0.), detachAmount_ - attachAmount_);
98 }
Real percentile(const Date &d, Real percentile) const
Value at Risk given a default loss percentile.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ expectedShortfall()

Real expectedShortfall ( const Date &  d,
Probability  percentile 
) const

Definition at line 99 of file inhomogeneouspooldef.hpp.

99 {
100 Distribution dist = lossDistrib(d);
101 dist.tranche(attachAmount_, detachAmount_);
102 return dist.expectedShortfall(percentile);
103 }
+ Here is the call graph for this function:

Member Data Documentation

◆ copula_

const QuantLib::ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> > copula_
protected

Definition at line 106 of file inhomogeneouspooldef.hpp.

◆ nBuckets_

Size nBuckets_
protected

Definition at line 107 of file inhomogeneouspooldef.hpp.

◆ attach_

Real attach_
mutableprotected

Definition at line 108 of file inhomogeneouspooldef.hpp.

◆ detach_

Real detach_
protected

Definition at line 108 of file inhomogeneouspooldef.hpp.

◆ notional_

Real notional_
protected

Definition at line 108 of file inhomogeneouspooldef.hpp.

◆ attachAmount_

Real attachAmount_
protected

Definition at line 108 of file inhomogeneouspooldef.hpp.

◆ detachAmount_

Real detachAmount_
protected

Definition at line 108 of file inhomogeneouspooldef.hpp.

◆ notionals_

std::vector<Real> notionals_
mutableprotected

Definition at line 109 of file inhomogeneouspooldef.hpp.

◆ max_

const Real max_
private

Definition at line 115 of file inhomogeneouspooldef.hpp.

◆ min_

const Real min_
private

Definition at line 116 of file inhomogeneouspooldef.hpp.

◆ nSteps_

const Real nSteps_
private

Definition at line 117 of file inhomogeneouspooldef.hpp.

◆ delta_

const Real delta_
private

Definition at line 118 of file inhomogeneouspooldef.hpp.