19#ifndef quantext_gaussian_lhp_lossmodel_hpp
20#define quantext_gaussian_lhp_lossmodel_hpp
22#include <ql/qldefines.hpp>
24#ifndef QL_PATCH_SOLARIS
26#include <ql/experimental/credit/recoveryratequote.hpp>
27#include <ql/math/distributions/bivariatenormaldistribution.hpp>
28#include <ql/quotes/simplequote.hpp>
32#include <ql/functional.hpp>
34#include <ql/experimental/math/latentmodel.hpp>
67 const std::vector<Handle<QuantLib::RecoveryRateQuote>>& quotes);
76 biphi_ = BivariateCumulativeNormalDistribution(-
beta_);
90 Real attachLimit, Real detachLimit)
const;
96 const Real remainingfullNot =
basket_->remainingNotional(d);
97 Real averageRR = recoveryRate != Null<Real>() ? recoveryRate :
averageRecovery(d);
99 Real remainingAttachAmount =
basket_->remainingAttachmentAmount();
100 Real remainingDetachAmount =
basket_->remainingDetachmentAmount();
106 const Real attach = remainingAttachAmount / remainingfullNot;
107 const Real detach = remainingDetachAmount / remainingfullNot;
116 Real
probOverLoss(
const Date& d, Real remainingLossFraction)
const override;
131 Real
expectedRecovery(
const Date& d, Size iName,
const DefaultProbKey& ik)
const override {
132 return rrQuotes_[iName].currentLink()->value();
138 const Real remainingNot =
basket_->remainingNotional(d);
139 Real remainingAttachAmount =
basket_->remainingAttachmentAmount();
140 Real remainingDetachAmount =
basket_->remainingDetachmentAmount();
141 const Real attach = std::min(remainingAttachAmount / remainingNot, 1.);
142 const Real detach = std::min(remainingDetachAmount / remainingNot, 1.);
143 return remainingNot *
149 const std::vector<Probability> probs =
basket_->remainingProbabilities(d);
150 const std::vector<Real> remainingNots =
basket_->remainingNotionals(d);
151 return std::inner_product(probs.begin(), probs.end(), remainingNots.begin(), 0.) /
165 const std::vector<Probability> probs =
basket_->remainingProbabilities(d);
166 std::vector<Real> recoveries;
167 for (Size i = 0; i <
basket_->remainingSize(); i++)
168 recoveries.push_back(
rrQuotes_[i]->value());
169 std::vector<Real> notionals =
basket_->remainingNotionals(d);
170 Real denominator = std::inner_product(notionals.begin(), notionals.end(), probs.begin(), 0.);
171 if (denominator == 0.)
174 std::transform(notionals.begin(), notionals.end(), probs.begin(), notionals.begin(), std::multiplies<Real>());
176 return std::inner_product(recoveries.begin(), recoveries.end(), notionals.begin(), 0.) / denominator;
184 std::vector<Handle<QuantLib::RecoveryRateQuote>>
rrQuotes_;
197 BivariateCumulativeNormalDistribution
biphi_;
198 static CumulativeNormalDistribution
const phi_;
basket of issuers and related notionals
virtual QuantLib::Real correlation() const
RelinkableHandle< QuantExt::Basket > basket_
Probability averageProb(const Date &d) const
Real percentilePortfolioLossFraction(const Date &d, Real perctl) const
Real percentile(const Date &d, Real perctl) const override
Value at Risk given a default loss percentile.
Real expectedTrancheLoss(const Date &d, Real recoveryRate=Null< Real >()) const override
std::vector< Handle< QuantLib::RecoveryRateQuote > > rrQuotes_
Real expectedTrancheLossImpl(Real remainingNot, Real prob, Real averageRR, Real attachLimit, Real detachLimit) const
BivariateCumulativeNormalDistribution biphi_
Real averageRecovery(const Date &d) const
Real probOverLoss(const Date &d, Real remainingLossFraction) const override
void resetModel() override
Concrete models do now any updates/inits they need on basket reset.
Real expectedShortfall(const Date &d, Probability perctl) const override
Returns the ESF as an absolute amount (rather than a fraction)
GaussianCopulaPolicy copulaType
Real expectedRecovery(const Date &d, Size iName, const DefaultProbKey &ik) const override
static CumulativeNormalDistribution const phi_
GaussianLHPLossModel(const Handle< Quote > &correlQuote, const std::vector< Handle< QuantLib::RecoveryRateQuote > > "es)