34 const vector<string>& names,
35 vector<Real> notionals,
36 ext::shared_ptr<Pool> pool,
39 ext::shared_ptr<Claim> claim)
40 : notionals_(
std::move(notionals)), pool_(
std::move(pool)), claim_(
std::move(claim)),
41 attachmentRatio_(attachment), detachmentRatio_(detachment), basketNotional_(0.0),
42 attachmentAmount_(0.0), detachmentAmount_(0.0), trancheNotional_(0.0), refDate_(refDate) {
47 "invalid attachment/detachment ratio");
50 "unmatched data entry sizes in basket");
75 const ext::shared_ptr<DefaultLossModel>& lossModel) {
111 vector<Real> prob(
size());
114 prob[j] =
pool_->get(
pool_->names()[j]).defaultProbability(
115 defKeys[j])->defaultProbability(
d);
121 "Target date lies before basket inception");
124 ext::shared_ptr<DefaultEvent> credEvent =
126 endDate,
pool_->defaultKeys()[i]);
127 if (credEvent !=
nullptr) {
132 if(credEvent->hasSettled())
133 loss +=
claim_->amount(credEvent->date(),
136 credEvent->settlement().recoveryRate(
137 pool_->defaultKeys()[i].seniority()));
145 "Target date lies before basket inception");
149 ext::shared_ptr<DefaultEvent> credEvent =
151 endDate,
pool_->defaultKeys()[i]);
152 if (credEvent !=
nullptr) {
153 if(credEvent->hasSettled()) {
154 loss +=
claim_->amount(credEvent->date(),
160 credEvent->settlement().recoveryRate(
161 pool_->defaultKeys()[i].seniority()));
173 std::vector<Size> calcBufferLiveList;
175 if (!
pool_->get(
pool_->names()[i]).defaultedBetween(
178 pool_->defaultKeys()[i]))
179 calcBufferLiveList.push_back(i);
181 return calcBufferLiveList;
199 "Target date lies before basket inception");
201 std::vector<Real> calcBufferNotionals;
202 const std::vector<Size>& alive =
liveList(endDate);
203 for(
Size i=0; i<alive.size(); i++)
204 calcBufferNotionals.push_back(
207 return calcBufferNotionals;
214 const std::vector<Size>& alive =
liveList();
216 for(
Size i=0; i<alive.size(); i++)
217 prob.push_back(
pool_->get(
pool_->names()[i]).defaultProbability(
218 pool_->defaultKeys()[i])->defaultProbability(
d,
true));
226 auto match = std::find(
pool_->names().begin(),
pool_->names().end(), name);
228 Real totalNotional = 0.;
235 match = std::find(match,
pool_->names().end(), name);
236 }
while(match !=
pool_->names().end());
238 return totalNotional;
250 "Target date lies before basket inception");
252 const std::vector<Size>& alive =
liveList(endDate);
253 std::vector<std::string> calcBufferNames;
254 calcBufferNames.reserve(alive.size());
255 for (
unsigned long i : alive)
256 calcBufferNames.push_back(
pool_->names()[i]);
257 return calcBufferNames;
263 "Target date lies before basket inception");
265 const std::vector<Size>& alive =
liveList(endDate);
266 vector<DefaultProbKey> defKeys;
267 defKeys.reserve(alive.size());
268 for (
unsigned long i : alive)
269 defKeys.push_back(
pool_->defaultKeys()[i]);
286 "Target date lies before basket inception");
293 "Target date lies before basket inception");
313 if(xPtfl < 0.)
return 1.;
343 std::vector<Probability>
347 if(alreadyDefaulted >=
n)
351 return lossModel_->probsBeingNthEvent(
n-alreadyDefaulted,
d);
356 return lossModel_->defaultCorrelation(
d, iName, jName);
basket of issuers and related notionals
std::vector< Probability > probabilities(const Date &d) const
Real recoveryRate(const Date &d, Size iName) const
Real evalDateAttachAmount_
void performCalculations() const override
const ext::shared_ptr< Claim > claim_
The claim is the same for all names.
Real defaultCorrelation(const Date &d, Size iName, Size jName) const
Real detachmentAmount_
basket tranched inception detachment amount:
Real remainingAttachmentAmount() const
const std::vector< DefaultProbKey > & remainingDefaultKeys() const
ext::shared_ptr< Pool > pool_
std::vector< Size > evalDateLiveList_
Real attachmentAmount_
basket tranched inception attachment amount:
std::vector< DefaultProbKey > defaultKeys() const
The keys each counterparty enters the basket with (sensitive to)
void computeBasket() const
const Date refDate_
Basket inception date.
Probability probOverLoss(const Date &d, Real lossFraction) const
std::vector< Real > notionals_
Size remainingSize() const
Number of counterparties alive on the requested date.
Real exposure(const std::string &name, const Date &=Date()) const
Returns the total expected exposures for that name.
Real trancheNotional_
basket tranched notional amount:
Probability probAtLeastNEvents(Size n, const Date &d) const
Real evalDateRemainingNot_
const std::vector< Size > & liveList() const
Indexes of remaining names. Notice these are names and not positions.
Real percentile(const Date &d, Probability prob) const
ext::shared_ptr< DefaultLossModel > lossModel_
Real expectedTrancheLoss(const Date &d) const
void setLossModel(const ext::shared_ptr< DefaultLossModel > &lossModel)
Assigns the default loss model to this basket. Resets calculations.
Real notional() const
Basket total notional at inception.
std::vector< Probability > probsBeingNthEvent(Size n, const Date &d) const
Real remainingDetachmentAmount() const
Size size() const
Basket inception number of counterparties.
const std::vector< std::string > & remainingNames() const
Real expectedShortfall(const Date &d, Probability prob) const
std::vector< Real > splitVaRLevel(const Date &date, Real loss) const
Real cumulatedLoss() const
const std::vector< Real > & remainingNotionals() const
std::vector< Probability > remainingProbabilities(const Date &d) const
Real remainingNotional() const
std::map< Real, Probability > lossDistribution(const Date &) const
virtual void calculate() const
Size unregisterWith(const ext::shared_ptr< Observable > &)
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
static Settings & instance()
access to the unique instance
#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
Pair of loss time and amount, sortable by loss time.