19#ifndef quantext_inhomogenous_pool_default_model_hpp
20#define quantext_inhomogenous_pool_default_model_hpp
22#include <ql/experimental/credit/lossdistribution.hpp>
58 Real min = -5., Real nSteps = 50)
60 QL_REQUIRE(copula->numFactors() == 1,
"Inhomogeneous model not implemented for multifactor");
65 Distribution
lossDistrib(
const Date& d,
bool zeroRecovery =
false)
const;
73 Real expectedLoss = 0;
75 for (Size i = 0; i < dist.size(); i++) {
77 Real x = dist.average(i);
82 expectedLoss += (x -
attachAmount_) * dist.dx(i) * dist.density(i);
106 const QuantLib::ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy>>
copula_;
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();
136 copula_->resetBasket(basket_.currentLink());
140 LossDistBucketing bucktLDistBuff(nBuckets_, detachAmount_);
142 std::vector<Real> lgd;
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);
155 Distribution dist(nBuckets_, 0.0, detachAmount_);
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);
166 for (Size j = 0; j < nBuckets_; j++) {
167 dist.addDensity(j, d.density(j) * densitydm);
168 dist.addAverage(j, d.average(j) * densitydm);
basket of issuers and related notionals
Default loss distribution convolution for finite non homogeneous pool.
Real expectedTrancheLoss(const Date &d, bool zeroRecovery=false) const
InhomogeneousPoolLossModel(const QuantLib::ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > &copula, Size nBuckets, Real max=5., Real min=-5., Real nSteps=50)
Real expectedShortfall(const Date &d, Probability percentile) const
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.
InhomogeneousPoolLossModel< GaussianCopulaPolicy > IHGaussPoolLossModel
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
InhomogeneousPoolLossModel< TCopulaPolicy > IHStudentPoolLossModel
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)