19#ifndef quantext_homogenous_pool_default_model_hpp
20#define quantext_homogenous_pool_default_model_hpp
22#include <ql/experimental/credit/lossdistribution.hpp>
50 Real max = 5., Real min = -5., Real nSteps = 50)
52 QL_REQUIRE(copula->numFactors() == 1,
"Inhomogeneous model not implemented for multifactor");
57 Distribution
lossDistrib(
const Date& d,
bool zeroRecovery =
false)
const;
65 Real expectedLoss = 0;
67 for (Size i = 0; i < dist.size(); i++) {
69 Real x = dist.average(i);
74 expectedLoss += (x -
attachAmount_) * dist.dx(i) * dist.density(i);
98 const QuantLib::ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy>>
copula_;
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();
128 copula_->resetBasket(basket_.currentLink());
133 LossDistHomogeneous bucktLDistBuff(nBuckets_, detachAmount_);
135 std::vector<Real> lgd;
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);
148 Distribution dist(nBuckets_, 0.0, detachAmount_);
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);
159 for (Size j = 0; j < nBuckets_; j++) {
160 dist.addDensity(j, d.density(j) * densitydm);
161 dist.addAverage(j, d.average(j) * densitydm);
basket of issuers and related notionals
Default loss distribution convolution for finite homogeneous pool.
Real expectedTrancheLoss(const Date &d, bool zeroRecovery=false) const
Real expectedShortfall(const Date &d, Probability percentile) const
HomogeneousPoolLossModel(const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > &copula, Size nBuckets, Real max=5., Real min=-5., Real nSteps=50)
std::vector< Real > notionals_
const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > copula_
Distribution lossDistrib(const Date &d, bool zeroRecovery=false) const
void resetModel()
Concrete models do now any updates/inits they need on basket reset.
Real percentile(const Date &d, Real percentile) const
Value at Risk given a default loss percentile.
HomogeneousPoolLossModel< TCopulaPolicy > HomogTPoolLossModel
HomogeneousPoolLossModel< GaussianCopulaPolicy > HomogGaussPoolLossModel
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)