QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Basket Class Reference

#include <basket.hpp>

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

Public Member Functions

 Basket ()=default
 
 Basket (const Date &refDate, const std::vector< std::string > &names, std::vector< Real > notionals, ext::shared_ptr< Pool > pool, Real attachmentRatio=0.0, Real detachmentRatio=1.0, ext::shared_ptr< Claim > claim=ext::shared_ptr< Claim >(new FaceValueClaim()))
 
void update () override
 
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 notional () const
 Basket total notional at inception. More...
 
Real exposure (const std::string &name, const Date &=Date()) const
 Returns the total expected exposures for that name. More...
 
const ext::shared_ptr< Pool > & pool () const
 Underlying pool. More...
 
std::vector< DefaultProbKeydefaultKeys () const
 The keys each counterparty enters the basket with (sensitive to) More...
 
const DaterefDate () 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...
 
ext::shared_ptr< Claimclaim () const
 default claim, same for all positions and counterparties More...
 
std::vector< Probabilityprobabilities (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< RealremainingNotionals (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< DefaultProbKeyremainingDefaultKeys (const Date &) const
 
Size remainingSize () const
 Number of counterparties alive on the requested date. More...
 
Size remainingSize (const Date &) const
 
std::vector< ProbabilityremainingProbabilities (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< SizeliveList (const Date &) const
 
void setLossModel (const ext::shared_ptr< DefaultLossModel > &lossModel)
 Assigns the default loss model to this basket. Resets calculations. More...
 
- Public Member Functions inherited from LazyObject
 LazyObject ()
 
 ~LazyObject () override=default
 
void update () override
 
bool isCalculated () const
 
void forwardFirstNotificationOnly ()
 
void alwaysForwardNotifications ()
 
void recalculate ()
 
void freeze ()
 
void unfreeze ()
 
- Public Member Functions inherited from Observable
 Observable ()
 
 Observable (const Observable &)
 
Observableoperator= (const Observable &)
 
 Observable (Observable &&)=delete
 
Observableoperator= (Observable &&)=delete
 
virtual ~Observable ()=default
 
void notifyObservers ()
 
- Public Member Functions inherited from Observer
 Observer ()=default
 
 Observer (const Observer &)
 
Observeroperator= (const Observer &)
 
virtual ~Observer ()
 
std::pair< iterator, boolregisterWith (const ext::shared_ptr< Observable > &)
 
void registerWithObservables (const ext::shared_ptr< Observer > &)
 
Size unregisterWith (const ext::shared_ptr< Observable > &)
 
void unregisterWithAll ()
 
virtual void update ()=0
 
virtual void deepUpdate ()
 

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< Realnotionals_
 
ext::shared_ptr< Poolpool_
 
const ext::shared_ptr< Claimclaim_
 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< SizeevalDateLiveList_
 
std::vector< RealevalDateLiveNotionals_
 
std::vector< std::string > evalDateLiveNames_
 
std::vector< DefaultProbKeyevalDateLiveKeys_
 
const Date refDate_
 Basket inception date. More...
 
ext::shared_ptr< DefaultLossModellossModel_
 
Real expectedTrancheLoss (const Date &d) 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< RealsplitVaRLevel (const Date &date, Real loss) const
 
std::map< Real, ProbabilitylossDistribution (const Date &) const
 
Real densityTrancheLoss (const Date &d, Real lossFraction) const
 
Real defaultCorrelation (const Date &d, Size iName, Size jName) const
 
std::vector< ProbabilityprobsBeingNthEvent (Size n, const Date &d) const
 
Probability probAtLeastNEvents (Size n, const Date &d) const
 
Real recoveryRate (const Date &d, Size iName) const
 
void performCalculations () const override
 

Additional Inherited Members

- Public Types inherited from Observer
typedef set_type::iterator iterator
 
- Protected Member Functions inherited from LazyObject
virtual void calculate () const
 
- Protected Attributes inherited from LazyObject
bool calculated_ = false
 
bool frozen_ = false
 
bool alwaysForward_
 

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 ( )
default

◆ Basket() [2/2]

Basket ( const Date refDate,
const std::vector< std::string > &  names,
std::vector< Real notionals,
ext::shared_ptr< Pool pool,
Real  attachmentRatio = 0.0,
Real  detachmentRatio = 1.0,
ext::shared_ptr< Claim claim = 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 33 of file basket.cpp.

+ Here is the call graph for this function:

Member Function Documentation

◆ update()

void update ( )
overridevirtual

This method must be implemented in derived classes. An instance of Observer does not call this method directly: instead, it will be called by the observables the instance registered with when they need to notify any changes.

Implements Observer.

Definition at line 70 of file basket.hpp.

+ Here is the call graph for this function:

◆ computeBasket()

void computeBasket ( ) const

Definition at line 74 of file basket.hpp.

+ 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 317 of file basket.hpp.

+ Here is the caller graph for this function:

◆ names()

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

Basket counterparties names at inception.

Definition at line 95 of file basket.hpp.

◆ notionals()

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

Basket counterparties notionals at inception.

Definition at line 321 of file basket.hpp.

◆ notional()

Real notional ( ) const

Basket total notional at inception.

Definition at line 106 of file basket.cpp.

+ Here is the caller graph for this function:

◆ exposure()

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

Returns the total expected exposures for that name.

Definition at line 224 of file basket.cpp.

+ Here is the caller graph for this function:

◆ pool()

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

Underlying pool.

Definition at line 329 of file basket.hpp.

◆ defaultKeys()

std::vector< DefaultProbKey > defaultKeys ( ) const

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

Definition at line 325 of file basket.hpp.

+ 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 110 of file basket.hpp.

◆ attachmentRatio()

Real attachmentRatio ( ) const

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

Definition at line 114 of file basket.hpp.

◆ detachmentRatio()

Real detachmentRatio ( ) const

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

Definition at line 116 of file basket.hpp.

◆ basketNotional()

Real basketNotional ( ) const

Original basket notional ignoring any losses.

Definition at line 118 of file basket.hpp.

◆ trancheNotional()

Real trancheNotional ( ) const

Original tranche notional ignoring any realized losses.

Definition at line 120 of file basket.hpp.

◆ attachmentAmount()

Real attachmentAmount ( ) const

Attachment amount = attachmentRatio() * basketNotional()

Definition at line 122 of file basket.hpp.

◆ detachmentAmount()

Real detachmentAmount ( ) const

Detachment amount = detachmentRatio() * basketNotional()

Definition at line 124 of file basket.hpp.

◆ claim()

ext::shared_ptr< Claim > claim ( ) const

default claim, same for all positions and counterparties

Definition at line 126 of file basket.hpp.

◆ 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 110 of file basket.cpp.

+ 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.

+ Here is the caller graph for this function:

◆ settledLoss() [2/2]

Real settledLoss ( const Date endDate) const

Definition at line 143 of file basket.cpp.

+ 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 353 of file basket.hpp.

+ Here is the caller graph for this function:

◆ cumulatedLoss() [2/2]

Real cumulatedLoss ( const Date endDate) const

Definition at line 119 of file basket.cpp.

+ 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 168 of file basket.cpp.

+ Here is the caller graph for this function:

◆ remainingNotional() [2/2]

Real remainingNotional ( const Date endDate) const

Definition at line 184 of file basket.cpp.

+ 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 349 of file basket.hpp.

+ Here is the caller graph for this function:

◆ remainingNotionals() [2/2]

vector< Real > remainingNotionals ( const Date endDate) const

Definition at line 196 of file basket.cpp.

+ 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 345 of file basket.hpp.

+ Here is the caller graph for this function:

◆ remainingNames() [2/2]

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

Definition at line 246 of file basket.cpp.

+ 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.

+ Here is the caller graph for this function:

◆ remainingDefaultKeys() [2/2]

vector< DefaultProbKey > remainingDefaultKeys ( const Date endDate) const

Definition at line 260 of file basket.cpp.

+ 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 273 of file basket.cpp.

◆ remainingSize() [2/2]

Size remainingSize ( const Date d) const

Definition at line 277 of file basket.cpp.

+ Here is the call graph for this function:

◆ 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 210 of file basket.cpp.

+ 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 341 of file basket.hpp.

+ Here is the caller graph for this function:

◆ remainingAttachmentAmount() [2/2]

Real remainingAttachmentAmount ( const Date endDate) const

Definition at line 290 of file basket.cpp.

+ 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 337 of file basket.hpp.

+ Here is the caller graph for this function:

◆ remainingDetachmentAmount() [2/2]

Real remainingDetachmentAmount ( const Date endDate) const

Definition at line 284 of file basket.cpp.

◆ remainingTrancheNotional() [1/2]

Real remainingTrancheNotional ( ) const

Remaining basket tranched notional on calculation date.

Definition at line 206 of file basket.hpp.

+ Here is the call graph for this function:

◆ 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 213 of file basket.hpp.

+ 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 333 of file basket.hpp.

+ Here is the caller graph for this function:

◆ liveList() [2/2]

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

Definition at line 172 of file basket.cpp.

+ Here is the call graph for this function:

◆ setLossModel()

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

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

Definition at line 74 of file basket.cpp.

+ Here is the call graph for this function:

◆ expectedTrancheLoss()

Real expectedTrancheLoss ( const Date d) const

Definition at line 323 of file basket.cpp.

+ 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 299 of file basket.cpp.

+ Here is the call graph for this function:

◆ percentile()

Real percentile ( const Date d,
Probability  prob 
) const

Definition at line 318 of file basket.cpp.

+ Here is the call graph for this function:

◆ expectedShortfall()

Real expectedShortfall ( const Date d,
Probability  prob 
) const

ESF

Definition at line 333 of file basket.cpp.

+ Here is the call graph for this function:

◆ splitVaRLevel()

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

Definition at line 328 of file basket.cpp.

+ Here is the call graph for this function:

◆ lossDistribution()

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

Full loss distribution

Definition at line 338 of file basket.cpp.

+ Here is the call graph for this function:

◆ densityTrancheLoss()

Real densityTrancheLoss ( const Date d,
Real  lossFraction 
) const

◆ defaultCorrelation()

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

Definition at line 354 of file basket.cpp.

+ Here is the call graph for this function:

◆ 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 344 of file basket.cpp.

+ 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 363 of file basket.cpp.

+ Here is the call graph for this function:

◆ 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 369 of file basket.cpp.

+ Here is the call graph for this function:

◆ performCalculations()

void performCalculations ( ) const
overrideprivatevirtual

This method must implement any calculations which must be (re)done in order to calculate the desired results.

Implements LazyObject.

Definition at line 88 of file basket.cpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 275 of file basket.hpp.

◆ pool_

ext::shared_ptr<Pool> pool_
private

Definition at line 276 of file basket.hpp.

◆ claim_

const ext::shared_ptr<Claim> claim_
private

The claim is the same for all names.

Definition at line 278 of file basket.hpp.

◆ attachmentRatio_

Real attachmentRatio_
private

Definition at line 280 of file basket.hpp.

◆ detachmentRatio_

Real detachmentRatio_
private

Definition at line 281 of file basket.hpp.

◆ basketNotional_

Real basketNotional_
private

Definition at line 282 of file basket.hpp.

◆ attachmentAmount_

Real attachmentAmount_
mutableprivate

basket tranched inception attachment amount:

Definition at line 284 of file basket.hpp.

◆ detachmentAmount_

Real detachmentAmount_
mutableprivate

basket tranched inception detachment amount:

Definition at line 286 of file basket.hpp.

◆ trancheNotional_

Real trancheNotional_
mutableprivate

basket tranched notional amount:

Definition at line 288 of file basket.hpp.

◆ evalDateSettledLoss_

Real evalDateSettledLoss_
mutableprivate

Definition at line 294 of file basket.hpp.

◆ evalDateRemainingNot_

Real evalDateRemainingNot_
private

Definition at line 295 of file basket.hpp.

◆ evalDateAttachAmount_

Real evalDateAttachAmount_
private

Definition at line 296 of file basket.hpp.

◆ evalDateDetachAmmount_

Real evalDateDetachAmmount_
private

Definition at line 297 of file basket.hpp.

◆ evalDateLiveList_

std::vector<Size> evalDateLiveList_
mutableprivate

Definition at line 298 of file basket.hpp.

◆ evalDateLiveNotionals_

std::vector<Real> evalDateLiveNotionals_
mutableprivate

Definition at line 299 of file basket.hpp.

◆ evalDateLiveNames_

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

Definition at line 300 of file basket.hpp.

◆ evalDateLiveKeys_

std::vector<DefaultProbKey> evalDateLiveKeys_
mutableprivate

Definition at line 301 of file basket.hpp.

◆ refDate_

const Date refDate_
private

Basket inception date.

Definition at line 303 of file basket.hpp.

◆ lossModel_

ext::shared_ptr<DefaultLossModel> lossModel_
private

Definition at line 312 of file basket.hpp.