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

#include <qle/models/poollossmodel.hpp>

+ Inheritance diagram for PoolLossModel< CopulaPolicy >:
+ Collaboration diagram for PoolLossModel< CopulaPolicy >:

Public Member Functions

 PoolLossModel (bool homogeneous, const QuantLib::ext::shared_ptr< ExtendedConstantLossLatentModel< CopulaPolicy > > &copula, QuantLib::Size nBuckets, QuantLib::Real max=5.0, QuantLib::Real min=-5.0, QuantLib::Size nSteps=50, bool useQuadrature=false, bool useStochasticRecovery=false)
 
QuantLib::Real expectedTrancheLoss (const QuantLib::Date &d, Real recoveryRate=Null< Real >()) const override
 
QuantLib::Real percentile (const QuantLib::Date &d, QuantLib::Real percentile) const override
 
QuantLib::Real expectedShortfall (const QuantLib::Date &d, QuantLib::Probability percentile) const override
 
QuantLib::Real correlation () const override
 
std::vector< std::vector< Real > > marginalProbabilitiesVV (Date d, Real recoveryRate=Null< Real >()) const
 

Private Member Functions

QuantLib::Distribution lossDistrib (const QuantLib::Date &d, Real recoveryRate=Null< Real >()) const
 
void updateLGDs (Real recoveryRate=Null< Real >()) const
 
void updateThresholds (QuantLib::Date d, Real recoveryRate=Null< Real >()) const
 
std::vector< Real > updateCPRs (std::vector< QuantLib::Real > factor, Real recoveryRate=Null< Real >()) const
 
void resetModel () override
 Concrete models do now any updates/inits they need on basket reset. More...
 
QuantLib::Real expectedTrancheLoss1 (const QuantLib::Date &d, Distribution &dist) const
 
QuantLib::Real expectedTrancheLoss2 (const QuantLib::Date &d, const Array &p, const Array &A) const
 

Private Attributes

bool homogeneous_
 
QuantLib::ext::shared_ptr< ExtendedConstantLossLatentModel< CopulaPolicy > > copula_
 
QuantLib::Size nBuckets_
 
QuantLib::Real max_
 
QuantLib::Real min_
 
QuantLib::Size nSteps_
 
bool useQuadrature_
 
bool useStochasticRecovery_
 
QuantLib::Real delta_
 
QuantLib::Real attach_
 
QuantLib::Real detach_
 
QuantLib::Real notional_
 
QuantLib::Real attachAmount_
 
QuantLib::Real detachAmount_
 
std::vector< QuantLib::Real > notionals_
 
std::vector< QuantLib::Real > lgd_
 
std::vector< std::vector< QuantLib::Real > > q_
 
std::vector< std::vector< QuantLib::Real > > c_
 
std::vector< std::vector< QuantLib::Real > > lgdVV_
 
std::vector< std::vector< QuantLib::Real > > cprVV_
 

Additional Inherited Members

- 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 percentile (const Date &d, Real percentile) const
 Value at Risk given a default loss percentile. More...
 
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
 
- Protected Attributes inherited from DefaultLossModel
RelinkableHandle< QuantExt::Basketbasket_
 

Detailed Description

template<class CopulaPolicy>
class QuantExt::PoolLossModel< CopulaPolicy >

Default loss distribution convolution for finite homogeneous or non-homogeneous pool

Definition at line 38 of file poollossmodel.hpp.

Constructor & Destructor Documentation

◆ PoolLossModel()

PoolLossModel ( bool  homogeneous,
const QuantLib::ext::shared_ptr< ExtendedConstantLossLatentModel< CopulaPolicy > > &  copula,
QuantLib::Size  nBuckets,
QuantLib::Real  max = 5.0,
QuantLib::Real  min = -5.0,
QuantLib::Size  nSteps = 50,
bool  useQuadrature = false,
bool  useStochasticRecovery = false 
)

Definition at line 139 of file poollossmodel.hpp.

