Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Basket Class Reference

#include <qle/models/basket.hpp>

+ Inheritance diagram for Basket:
+ Collaboration diagram for Basket:

Public Member Functions

 Basket ()
 
 Basket (const Date &refDate, const std::vector< std::string > &names, const std::vector< Real > &notionals, const QuantLib::ext::shared_ptr< Pool > pool, Real attachmentRatio=0.0, Real detachmentRatio=1.0, const QuantLib::ext::shared_ptr< Claim > &claim=QuantLib::ext::shared_ptr< Claim >(new FaceValueClaim()))
 
void computeBasket () const
 
Size size () const
 Basket inception number of counterparties. More...
 
const std::vector< std::string > & names () const
 Basket counterparties names at inception. More...
 
const std::vector< Real > & notionals () const
 Basket counterparties notionals at inception. More...
 
Real exposure (const std::string &name, const Date &=Date()) const
 Returns the total expected exposures for that name. More...
 
const QuantLib::ext::shared_ptr< Pool > & pool () const
 Underlying pool. More...
 
std::vector< DefaultProbKey > defaultKeys () const
 The keys each counterparty enters the basket with (sensitive to) More...
 
const Date & refDate () const
 Basket inception date. More...
 
Real attachmentRatio () const
 
Real detachmentRatio () const
 Detachment point expressed as a fraction of the total pool notional. More...
 
Real basketNotional () const
 Original basket notional ignoring any losses. More...
 
Real trancheNotional () const
 Original tranche notional ignoring any realized losses. More...
 
Real attachmentAmount () const
 Attachment amount = attachmentRatio() * basketNotional() More...
 
Real detachmentAmount () const
 Detachment amount = detachmentRatio() * basketNotional() More...
 
QuantLib::ext::shared_ptr< Claim > claim () const
 default claim, same for all positions and counterparties More...
 
std::vector< Probability > probabilities (const Date &d) const
 
Real settledLoss () const
 
Real settledLoss (const Date &) const
 
Real cumulatedLoss () const
 
Real cumulatedLoss (const Date &) const
 
Real remainingNotional () const
 
Real remainingNotional (const Date &) const
 
const std::vector< Real > & remainingNotionals () const
 
std::vector< Real > remainingNotionals (const Date &) const
 
const std::vector< std::string > & remainingNames () const
 
std::vector< std::string > remainingNames (const Date &) const
 
const std::vector< DefaultProbKey > & remainingDefaultKeys () const
 
std::vector< DefaultProbKey > remainingDefaultKeys (const Date &) const
 
Size remainingSize () const
 Number of counterparties alive on the requested date. More...
 
Size remainingSize (const Date &) const
 
std::vector< Probability > remainingProbabilities (const Date &d) const
 
Real remainingAttachmentAmount () const
 
Real remainingAttachmentAmount (const Date &endDate) const
 
Real remainingDetachmentAmount () const
 
Real remainingDetachmentAmount (const Date &endDate) const
 
Real remainingTrancheNotional () const
 Remaining basket tranched notional on calculation date. More...
 
Real remainingTrancheNotional (const Date &endDate) const
 
const std::vector< Size > & liveList () const
 Indexes of remaining names. Notice these are names and not positions. More...
 
std::vector< Size > liveList (const Date &) const
 
void setLossModel (const QuantLib::ext::shared_ptr< QuantExt::DefaultLossModel > &lossModel)
 Assigns the default loss model to this basket. Resets calculations. More...
 

Basket Loss Statistics

Methods providing statistical metrics on the loss or value distribution of the basket. Most calculations rely on the pressence of a model assigned to the basket.

std::vector< Real > notionals_
 
QuantLib::ext::shared_ptr< Pool > pool_
 
const QuantLib::ext::shared_ptr< Claim > claim_
 The claim is the same for all names. More...
 
Real attachmentRatio_
 
Real detachmentRatio_
 
Real basketNotional_
 
Real attachmentAmount_
 basket tranched inception attachment amount: More...
 
Real detachmentAmount_
 basket tranched inception detachment amount: More...
 
Real trancheNotional_
 basket tranched notional amount: More...
 
Real evalDateSettledLoss_
 
Real evalDateRemainingNot_
 
Real evalDateAttachAmount_
 
Real evalDateDetachAmmount_
 
std::vector< Size > evalDateLiveList_
 
std::vector< Real > evalDateLiveNotionals_
 
std::vector< std::string > evalDateLiveNames_
 
