23#ifndef QL_PATCH_SOLARIS
31 CumulativeNormalDistribution();
40 sqrt1minuscorrel_(
std::sqrt(1.-correlQuote->value())),
43 beta_(sqrt(correlQuote->value())),
44 biphi_(-sqrt(correlQuote->value()))
47 for (
const auto& quote : quotes)
53 const std::vector<Real>& recoveries)
58 sqrt1minuscorrel_(
std::sqrt(1.-correlation)),
60 beta_(sqrt(correlation)),
61 biphi_(-sqrt(correlation))
63 for (
Real recoverie : recoveries)
64 rrQuotes_.emplace_back(ext::make_shared<RecoveryRateQuote>(recoverie));
69 const std::vector<Real>& recoveries)
74 sqrt1minuscorrel_(
std::sqrt(1.-correlQuote->value())),
76 beta_(sqrt(correlQuote->value())),
77 biphi_(-sqrt(correlQuote->value()))
80 for (
Real recoverie : recoveries)
81 rrQuotes_.emplace_back(ext::make_shared<RecoveryRateQuote>(recoverie));
90 Real attachLimit,
Real detachLimit)
const
93 if (attachLimit >= detachLimit)
return 0.;
95 if (remainingNot == 0.)
return 0.;
97 const Real one = 1.0 - 1.0e-12;
98 const Real k1 = std::min(one, attachLimit /(1.0 - averageRR)
100 const Real k2 = std::min(one, detachLimit /(1.0 - averageRR)
105 const Real invFlightK1 =
111 return remainingNot * (detachLimit *
phi_(invFlightK2)
112 - attachLimit *
phi_(invFlightK1) + (1.-averageRR) *
113 (
biphi_(ip, -invFlightK2) -
biphi_(ip, -invFlightK1)) );
119 Real remainingLossFraction)
const {
121 QL_REQUIRE(remainingLossFraction >=0.,
"Incorrect loss fraction.");
122 QL_REQUIRE(remainingLossFraction <=1.,
"Incorrect loss fraction.");
124 Real remainingAttachAmount =
basket_->remainingAttachmentAmount();
125 Real remainingDetachAmount =
basket_->remainingDetachmentAmount();
128 const Real remainingBasktNot =
basket_->remainingNotional(
d);
130 std::min(remainingAttachAmount / remainingBasktNot, 1.);
132 std::min(remainingDetachAmount / remainingBasktNot, 1.);
135 attach + remainingLossFraction * (detach - attach);
138 Real maxAttLossFract = (1.-averageRR);
139 if(portfFract > maxAttLossFract)
return 0.;
151 /(1.-averageRR)))/
beta_;
153 return phi_(invFlightK);
161 Real remainingAttachAmount =
basket_->remainingAttachmentAmount();
162 Real remainingDetachAmount =
basket_->remainingDetachmentAmount();
164 const Real remainingNot =
basket_->remainingNotional(
d);
166 std::min(remainingAttachAmount / remainingNot, 1.);
168 std::min(remainingDetachAmount / remainingNot, 1.);
171 return remainingNot * (detach-attach);
173 Real maxLossLevel = std::max(attach, ptflLossPerc);
178 averageRR, maxLossLevel, detach);
182 /(detach - attach), 0.), 1.));
183 return ( valA + (maxLossLevel - attach) * remainingNot * valB )
192 "Percentile argument out of bounds.");
194 if(perctl==0.)
return 0.;
RelinkableHandle< Basket > basket_
Probability averageProb(const Date &d) const
Real percentilePortfolioLossFraction(const Date &d, Real perctl) const
Real expectedTrancheLossImpl(Real remainingNot, Real prob, Real averageRR, Real attachLimit, Real detachLimit) const
std::vector< Handle< RecoveryRateQuote > > rrQuotes_
BivariateCumulativeNormalDistribution biphi_
Real averageRecovery(const Date &d) const
Real probOverLoss(const Date &d, Real remainingLossFraction) const override
GaussianLHPLossModel(const Handle< Quote > &correlQuote, const std::vector< Handle< RecoveryRateQuote > > "es)
Real expectedShortfall(const Date &d, Probability perctl) const override
Returns the ESF as an absolute amount (rather than a fraction)
static CumulativeNormalDistribution const phi_
Shared handle to an observable.
static Real standard_value(Real x)
Generic multifactor latent variable model.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
purely virtual base class for market observables
market element returning a stored value
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Probability
probability