21#ifndef quantlib_inhomogenous_pool_default_model_hpp
22#define quantlib_inhomogenous_pool_default_model_hpp
45 template<
class copulaPolicy>
67 "Inhomogeneous model not implemented for multifactor");
93 const ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> >
copula_;
118 attach_ = std::min(basket_->remainingAttachmentAmount() /
119 basket_->remainingNotional(), 1.);
120 detach_ = std::min(basket_->remainingDetachmentAmount() /
121 basket_->remainingNotional(), 1.);
122 notional_ = basket_->remainingNotional();
123 notionals_ = basket_->remainingNotionals();
124 attachAmount_ = basket_->remainingAttachmentAmount();
125 detachAmount_ = basket_->remainingDetachmentAmount();
127 copula_->resetBasket(basket_.currentLink());
136 std::vector<Real> lgd;
137 std::vector<Real> recoveries = copula_->recoveries();
138 std::transform(recoveries.begin(), recoveries.end(),
139 std::back_inserter(lgd),
140 [](
Real x) ->
Real { return 1.0-x; });
141 std::transform(lgd.begin(), lgd.end(), notionals_.begin(),
142 lgd.begin(), std::multiplies<>());
143 std::vector<Real> prob = basket_->remainingProbabilities(
d);
144 for(
Size iName=0; iName<prob.size(); iName++)
145 prob[iName] = copula_->inverseCumulativeY(prob[iName], iName);
153 std::vector<Real> mkft(1, min_ + delta_ /2.);
154 for (
Size i = 0; i < nSteps_; i++) {
155 std::vector<Real> conditionalProbs;
156 for(
Size iName=0; iName<notionals_.size(); iName++)
157 conditionalProbs.push_back(
158 copula_->conditionalDefaultProbabilityInvP(prob[iName], iName,
160 Distribution bld = bucktLDistBuff(lgd, conditionalProbs);
161 Real densitydm = delta_ * copula_->density(mkft);
164 for (
Size j = 0; j < nBuckets_; j++)
basket of issuers and related notionals
void tranche(Real attachmentPoint, Real detachmentPoint)
Real cumulativeExcessProbability(Real a, Real b)
Real confidenceLevel(Real quantil)
void addDensity(int bucket, Real value)
Real expectedShortfall(Real percValue)
Default loss distribution convolution for finite non homogeneous pool.
Distribution lossDistrib(const Date &d) const
Real percentile(const Date &d, Real percentile) const override
Value at Risk given a default loss percentile.
std::vector< Real > notionals_
const ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > copula_
InhomogeneousPoolLossModel(const ext::shared_ptr< ConstantLossLatentmodel< copulaPolicy > > &copula, Size nBuckets, Real max=5., Real min=-5., Size nSteps=50)
void resetModel() override
Concrete models do now any updates/inits they need on basket reset.
Real expectedShortfall(const Date &d, Probability percentile) const override
Expected shortfall given a default loss percentile.
Real expectedTrancheLoss(const Date &d) const override
Loss distribution with Hull-White bucketing.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Probability
probability
std::size_t Size
size of a container
Loss distributions and probability of n defaults.
InhomogeneousPoolLossModel< GaussianCopulaPolicy > IHGaussPoolLossModel
InhomogeneousPoolLossModel< TCopulaPolicy > IHStudentPoolLossModel