std::vector< DefaultProbKey > evalDateLiveKeys_
 
const Date refDate_
 Basket inception date. More...
 
QuantLib::ext::shared_ptr< QuantExt::DefaultLossModellossModel_
 
Real expectedTrancheLoss (const Date &d, Real recoveryRate=Null< Real >()) const
 
Probability probOverLoss (const Date &d, Real lossFraction) const
 
Real percentile (const Date &d, Probability prob) const
 
Real expectedShortfall (const Date &d, Probability prob) const
 
std::vector< Real > splitVaRLevel (const Date &date, Real loss) const
 
std::map< Real, Probability > lossDistribution (const Date &) const
 
Real densityTrancheLoss (const Date &d, Real lossFraction) const
 
Real defaultCorrelation (const Date &d, Size iName, Size jName) const
 
std::vector< Probability > probsBeingNthEvent (Size n, const Date &d) const
 
Probability probAtLeastNEvents (Size n, const Date &d) const
 
Real recoveryRate (const Date &d, Size iName) const
 
QuantLib::Real correlation () const
 
void performCalculations () const override
 

Detailed Description

Credit Basket.

A basket is a collection of credit names, represented by a unique identifier (a text string), associated notional amounts, a pool and tranche information. The pool is a map of "names" to issuers. The Basket structure is motivated by CDO squared instruments containing various underlying inner CDOs which can be represented by respective baskets including their tranche structure. The role of the Pool is providing a unique list of relevant issuers while names may appear multiple times across different baskets (overlap).

Definition at line 52 of file basket.hpp.

Constructor & Destructor Documentation

◆ Basket() [1/2]

Basket ( )

Definition at line 54 of file basket.hpp.

54{}

◆ Basket() [2/2]

Basket ( const Date &  refDate,
const std::vector< std::string > &  names,
const std::vector< Real > &  notionals,
const QuantLib::ext::shared_ptr< Pool >  pool,
Real  attachmentRatio = 0.0,
Real  detachmentRatio = 1.0,
const QuantLib::ext::shared_ptr< Claim > &  claim = QuantLib::ext::shared_ptr<Claim>(new FaceValueClaim()) 
)

Constructs a basket of simple collection of constant notional positions subject to default risk only.

The refDate parameter is the basket inception date, that is, the date at which defaultable events are relevant. (There are no constraints on forward baskets but models assigned should be consistent.)

Definition at line 31 of file basket.cpp.

36 QL_REQUIRE(!notionals_.empty(), "notionals empty");
38 "invalid attachment/detachment ratio");
39 QL_REQUIRE(pool_, "Empty pool pointer.");
40 QL_REQUIRE(notionals_.size() == pool_->size(), "unmatched data entry sizes in basket, "
41 << notionals_.size() << " notionals, " << pool_->size()
42 << " pool size");
43
44 // registrations relevant to the loss status, not to the expected
45 // loss values; those are through models.
46 registerWith(Settings::instance().evaluationDate());
47 registerWith(claim_);
48}
Real detachmentAmount_
basket tranched inception detachment amount:
Definition: basket.hpp:290
const std::vector< Real > & notionals() const
Basket counterparties notionals at inception.
Definition: basket.hpp:321
Real attachmentAmount_
basket tranched inception attachment amount:
Definition: basket.hpp:288
QuantLib::ext::shared_ptr< Pool > pool_
Definition: basket.hpp:280
const QuantLib::ext::shared_ptr< Claim > claim_
The claim is the same for all names.
Definition: basket.hpp:282
Real detachmentRatio_
Definition: basket.hpp:285
const Date refDate_
Basket inception date.
Definition: basket.hpp:304
std::vector< Real > notionals_
Definition: basket.hpp:279
Real trancheNotional_
basket tranched notional amount:
Definition: basket.hpp:292
const QuantLib::ext::shared_ptr< Pool > & pool() const
Underlying pool.
Definition: basket.hpp:325
QuantLib::ext::shared_ptr< Claim > claim() const
default claim, same for all positions and counterparties
Definition: basket.hpp:127
const Date & refDate() const
Basket inception date.
Definition: basket.hpp:99
Real attachmentRatio_
Definition: basket.hpp:284
Real basketNotional_
Definition: basket.hpp:286

Member Function Documentation

◆ computeBasket()

void computeBasket ( ) const

Definition at line 66 of file basket.hpp.