148 : homogeneous_(homogeneous),
149 copula_(copula),
150 nBuckets_(nBuckets),
151 max_(max),
152 min_(min),
153 nSteps_(nSteps),
154 useQuadrature_(useQuadrature),
155 useStochasticRecovery_(useStochasticRecovery),
156 delta_((max - min) / nSteps),
157 attach_(0.0),
158 detach_(0.0),
159 notional_(0.0),
160 attachAmount_(0.0),
161 detachAmount_(0.0) {
162
163 QL_REQUIRE(copula->numFactors() == 1, "Multifactor PoolLossModel not yet implemented.");
164}
QuantLib::ext::shared_ptr< ExtendedConstantLossLatentModel< CopulaPolicy > > copula_
QuantLib::Real detachAmount_
QuantLib::Real notional_
QuantLib::Size nBuckets_
QuantLib::Real attachAmount_
+ Here is the call graph for this function:

Member Function Documentation

◆ expectedTrancheLoss()

QuantLib::Real expectedTrancheLoss ( const QuantLib::Date &  d,
Real  recoveryRate = Null<Real>() 
) const
override

Definition at line 167 of file poollossmodel.hpp.

167 {
168
169 QuantLib::Distribution dist = lossDistrib(d, recoveryRate);
170
171 // RL: dist.trancheExpectedValue() using x = dist.average(i)
172 // FIXME: some remaining inaccuracy in dist.cumulativeDensity(detachAmount_)
173 QuantLib::Real expectedLoss = 0;
174 dist.normalize();
175 for (QuantLib::Size i = 0; i < dist.size(); i++) {
176 // Real x = dist.x(i) + dist.dx(i)/2; // in QL distribution.cpp
177 QuantLib::Real x = dist.average(i);
178 if (x < attachAmount_)
179 continue;
180 if (x > detachAmount_)
181 break;
182 expectedLoss += (x - attachAmount_) * dist.dx(i) * dist.density(i);
183 }
184 expectedLoss += (detachAmount_ - attachAmount_) * (1.0 - dist.cumulativeDensity(detachAmount_));
185
186 return expectedLoss;
187}
QuantLib::Distribution lossDistrib(const QuantLib::Date &d, Real recoveryRate=Null< Real >()) const

◆ percentile()

QuantLib::Real percentile ( const QuantLib::Date &  d,
QuantLib::Real  percentile 
) const
override

Definition at line 229 of file poollossmodel.hpp.

229 {
230 QuantLib::Real portfLoss = lossDistrib(d).confidenceLevel(percentile);
231 return std::min(std::max(portfLoss - attachAmount_, 0.), detachAmount_ - attachAmount_);
232}
QuantLib::Real percentile(const QuantLib::Date &d, QuantLib::Real percentile) const override

◆ expectedShortfall()

QuantLib::Real expectedShortfall ( const QuantLib::Date &  d,
QuantLib::Probability  percentile 
) const
override

Definition at line 235 of file poollossmodel.hpp.

236 {
237
238 QuantLib::Distribution dist = lossDistrib(d);
239 dist.tranche(attachAmount_, detachAmount_);
240 return dist.expectedShortfall(percentile);
241}

◆ correlation()

QuantLib::Real correlation
overridevirtual

Return single correlation number for one factor models. If not implemented or not applicable, returns a Null<Real>().

Reimplemented from DefaultLossModel.

Definition at line 244 of file poollossmodel.hpp.

244 {
245
246 const std::vector<std::vector<QuantLib::Real> >& weights = copula_->factorWeights();
247
248 if (weights.empty() || weights[0].size() != 1) {
249 return QuantLib::Null<QuantLib::Real>();
250 }
251
252 QuantLib::Real res = weights[0][0];
253 for (QuantLib::Size i = 1; i < weights.size(); ++i) {
254 if (weights[i].size() != 1 || !close(res, weights[i][0])) {
255 return QuantLib::Null<QuantLib::Real>();
256 }
257 }
258
259 return res * res;
260}

◆ marginalProbabilitiesVV()

std::vector< std::vector< Real > > marginalProbabilitiesVV ( Date  d,
Real  recoveryRate = Null<Real>() 
) const

