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

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

#include <qle/models/homogeneouspooldef.hpp>

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

Public Member Functions

 HomogeneousPoolLossModel (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::HomogeneousPoolLossModel< copulaPolicy >

Default loss distribution convolution for finite homogeneous pool.

Definition at line 44 of file homogeneouspooldef.hpp.

Constructor & Destructor Documentation

◆ HomogeneousPoolLossModel()

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

Definition at line 49 of file homogeneouspooldef.hpp.

51 : copula_(copula), nBuckets_(nBuckets), max_(max), min_(min), nSteps_(nSteps), delta_((max - min) / nSteps) {
52 QL_REQUIRE(copula->numFactors() == 1, "Inhomogeneous model not implemented for multifactor");
53 }
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 118 of file homogeneouspooldef.hpp.

118 {
119 // need to be capped now since the limit amounts might be over the
120 // remaining notional (think amortizing)
121 attach_ = std::min(basket_->remainingAttachmentAmount() / basket_->remainingNotional(), 1.);
122 detach_ = std::min(basket_->remainingDetachmentAmount() / basket_->remainingNotional(), 1.);
123 notional_ = basket_->remainingNotional();
124 notionals_ = basket_->remainingNotionals();
125 attachAmount_ = basket_->remainingAttachmentAmount();
126 detachAmount_ = basket_->remainingDetachmentAmount();
127
128 copula_->resetBasket(basket_.currentLink());
129}
RelinkableHandle< QuantExt::Basket > basket_

◆ lossDistrib()

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

Definition at line 132 of file homogeneouspooldef.hpp.

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

◆ expectedTrancheLoss()

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

Definition at line 61 of file homogeneouspooldef.hpp.

61 {
62 Distribution dist = lossDistrib(d, zeroRecovery);
63 // RL: dist.trancheExpectedValue() using x = dist.average(i)
64 // FIXME: some remaining inaccuracy in dist.cumulativeDensity(detachAmount_)
65 Real expectedLoss = 0;
66 dist.normalize();
67 for (Size i = 0; i < dist.size(); i++) {
68 // Real x = dist.x(i) + dist.dx(i)/2; // in QL distribution.cpp
69 Real x = dist.average(i);
70 if (x < attachAmount_)
71 continue;
72 if (x > detachAmount_)
73 break;
74 expectedLoss += (x - attachAmount_) * dist.dx(i) * dist.density(i);
75 }
76 expectedLoss += (detachAmount_ - attachAmount_) * (1.0 - dist.cumulativeDensity(detachAmount_));
77 return expectedLoss;
78
79 return lossDistrib(d, zeroRecovery).cumulativeExcessProbability(attachAmount_, detachAmount_);
80 // This one if the distribution is over the whole loss structure:
81 // but it becomes very expensive
82 /*
83 return lossDistrib(d).trancheExpectedValue(attach_ * notional_,
84 detach_ * notional_);
85 */
86 }
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 87 of file homogeneouspooldef.hpp.

87 {
88 Real portfLoss = lossDistrib(d).confidenceLevel(percentile);
89 return std::min(std::max(portfLoss - attachAmount_, 0.), detachAmount_ - attachAmount_);
90 }
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 91 of file homogeneouspooldef.hpp.

91 {
92 Distribution dist = lossDistrib(d);
93 dist.tranche(attachAmount_, detachAmount_);
94 return dist.expectedShortfall(percentile);
95 }
+ Here is the call graph for this function:

Member Data Documentation

◆ copula_

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

Definition at line 98 of file homogeneouspooldef.hpp.

◆ nBuckets_

Size nBuckets_
protected

Definition at line 99 of file homogeneouspooldef.hpp.

◆ attach_

Real attach_
mutableprotected

Definition at line 100 of file homogeneouspooldef.hpp.

◆ detach_

Real detach_
protected

Definition at line 100 of file homogeneouspooldef.hpp.

◆ notional_

Real notional_
protected

Definition at line 100 of file homogeneouspooldef.hpp.

◆ attachAmount_

Real attachAmount_
protected

Definition at line 100 of file homogeneouspooldef.hpp.

◆ detachAmount_

Real detachAmount_
protected

Definition at line 100 of file homogeneouspooldef.hpp.

◆ notionals_

std::vector<Real> notionals_
mutableprotected

Definition at line 101 of file homogeneouspooldef.hpp.

◆ max_

const Real max_
private

Definition at line 107 of file homogeneouspooldef.hpp.

◆ min_

const Real min_
private

Definition at line 108 of file homogeneouspooldef.hpp.

◆ nSteps_

const Real nSteps_
private

Definition at line 109 of file homogeneouspooldef.hpp.

◆ delta_

const Real delta_
private

Definition at line 110 of file homogeneouspooldef.hpp.