66 {
67 Date today = Settings::instance().evaluationDate();
68 /* update cache values at the calculation date (work as arguments
69 to the Loss Models)
70 \to do: IMPORTANT: notice that defaults added to Issuers dont get
71 notify as the codes stnds today. Issuers need to be observables.
72 */
73 // this one must remain on top since there are dependencies
82 }
Real evalDateAttachAmount_
Definition: basket.hpp:298
Real remainingAttachmentAmount() const
Definition: basket.hpp:337
const std::vector< DefaultProbKey > & remainingDefaultKeys() const
Definition: basket.hpp:362
Real evalDateSettledLoss_
Definition: basket.hpp:298
std::vector< DefaultProbKey > evalDateLiveKeys_
Definition: basket.hpp:302
std::vector< Real > evalDateLiveNotionals_
Definition: basket.hpp:300
std::vector< Size > evalDateLiveList_
Definition: basket.hpp:299
Real evalDateRemainingNot_
Definition: basket.hpp:298
const std::vector< Size > & liveList() const
Indexes of remaining names. Notice these are names and not positions.
Definition: basket.hpp:327
std::vector< std::string > evalDateLiveNames_
Definition: basket.hpp:301
Real remainingDetachmentAmount() const
Definition: basket.hpp:332
const std::vector< std::string > & remainingNames() const
Definition: basket.hpp:342
const std::vector< Real > & remainingNotionals() const
Definition: basket.hpp:347
Real evalDateDetachAmmount_
Definition: basket.hpp:298
Real remainingNotional() const
Definition: basket.cpp:145
Real settledLoss() const
Definition: basket.hpp:357
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

Size size ( ) const

Basket inception number of counterparties.

Definition at line 319 of file basket.hpp.

319{ return pool_->size(); }
+ Here is the caller graph for this function:

◆ names()

const std::vector< std::string > & names ( ) const

Basket counterparties names at inception.

Definition at line 86 of file basket.hpp.

86{ return pool_->names(); }

◆ notionals()

const std::vector< Real > & notionals ( ) const

Basket counterparties notionals at inception.

Definition at line 321 of file basket.hpp.

321{ return notionals_; }

◆ exposure()

Real exposure ( const std::string &  name,
const Date &  d = Date() 
) const

Returns the total expected exposures for that name.

Definition at line 196 of file basket.cpp.

196 {
197 calculate();
198 //'this->names_' contains duplicates, contrary to 'pool->names'
199 std::vector<std::string>::const_iterator match = std::find(pool_->names().begin(), pool_->names().end(), name);
200 QL_REQUIRE(match != pool_->names().end(), "Name not in basket.");
201 Real totalNotional = 0.;
202 do {
203 totalNotional +=
204 // NOT IMPLEMENTED YET:
205 // positions_[std::distance(names_.begin(), match)]->expectedExposure(d);
206 notionals_[std::distance(pool_->names().begin(), match)];
207 ++match;
208 match = std::find(match, pool_->names().end(), name);
209 } while (match != pool_->names().end());
210
211 return totalNotional;
212 // Size position = std::distance(poolNames.begin(),
213 // std::find(poolNames.begin(), poolNames.end(), name));
214 // QL_REQUIRE(position < pool_->size(), "Name not in pool list");
215
216 // return positions_[position]->expectedExposure(d);
217}
+ Here is the caller graph for this function:

◆ pool()

const QuantLib::ext::shared_ptr< Pool > & pool ( ) const

Underlying pool.

Definition at line 325 of file basket.hpp.

325{ return pool_; }

◆ defaultKeys()

std::vector< DefaultProbKey > defaultKeys ( ) const

The keys each counterparty enters the basket with (sensitive to)

Definition at line 323 of file basket.hpp.

323{ return pool_->defaultKeys(); }
+ Here is the caller graph for this function:

◆ refDate()

const Date & refDate ( ) const

Basket inception date.

Loss Given Default for all issuers/notionals based on expected recovery rates for the respective issuers.

Definition at line 99 of file basket.hpp.

99{ return refDate_; }

◆ attachmentRatio()

Real attachmentRatio ( ) const

Attachment point expressed as a fraction of the total inception notional.

Definition at line 103 of file basket.hpp.

103{ return attachmentRatio_; }

◆ detachmentRatio()

Real detachmentRatio ( ) const

Detachment point expressed as a fraction of the total pool notional.

Definition at line 105 of file basket.hpp.

105{ return detachmentRatio_; }

◆ basketNotional()