Definition at line 334 of file poollossmodel.hpp.

334 {
335
336 std::vector<QuantLib::Real> prob = basket_->remainingProbabilities(d);
337 std::vector<std::vector<QuantLib::Real>> probVV(notionals_.size(), std::vector<Real>());
338 if (!useStochasticRecovery_ || recoveryRate == Null<Real>()) {
339 for (Size i = 0; i < notionals_.size(); ++i)
340 probVV[i].resize(1, prob[i]);
341 return probVV;
342 } else {
343 QL_REQUIRE(copula_->recoveryProbabilities().size() == notionals_.size(),
344 "number of rec rate probability vectors does not match number of notionals");
345 for (Size i = 0; i < notionals_.size(); ++i) {
346 Real pd = prob[i];
347 std::vector<Real> rrProbs = copula_->recoveryProbabilities()[i];
348 probVV[i].resize(rrProbs.size(), 0.0);
349 for (Size j = 0; j < rrProbs.size(); ++j)
350 probVV[i][j] = pd * rrProbs[j];
351 }
352 return probVV;
353 }
354}
RelinkableHandle< QuantExt::Basket > basket_
std::vector< QuantLib::Real > notionals_

◆ lossDistrib()

QuantLib::Distribution lossDistrib ( const QuantLib::Date &  d,
Real  recoveryRate = Null<Real>() 
) const
private

Definition at line 404 of file poollossmodel.hpp.