Real basketNotional ( ) const

Original basket notional ignoring any losses.

Definition at line 107 of file basket.hpp.

107 {
108 calculate();
109 return basketNotional_;
110 }

◆ trancheNotional()

Real trancheNotional ( ) const

Original tranche notional ignoring any realized losses.

Definition at line 112 of file basket.hpp.

112 {
113 calculate();
114 return trancheNotional_;
115 }

◆ attachmentAmount()

Real attachmentAmount ( ) const

Attachment amount = attachmentRatio() * basketNotional()

Definition at line 117 of file basket.hpp.

117 {
118 calculate();
119 return attachmentAmount_;
120 }

◆ detachmentAmount()

Real detachmentAmount ( ) const

Detachment amount = detachmentRatio() * basketNotional()

Definition at line 122 of file basket.hpp.

122 {
123 calculate();
124 return detachmentAmount_;
125 }

◆ claim()

QuantLib::ext::shared_ptr< Claim > claim ( ) const

default claim, same for all positions and counterparties

Definition at line 127 of file basket.hpp.

127{ return claim_; }

◆ probabilities()

vector< Real > probabilities ( const Date &  d) const

Vector of cumulative default probability to date d for all issuers in the basket.

Definition at line 91 of file basket.cpp.

91 {
92 calculate();
93 vector<Real> prob(size());
94 vector<DefaultProbKey> defKeys = defaultKeys();
95 for (Size j = 0; j < size(); j++)
96 prob[j] = pool_->get(pool_->names()[j]).defaultProbability(defKeys[j])->defaultProbability(d);
97 return prob;
98}
std::vector< DefaultProbKey > defaultKeys() const
The keys each counterparty enters the basket with (sensitive to)
Definition: basket.hpp:323
Size size() const
Basket inception number of counterparties.
Definition: basket.hpp:319
+ Here is the call graph for this function:

◆ settledLoss() [1/2]

Real settledLoss ( ) const

Realized basket losses between the reference date and the calculation date, taking the actual recovery rates of loss events into account. Only default events that have settled (have a realized RR) are accounted for. For contingent losses after a default you need to compute the losses through a DefaultLossModel