404 {
405
406 bool check = false;
407
408 Real maximum = detachAmount_;
409 Real minimum = 0.0;
410
411 // Update the LGD vector, could be moved to resetModel() if we can disregard the zeroRecovery flag
412 updateLGDs(recoveryRate);
413
414 // Update probabilities qij and thresholds cij, needs to stay here because date dependent
415 updateThresholds(d, recoveryRate);
416
417 // Init bucketing class
418 HullWhiteBucketing hwb(minimum, maximum, nBuckets_);
419
420 // Container for the final (unconditional) loss distribution up to date d.
421 Array p(hwb.buckets()-1, 0.0), A(hwb.buckets()-1, 0.0);
422 QuantLib::Distribution dist(nBuckets_, minimum, maximum);
423
424 // Use the relevant loss bucketing algorithm
425 QuantLib::ext::shared_ptr<QuantLib::LossDist> bucketing;
426 if (homogeneous_)
427 bucketing = QuantLib::ext::make_shared<QuantLib::LossDistHomogeneous>(nBuckets_, maximum);
428 else
429 bucketing = QuantLib::ext::make_shared<QuantLib::LossDistBucketing>(nBuckets_, maximum);
430
431 // Is the ql bucketing used?
432 bool useQlBucketing = false;
433
434 // Switch between quadrature integration and basic segment type scheme.
436
437 // FIXME: Ensure quadrature works with stochastic recovery
438
439 QuantLib::GaussHermiteIntegration Integrator(nSteps_);
440 // Marginal probabilities for each remaining entity in basket, P(\tau_i < t).
441 std::vector<QuantLib::Real> prob = basket_->remainingProbabilities(d);
442 LossModelConditionalDist<CopulaPolicy> lmcd(copula_, bucketing, prob, lgd_);
443
444 for (QuantLib::Size j = 0; j < nBuckets_; j++) {
445 std::function<QuantLib::Real(QuantLib::Real)> densityFunc = std::bind(
446 &LossModelConditionalDist<CopulaPolicy>::conditionalDensity, &lmcd, std::placeholders::_1, j);
447 std::function<QuantLib::Real(QuantLib::Real)> averageFunc = std::bind(
448 &LossModelConditionalDist<CopulaPolicy>::conditionalAverage, &lmcd, std::placeholders::_1, j);
449 dist.addDensity(j, Integrator(densityFunc));
450 dist.addAverage(j, Integrator(averageFunc));
451 }
452
453 useQlBucketing = true;
454
455 } else {
456
457 std::vector<QuantLib::Real> factor{ min_ + delta_ / 2.0 };
458
459 for (QuantLib::Size k = 0; k < nSteps_; k++) {
460
461 std::vector<Real> cpr = updateCPRs(factor, recoveryRate);
462
463 // Loss distribution up to date d conditional on common factor M = m.
464 Distribution conditionalDist;
466 // HW bucketing with multi-state extension for stochastic recovery
467 // With stochastic recovery the portfolios is in general not homogeneous any more, so that
468 // bucketing is the only choice. We could use this call in all cases (including deterministic
469 // recovery, homogeneous pool), but this can cause small regression errors (using bucketing
470 // instead of homogeneoius pool algorithm) and calculation time increase (QuantLib::LossDist's
471 // bucketing is faster).
472 hwb.computeMultiState(cprVV_.begin(), cprVV_.end(), lgdVV_.begin());
473 }
474 else if (homogeneous_) {
475 // Original QuantLib::LossDist (homogeneous), works with deterministic recovery only.
476 // If possible we use the homogeneous algorithm in QuantLib::LossDist. This also avoids small
477 // regression errors from switching to any of the bucketing algorithms in the homogeneous case.
478 conditionalDist = (*bucketing)(lgd_, cpr);
479 useQlBucketing = true;
480 }
481 else {
482 // We could use hwb.computeMultiState here as well, yields the same result,
483 // but compute is slightly faster than computeMultiState.
484 hwb.compute(cpr.begin(), cpr.end(), lgd_.begin());
485 }
486
487 // Update final distribution with contribution from common factor M = m.
488 Real densitydm = delta_ * copula_->density(factor);
489
490 if (useQlBucketing) {
491 for (Size j = 0; j < nBuckets_; j++) {
492 dist.addDensity(j, conditionalDist.density(j) * densitydm);
493 dist.addAverage(j, conditionalDist.average(j) * densitydm);
494 }
495 }
496 else {
497 // Bucket 0 contains losses up to lowerBound, and bucket 1 from [lowerBound, lowerBound + dx),
498 // together both buckets contains (-inf, lowerBound + dx)
499 // Since we dont have any negative losses in a CDO its [0, dx)
500 double p0 = (hwb.probability()[0] + hwb.probability()[1]);
501 double A0 = 0;
502 if (!QuantLib::close_enough(p0, 0.0)) {
503 A0 = (hwb.averageLoss()[0] * hwb.probability()[0] + hwb.averageLoss()[1] * hwb.probability()[1]) / p0;
504 }
505 p[0] += p0 * densitydm;
506 A[0] += A0 * densitydm;
507
508 for (Size j = 2; j < hwb.buckets(); j++) {
509 p[j-1] += hwb.probability()[j] * densitydm;
510 A[j-1] += hwb.averageLoss()[j] * densitydm;
511 }
512 }
513
514 // Move to next value of common factor in [min,max] region.
515 factor[0] += delta_;
516 }
517
518 if (!useQlBucketing) {
519 // Copy results to distribution, skip the right-most bucket (maximum, infty)
520 for (Size j = 0; j < nBuckets_; j++) {
521 dist.addDensity(j, p[j] / dist.dx(j));
522 dist.addAverage(j, A[j]);
523 }
524 }
525 }
526
527 if (check && !useQlBucketing) {
528 // This checks the consistency between the Distribution object and the "raw" p and A vectors
529 // by way of expectedTrancheLoss calculations.
530 // Can be deactivated because of its performance impact.
531 Real etl1 = expectedTrancheLoss1(d, dist);
532 Real etl2 = expectedTrancheLoss2(d, p, A);
533 Real tiny = 1e-3;
534 QL_REQUIRE(fabs((etl1 - etl2)/etl2) < tiny, "expected tranche loss failed, " << etl1 << " vs " << etl2);
535 }
536
537 return dist;
538}
QuantLib::Real conditionalDensity(QuantLib::Real factor, QuantLib::Size bucket)
QuantLib::Real conditionalAverage(QuantLib::Real factor, QuantLib::Size bucket)
std::vector< std::vector< QuantLib::Real > > cprVV_
std::vector< Real > updateCPRs(std::vector< QuantLib::Real > factor, Real recoveryRate=Null< Real >()) const
QuantLib::Real expectedTrancheLoss2(const QuantLib::Date &d, const Array &p, const Array &A) const
void updateThresholds(QuantLib::Date d, Real recoveryRate=Null< Real >()) const
QuantLib::Real expectedTrancheLoss1(const QuantLib::Date &d, Distribution &dist) const
std::vector< std::vector< QuantLib::Real > > lgdVV_
std::vector< QuantLib::Real > lgd_
void updateLGDs(Real recoveryRate=Null< Real >()) const
+ Here is the call graph for this function:

◆ updateLGDs()

void updateLGDs ( Real  recoveryRate = Null<Real>()) const
private

Definition at line 263 of file poollossmodel.hpp.

263 {
264
265 // one LGD per entity, notional modified with deterministic recovery rate
267 const std::vector<Real>& recoveries = copula_->recoveries();
268 for (QuantLib::Size i = 0; i < notionals_.size(); ++i) {
269 if (recoveryRate != Null<Real>())
270 lgd_[i] *= (1 - recoveryRate);
271 else
272 lgd_[i] *= (1 - recoveries[i]);
273 }
274
275 // Initialize the LGD matrix for stochastic recovery
276 lgdVV_.clear();
277 lgdVV_.resize(notionals_.size(), std::vector<Real>());
278 for (Size i = 0; i < notionals_.size(); ++i) {
279 if (recoveryRate != Null<Real>())
280 lgdVV_[i].push_back(notionals_[i] * (1.0 - recoveryRate));
281 else if (!useStochasticRecovery_)
282 lgdVV_[i].push_back(notionals_[i] * (1.0 - recoveries[i]));
283 else {
284 const std::vector<Real>& rrGrid = copula_->recoveryRateGrids()[i];
285 for (Size j = 0; j < rrGrid.size(); ++j) {
286 QL_REQUIRE(j == 0 || rrGrid[j] <= rrGrid[j-1], "recovery rates need to be sorted in decreasing order");
287 // j == 0 corresponds to the lowest recovery or largest loss
288 lgdVV_[i].push_back(notionals_[i] * (1.0 - rrGrid[j]));
289 }
290 // std::cout << std::endl;
291 }
292 }
293}

◆ updateThresholds()

void updateThresholds ( QuantLib::Date  d,
Real  recoveryRate = Null<Real>() 
) const
private

Definition at line 296 of file poollossmodel.hpp.

296 {
297 // Initialize probability of default function Q and thresholds C according to spec
298
299 // Marginal probabilities of default for each remaining entity in basket
300 std::vector<QuantLib::Real> prob = basket_->remainingProbabilities(d);
301
302 q_.resize(notionals_.size());
303 c_.resize(notionals_.size());
304
305 if (useStochasticRecovery_ && recoveryRate == Null<Real>()) {
306 Real tiny = 1.0e-10;
307 for (Size i = 0; i < notionals_.size(); ++i) {
308 QL_REQUIRE(copula_->recoveryProbabilities().size() == notionals_.size(),
309 "number of rec rate probability vectors does not match number of notionals");
310 std::vector<Real> rrProbs = copula_->recoveryProbabilities()[i];
311 q_[i] = std::vector<Real>(rrProbs.size() + 1, prob[i]);
312 c_[i] = std::vector<Real>(rrProbs.size() + 1, copula_->inverseCumulativeY(q_[i][0], i));
313 Real sum = 0.0;
314 for (Size j = 0; j < rrProbs.size(); ++j) {
315 sum += rrProbs[j];
316 q_[i][j+1] = q_[i][0] * (1.0 - sum);
317 if (QuantLib::close_enough(q_[i][j+1], 0.0))
318 c_[i][j+1] = QL_MIN_REAL;
319 else
320 c_[i][j+1] = copula_->inverseCumulativeY(q_[i][j+1], i);
321 }
322 QL_REQUIRE(fabs(q_[i].back()) < tiny, "expected zero qij, but found " << q_[i].back() << " for i=" << i);
323 }
324 }
325 else {
326 for (QuantLib::Size i = 0; i < prob.size(); i++) {
327 q_[i] = std::vector<Real>(1, prob[i]);
328 c_[i] = std::vector<Real>(1, copula_->inverseCumulativeY(prob[i], i));
329 }
330 }
331}
std::vector< std::vector< QuantLib::Real > > q_
std::vector< std::vector< QuantLib::Real > > c_
Real sum(const Cash &c, const Cash &d)
Definition: bondbasket.cpp:107
+ Here is the call graph for this function:

◆ updateCPRs()

std::vector< Real > updateCPRs ( std::vector< QuantLib::Real >  factor,
Real  recoveryRate = Null<Real>() 
) const
private

Definition at line 357 of file poollossmodel.hpp.

357 {
358 cprVV_.clear();
359
360 Real tiny = 1.0e-10;
361 if (useStochasticRecovery_ && recoveryRate == Null<Real>()) {
362 cprVV_.resize(notionals_.size(), std::vector<Real>());
363 for (Size i = 0; i < c_.size(); ++i) {
364 cprVV_[i].resize(c_[i].size() - 1, 0.0);
365 Real pd = copula_->conditionalDefaultProbabilityInvP(c_[i][0], i, factor);
366 Real sum = 0.0;
367 for (Size j = 1; j < c_[i].size(); ++j) {
368 // probability of recovery j conditional on default of i
369 cprVV_[i][j-1] = copula_->conditionalDefaultProbabilityInvP(c_[i][j-1], i, factor)
370 - copula_->conditionalDefaultProbabilityInvP(c_[i][j], i, factor);
371 sum += cprVV_[i][j-1];
372 }
373 QL_REQUIRE(fabs(sum - pd) < tiny, "probability check failed for factor0 " << factor[0]);
374 }
375 }
376 else {
377 cprVV_.resize(notionals_.size(), std::vector<Real>(1, 0));
378 for (Size i = 0; i < c_.size(); ++i) {
379 cprVV_[i][0] = copula_->conditionalDefaultProbabilityInvP(c_[i][0], i, factor);
380 }
381 }
382
383 // Vector of default probabilities conditional on the common market factor M: P(\tau_i < t | M = m).
384 std::vector<Real> probs;
385 for (Size i = 0; i < c_.size(); i++)
386 probs.push_back(copula_->conditionalDefaultProbabilityInvP(c_[i][0], i, factor));
387
388 return probs;
389}
+ Here is the call graph for this function:

◆ resetModel()

void resetModel ( )
overrideprivatevirtual

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

Implements DefaultLossModel.

Definition at line 392 of file poollossmodel.hpp.

392 {
393 // need to be capped now since the limit amounts might be over the remaining notional (think amortizing)
394 attach_ = std::min(basket_->remainingAttachmentAmount() / basket_->remainingNotional(), 1.);
395 detach_ = std::min(basket_->remainingDetachmentAmount() / basket_->remainingNotional(), 1.);
396 notional_ = basket_->remainingNotional();
397 notionals_ = basket_->remainingNotionals();
398 attachAmount_ = basket_->remainingAttachmentAmount();
399 detachAmount_ = basket_->remainingDetachmentAmount();
400 copula_->resetBasket(basket_.currentLink());
401}

◆ expectedTrancheLoss1()

QuantLib::Real expectedTrancheLoss1 ( const QuantLib::Date &  d,
Distribution &  dist 
) const
private

Definition at line 190 of file poollossmodel.hpp.

190 {
191
192 // RL: dist.trancheExpectedValue() using x = dist.average(i)
193 // FIXME: some remaining inaccuracy in dist.cumulativeDensity(detachAmount_)
194 QuantLib::Real expectedLoss = 0;
195 for (QuantLib::Size i = 0; i < dist.size(); i++) {
196 // Real x = dist.x(i) + dist.dx(i)/2; // in QL distribution.cpp
197 QuantLib::Real x = dist.average(i);
198 if (x < attachAmount_)
199 continue;
200 if (x > detachAmount_)
201 break;
202 expectedLoss += (x - attachAmount_) * dist.dx(i) * dist.density(i);
203 }
204 expectedLoss += (detachAmount_ - attachAmount_) * (1.0 - dist.cumulativeDensity(detachAmount_));
205
206 return expectedLoss;
207}

◆ expectedTrancheLoss2()

QuantLib::Real expectedTrancheLoss2 ( const QuantLib::Date &  d,
const Array &  p,
const Array &  A 
) const
private

Definition at line 210 of file poollossmodel.hpp.

210 {
211 // QL_REQUIRE(A.back() > detachAmount_, "A grid (max " << A.back() << ") does not cover the tranche with D " << detachAmount_);
212 QuantLib::Real expectedLoss = 0;
213 QuantLib::Real cumulative = 0.0;
214 for (QuantLib::Size i = 0; i < p.size(); i++) {
215 QuantLib::Real x = A[i];
216 if (x < attachAmount_)
217 continue;
218 if (x > detachAmount_)
219 break;
220 expectedLoss += (x - attachAmount_) * p[i];
221 cumulative += p[i];
222 }
223 expectedLoss += (detachAmount_ - attachAmount_) * (1.0 - cumulative);
224
225 return expectedLoss;
226}

Member Data Documentation

◆ homogeneous_

bool homogeneous_
private

Definition at line 62 of file poollossmodel.hpp.

◆ copula_

QuantLib::ext::shared_ptr<ExtendedConstantLossLatentModel<CopulaPolicy> > copula_
private

Definition at line 63 of file poollossmodel.hpp.

◆ nBuckets_

QuantLib::Size nBuckets_
private

Definition at line 64 of file poollossmodel.hpp.

◆ max_

QuantLib::Real max_
private

Definition at line 65 of file poollossmodel.hpp.

◆ min_

QuantLib::Real min_
private

Definition at line 66 of file poollossmodel.hpp.

◆ nSteps_

QuantLib::Size nSteps_
private

Definition at line 67 of file poollossmodel.hpp.

◆ useQuadrature_

bool useQuadrature_
private

Definition at line 68 of file poollossmodel.hpp.

◆ useStochasticRecovery_

bool useStochasticRecovery_
private

Definition at line 69 of file poollossmodel.hpp.

◆ delta_

QuantLib::Real delta_
private

Definition at line 71 of file poollossmodel.hpp.

◆ attach_

QuantLib::Real attach_
mutableprivate

Definition at line 72 of file poollossmodel.hpp.

◆ detach_

QuantLib::Real detach_
mutableprivate

Definition at line 73 of file poollossmodel.hpp.

◆ notional_

QuantLib::Real notional_
mutableprivate

Definition at line 74 of file poollossmodel.hpp.

◆ attachAmount_

QuantLib::Real attachAmount_
mutableprivate

Definition at line 75 of file poollossmodel.hpp.

◆ detachAmount_

QuantLib::Real detachAmount_
mutableprivate

Definition at line 76 of file poollossmodel.hpp.

◆ notionals_

std::vector<QuantLib::Real> notionals_
mutableprivate

Definition at line 77 of file poollossmodel.hpp.

◆ lgd_

std::vector<QuantLib::Real> lgd_
mutableprivate

Definition at line 80 of file poollossmodel.hpp.

◆ q_

std::vector<std::vector<QuantLib::Real> > q_
mutableprivate

Definition at line 82 of file poollossmodel.hpp.

◆ c_

std::vector<std::vector<QuantLib::Real> > c_
mutableprivate

Definition at line 84 of file poollossmodel.hpp.

◆ lgdVV_

std::vector<std::vector<QuantLib::Real> > lgdVV_
mutableprivate

Definition at line 86 of file poollossmodel.hpp.

◆ cprVV_

std::vector<std::vector<QuantLib::Real> > cprVV_
mutableprivate

Definition at line 88 of file poollossmodel.hpp.