Optionally one can pass a date in the future and that will collect events stored in the issuers list. This shows the effect of 'programmed' (after today's) events on top of past ones. The intention is to be used in risk analysis (jump to default, etc).

Definition at line 357 of file basket.hpp.

357 {
358 calculate();
360}
+ Here is the caller graph for this function:

◆ settledLoss() [2/2]

Real settledLoss ( const Date &  endDate) const

Definition at line 122 of file basket.cpp.

122 {
123 calculate();
124 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
125
126 Real loss = 0.0;
127 for (Size i = 0; i < size(); i++) {
128 QuantLib::ext::shared_ptr<DefaultEvent> credEvent =
129 pool_->get(pool_->names()[i]).defaultedBetween(refDate_, endDate, pool_->defaultKeys()[i]);
130 if (credEvent) {
131 if (credEvent->hasSettled()) {
132 loss += claim_->amount(credEvent->date(),
133 // notionals_[i],
134 exposure(pool_->names()[i], credEvent->date()),
135 // NOtice I am requesting an exposure in the past...
136 /* also the seniority does not belong to the
137 counterparty anymore but to the position.....*/
138 credEvent->settlement().recoveryRate(pool_->defaultKeys()[i].seniority()));
139 }
140 }
141 }
142 return loss;
143}
Real exposure(const std::string &name, const Date &=Date()) const
Returns the total expected exposures for that name.
Definition: basket.cpp:196
+ Here is the call graph for this function:

◆ cumulatedLoss() [1/2]

Real cumulatedLoss ( ) const

Actual basket losses between the reference date and the calculation date, taking the actual recovery rates of loss events into account. If the event has not settled yet a model driven recovery is used.

Returns the realized losses in this portfolio since the portfolio default reference date. This method relies on an implementation of the loss given default since the events have not necessarily settled.

Definition at line 352 of file basket.hpp.

352 {
353 calculate();
354 return this->evalDateSettledLoss_;
355}
+ Here is the caller graph for this function:

◆ cumulatedLoss() [2/2]

Real cumulatedLoss ( const Date &  endDate) const

Definition at line 100 of file basket.cpp.

100 {
101 calculate();
102 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
103 Real loss = 0.0;
104 for (Size i = 0; i < size(); i++) {
105 QuantLib::ext::shared_ptr<DefaultEvent> credEvent =
106 pool_->get(pool_->names()[i]).defaultedBetween(refDate_, endDate, pool_->defaultKeys()[i]);
107 if (credEvent) {
108 /* \todo If the event has not settled one would need to
109 introduce some model recovery rate (independently of a loss
110 model) This remains to be done.
111 */
112 if (credEvent->hasSettled())
113 loss += claim_->amount(credEvent->date(),
114 // notionals_[i],
115 exposure(pool_->names()[i], credEvent->date()),
116 credEvent->settlement().recoveryRate(pool_->defaultKeys()[i].seniority()));
117 }
118 }
119 return loss;
120}
+ Here is the call graph for this function:

◆ remainingNotional() [1/2]

Real remainingNotional ( ) const

Remaining full basket (untranched) notional after settled losses between the reference date and the given date. The full notional for defaulted names is subracted, recovery ignored.

Definition at line 145 of file basket.cpp.

145 {
146 calculate();
148}
+ Here is the caller graph for this function:

◆ remainingNotional() [2/2]

Real remainingNotional ( const Date &  endDate) const

Definition at line 160 of file basket.cpp.

160 {
161 calculate();
162 Real notional = 0;
163 vector<DefaultProbKey> defKeys = defaultKeys();
164 for (Size i = 0; i < size(); i++) {
165 if (!pool_->get(pool_->names()[i]).defaultedBetween(refDate_, endDate, defKeys[i]))
166 notional += notionals_[i];
167 }
168 return notional;
169}
+ Here is the call graph for this function:

◆ remainingNotionals() [1/2]

const std::vector< Real > & remainingNotionals ( ) const

Vector of surviving notionals after settled losses between the reference date and the given date, recovery ignored.

Definition at line 347 of file basket.hpp.

347 {
348 calculate();
350}
+ Here is the caller graph for this function:

◆ remainingNotionals() [2/2]

vector< Real > remainingNotionals ( const Date &  endDate) const

Definition at line 171 of file basket.cpp.

171 {
172 calculate();
173 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
174
175 std::vector<Real> calcBufferNotionals;
176 const std::vector<Size>& alive = liveList(endDate);
177 for (Size i = 0; i < alive.size(); i++)
178 calcBufferNotionals.push_back(exposure(pool_->names()[i], endDate)); // some better way to trim it?
179 return calcBufferNotionals;
180}
+ Here is the call graph for this function:

◆ remainingNames() [1/2]

const std::vector< std::string > & remainingNames ( ) const

Vector of surviving issuers after defaults between the reference basket date and the given (or evaluation) date.

Definition at line 342 of file basket.hpp.

342 {
343 calculate();
344 return evalDateLiveNames_;
345}
+ Here is the caller graph for this function:

◆ remainingNames() [2/2]

std::vector< std::string > remainingNames ( const Date &  endDate) const

Definition at line 219 of file basket.cpp.

219 {
220 calculate();
221 // maybe return zero directly instead?:
222 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
223
224 const std::vector<Size>& alive = liveList(endDate);
225 std::vector<std::string> calcBufferNames;
226 for (Size i = 0; i < alive.size(); i++)
227 calcBufferNames.push_back(pool_->names()[alive[i]]);
228 return calcBufferNames;
229}
+ Here is the call graph for this function:

◆ remainingDefaultKeys() [1/2]

const std::vector< DefaultProbKey > & remainingDefaultKeys ( ) const

Default keys of non defaulted counterparties

Definition at line 362 of file basket.hpp.

362 {
363 calculate();
364 return evalDateLiveKeys_;
365}
+ Here is the caller graph for this function:

◆ remainingDefaultKeys() [2/2]

vector< DefaultProbKey > remainingDefaultKeys ( const Date &  endDate) const

Definition at line 231 of file basket.cpp.

231 {
232 calculate();
233 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
234
235 const std::vector<Size>& alive = liveList(endDate);
236 vector<DefaultProbKey> defKeys;
237 for (Size i = 0; i < alive.size(); i++)
238 defKeys.push_back(pool_->defaultKeys()[alive[i]]);
239 return defKeys;
240}
+ Here is the call graph for this function:

◆ remainingSize() [1/2]

Size remainingSize ( ) const

Number of counterparties alive on the requested date.

Definition at line 242 of file basket.cpp.

242 {
243 calculate();
244 return evalDateLiveList_.size();
245}

◆ remainingSize() [2/2]

Size remainingSize ( const Date &  ) const

◆ remainingProbabilities()

std::vector< Probability > remainingProbabilities ( const Date &  d) const

Vector of cumulative default probability to date d for all issuers still (at the evaluation date) alive in the basket.

Definition at line 182 of file basket.cpp.

182 {
183 calculate();
184 QL_REQUIRE(d >= refDate_, "Target date lies before basket inception");
185 vector<Real> prob;
186 const std::vector<Size>& alive = liveList();
187
188 for (Size i = 0; i < alive.size(); i++)
189 prob.push_back(
190 pool_->get(pool_->names()[i]).defaultProbability(pool_->defaultKeys()[i])->defaultProbability(d, true));
191 return prob;
192}
+ Here is the call graph for this function:

◆ remainingAttachmentAmount() [1/2]

Real remainingAttachmentAmount ( ) const

Attachment amount of the equivalent (after defaults) remaining basket The remaining attachment amount is RAA = max (0, attachmentAmount - cumulatedLoss())

The remaining attachment ratio is then RAR = RAA / remainingNotional()

Definition at line 337 of file basket.hpp.

337 {
338 calculate();
340}
+ Here is the caller graph for this function:

◆ remainingAttachmentAmount() [2/2]

Real remainingAttachmentAmount ( const Date &  endDate) const

Definition at line 255 of file basket.cpp.

255 {
256 calculate();
257 // maybe return zero directly instead?:
258 QL_REQUIRE(endDate >= refDate_, "Target date lies before basket inception");
259 Real loss = settledLoss(endDate);
260 return std::min(detachmentAmount_, attachmentAmount_ + std::max(0.0, loss - attachmentAmount_));
261}
+ Here is the call graph for this function:

◆ remainingDetachmentAmount() [1/2]

Real remainingDetachmentAmount ( ) const

Detachment amount of the equivalent remaining basket. The remaining detachment amount is RDA = max (0, detachmentAmount - cumulatedLoss())

The remaining detachment ratio is then RDR = RDA / remainingNotional()

Definition at line 332 of file basket.hpp.

332 {
333 calculate();
335}
+ Here is the caller graph for this function:

◆ remainingDetachmentAmount() [2/2]

Real remainingDetachmentAmount ( const Date &  endDate) const

Definition at line 250 of file basket.cpp.

250 {
251 calculate();
252 return detachmentAmount_;
253}

◆ remainingTrancheNotional() [1/2]

Real remainingTrancheNotional ( ) const

Remaining basket tranched notional on calculation date.

Definition at line 207 of file basket.hpp.

207 {
208 calculate();
210 }

◆ remainingTrancheNotional() [2/2]

Real remainingTrancheNotional ( const Date &  endDate) const

Expected basket tranched notional on the requested date according to the basket model. Model should have been assigned.

Definition at line 214 of file basket.hpp.

214 {
215 calculate();
216 return remainingDetachmentAmount(endDate) - remainingAttachmentAmount(endDate);
217 }
+ Here is the call graph for this function:

◆ liveList() [1/2]

const std::vector< Size > & liveList ( ) const

Indexes of remaining names. Notice these are names and not positions.

Definition at line 327 of file basket.hpp.

327 {
328 calculate();
329 return evalDateLiveList_;
330}
+ Here is the caller graph for this function:

◆ liveList() [2/2]

std::vector< Size > liveList ( const Date &  endDate) const

Definition at line 150 of file basket.cpp.

150 {
151 calculate();
152 std::vector<Size> calcBufferLiveList;
153 for (Size i = 0; i < size(); i++)
154 if (!pool_->get(pool_->names()[i]).defaultedBetween(refDate_, endDate, pool_->defaultKeys()[i]))
155 calcBufferLiveList.push_back(i);
156
157 return calcBufferLiveList;
158}
+ Here is the call graph for this function:

◆ setLossModel()

void setLossModel ( const QuantLib::ext::shared_ptr< QuantExt::DefaultLossModel > &  lossModel)

Assigns the default loss model to this basket. Resets calculations.

Definition at line 53 of file basket.cpp.

53 {
54
55 if (lossModel_)
56 unregisterWith(lossModel_);
57 lossModel_ = lossModel;
58 if (lossModel_) {
59 // recovery quotes, defaults(once Issuer is observable)etc might
60 // trigger us:
61 registerWith(lossModel_);
62 }
63 LazyObject::update(); //<- just set calc=false
64}
QuantLib::ext::shared_ptr< QuantExt::DefaultLossModel > lossModel_
Definition: basket.hpp:314

◆ expectedTrancheLoss()

Real expectedTrancheLoss ( const Date &  d,
Real  recoveryRate = Null<Real>() 
) const

Definition at line 293 of file basket.cpp.

293 {
294 calculate();
295 return cumulatedLoss() + lossModel_->expectedTrancheLoss(d, recoveryRate);
296}
Real recoveryRate(const Date &d, Size iName) const
Definition: basket.cpp:335
Real cumulatedLoss() const
Definition: basket.hpp:352
+ Here is the call graph for this function:

◆ probOverLoss()

Probability probOverLoss ( const Date &  d,
Real  lossFraction 
) const

The lossFraction is the fraction of losses expressed in inception (no losses) tranche units (e.g. 'attach level'=0%, 'detach level'=100%)

Definition at line 263 of file basket.cpp.

263 {
264 // convert initial basket fraction to remaining basket fraction
265 calculate();
266 // if eaten up all the tranche the prob of losing any amount is 1
267 // (we have already lost it)
268 if (evalDateRemainingNot_ == 0.)
269 return 1.;
270
271 // Turn to live (remaining) tranche units to feed into the model request
272 Real xPtfl = attachmentAmount_ + (detachmentAmount_ - attachmentAmount_) * lossFraction;
274 // in live tranche fractional units
275 // if the level falls within realized losses the prob is 1.
276 if (xPtfl < 0.)
277 return 1.;
278
279 return lossModel_->probOverLoss(d, xPrim);
280}

◆ percentile()

Real percentile ( const Date &  d,
Probability  prob 
) const

Definition at line 282 of file basket.cpp.

282 {
283 calculate();
284 return lossModel_->percentile(d, prob);
285
286 // Real percLiveFract = lossModel_->percentile(d, prob);
287 // return (percLiveFract * (detachmentAmount_ - evalDateAttachAmount_) + attachmentAmount_ - evalDateAttachAmount_)
288 // /
289 // (detachmentAmount_ - attachmentAmount_);
290}

◆ expectedShortfall()

Real expectedShortfall ( const Date &  d,
Probability  prob 
) const

ESF

Definition at line 303 of file basket.cpp.

303 {
304 calculate();
305 return lossModel_->expectedShortfall(d, prob);
306}

◆ splitVaRLevel()

std::vector< Real > splitVaRLevel ( const Date &  date,
Real  loss 
) const

Definition at line 298 of file basket.cpp.

298 {
299 calculate();
300 return lossModel_->splitVaRLevel(date, loss);
301}

◆ lossDistribution()

std::map< Real, Probability > lossDistribution ( const Date &  d) const

Full loss distribution

Definition at line 308 of file basket.cpp.

308 {
309 calculate();
310 return lossModel_->lossDistribution(d);
311}

◆ densityTrancheLoss()

Real densityTrancheLoss ( const Date &  d,
Real  lossFraction 
) const

◆ defaultCorrelation()

Real defaultCorrelation ( const Date &  d,
Size  iName,
Size  jName 
) const

Definition at line 322 of file basket.cpp.

322 {
323 calculate();
324 return lossModel_->defaultCorrelation(d, iName, jName);
325}

◆ probsBeingNthEvent()

std::vector< Probability > probsBeingNthEvent ( Size  n,
const Date &  d 
) const

Probability vector that each of the remaining live names (at eval date) is the n-th default by date d.

The n parameter is the internal index to the name; it should be alive at the evaluation date.

------—TO DO: Implement with a string passed-------------------— ------—TO DO: Perform check the name is alive------------------—

Definition at line 313 of file basket.cpp.

313 {
314 Size alreadyDefaulted = pool_->size() - remainingNames().size();
315 if (alreadyDefaulted >= n)
316 return std::vector<Probability>(remainingNames().size(), 0.);
317
318 calculate();
319 return lossModel_->probsBeingNthEvent(n - alreadyDefaulted, d);
320}
+ Here is the call graph for this function:

◆ probAtLeastNEvents()

Probability probAtLeastNEvents ( Size  n,
const Date &  d 
) const

Returns the probaility of having a given or larger number of defaults in the basket portfolio at a given time.

Definition at line 330 of file basket.cpp.

330 {
331 calculate();
332 return lossModel_->probAtLeastNEvents(n, d);
333}

◆ recoveryRate()

Real recoveryRate ( const Date &  d,
Size  iName 
) const

Expected recovery rate of the underlying position as a fraction of its exposure value at date d given it has defaulted on that date. NOTICE THE ARG IS THE CTPTY....SHOULDNT IT BE THE POSITION/INSTRUMENT?????<<<<<<<<<<<<<<<<<<<<<<<

Definition at line 335 of file basket.cpp.

335 {
336 calculate();
337 return lossModel_->expectedRecovery(d, iName, pool_->defaultKeys()[iName]);
338}
+ Here is the caller graph for this function:

◆ correlation()

Real correlation ( ) const

Return single correlation number from the underlying loss model if it is a one factor model. If the underlying loss model is null, this returns a Null<Real>().

Definition at line 340 of file basket.cpp.

340 {
341 calculate();
342 if (lossModel_)
343 return lossModel_->correlation();
344 else
345 return Null<Real>();
346}

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 66 of file basket.cpp.

66 {
68 for (Size i = 0; i < notionals_.size(); i++) {
72 }
74 // Calculations for status
75 computeBasket(); // or we might be called from an statistic member
76 // without being intialized yet (first called)
77 QL_REQUIRE(lossModel_, "Basket has no default loss model assigned.");
78
79 /* The model must notify us if the another basket calls it for
80 reasignment. The basket works as an argument to the deafult loss models
81 so, even if the models dont cache anything, they will be using the wrong
82 defautl TS. \todo: This has a possible optimization: the basket
83 incorporates trancheability and many models do their compuations
84 independently of that (some do but do it inefficiently when asked for
85 two tranches on the same basket; e,g, recursive model) so it might be
86 more efficient sending the pool only; however the modtionals and other
87 basket info are still used.*/
88 lossModel_->setBasket(const_cast<Basket*>(this));
89}
void computeBasket() const
Definition: basket.hpp:66
+ Here is the call graph for this function:

Member Data Documentation

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 279 of file basket.hpp.

◆ pool_

QuantLib::ext::shared_ptr<Pool> pool_
private

Definition at line 280 of file basket.hpp.

◆ claim_

const QuantLib::ext::shared_ptr<Claim> claim_
private

The claim is the same for all names.

Definition at line 282 of file basket.hpp.

◆ attachmentRatio_

Real attachmentRatio_
private

Definition at line 284 of file basket.hpp.

◆ detachmentRatio_

Real detachmentRatio_
private

Definition at line 285 of file basket.hpp.

◆ basketNotional_

Real basketNotional_
mutableprivate

Definition at line 286 of file basket.hpp.

◆ attachmentAmount_

Real attachmentAmount_
mutableprivate

basket tranched inception attachment amount:

Definition at line 288 of file basket.hpp.

◆ detachmentAmount_

Real detachmentAmount_
mutableprivate

basket tranched inception detachment amount:

Definition at line 290 of file basket.hpp.

◆ trancheNotional_

Real trancheNotional_
mutableprivate

basket tranched notional amount:

Definition at line 292 of file basket.hpp.

◆ evalDateSettledLoss_

Real evalDateSettledLoss_
mutableprivate

Definition at line 298 of file basket.hpp.

◆ evalDateRemainingNot_

Real evalDateRemainingNot_
private

Definition at line 298 of file basket.hpp.

◆ evalDateAttachAmount_

Real evalDateAttachAmount_
private

Definition at line 298 of file basket.hpp.

◆ evalDateDetachAmmount_

Real evalDateDetachAmmount_
private

Definition at line 298 of file basket.hpp.

◆ evalDateLiveList_

std::vector<Size> evalDateLiveList_
mutableprivate

Definition at line 299 of file basket.hpp.

◆ evalDateLiveNotionals_

std::vector<Real> evalDateLiveNotionals_
mutableprivate

Definition at line 300 of file basket.hpp.

◆ evalDateLiveNames_

std::vector<std::string> evalDateLiveNames_
mutableprivate

Definition at line 301 of file basket.hpp.

◆ evalDateLiveKeys_

std::vector<DefaultProbKey> evalDateLiveKeys_
mutableprivate

Definition at line 302 of file basket.hpp.

◆ refDate_

const Date refDate_
private

Basket inception date.

Definition at line 304 of file basket.hpp.

◆ lossModel_

QuantLib::ext::shared_ptr<QuantExt::DefaultLossModel> lossModel_
private

Definition at line 314 of file basket.hpp.