QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Protected Member Functions | Private Types | List of all members
RandomLM< derivedRandomLM, copulaPolicy, USNG > Class Template Reference

#include <randomdefaultlatentmodel.hpp>

+ Inheritance diagram for RandomLM< derivedRandomLM, copulaPolicy, USNG >:
+ Collaboration diagram for RandomLM< derivedRandomLM, copulaPolicy, USNG >:

Protected Member Functions

 RandomLM (Size numFactors, Size numLMVars, copulaPolicy copula, Size nSims, BigNatural seed)
 
void update () override
 
void performCalculations () const override
 
void performSimulations () const
 
const std::vector< simEvent< derivedRandomLM< copulaPolicy, USNG > > > & getSim (const Size iSim) const
 
Real getEventRecovery (const simEvent< derivedRandomLM< copulaPolicy, USNG > > &evt) const
 
- Protected Member Functions inherited from LazyObject
virtual void calculate () const
 
- Protected Member Functions inherited from DefaultLossModel
 DefaultLossModel ()=default
 
virtual Probability probOverLoss (const Date &d, Real lossFraction) const
 
virtual std::vector< RealsplitESFLevel (const Date &d, Real loss) const
 Associated ESF fraction to each counterparty. More...
 
virtual Real densityTrancheLoss (const Date &d, Real lossFraction) const
 Probability density of a given loss fraction of the basket notional. More...
 
virtual Real expectedRecovery (const Date &, Size iName, const DefaultProbKey &) const
 

Private Types

typedef LatentModel< copulaPolicy >::template FactorSampler< USNG > copulaRNG_type
 

Statistics, DefaultLossModel interface.

BigNatural seed_
 
const Size numFactors_
 
const Size numLMVars_
 
const Size nSims_
 
std::vector< std::vector< simEvent< derivedRandomLM< copulaPolicy, USNG > > > > simsBuffer_
 
copulaPolicy copula_
 
ext::shared_ptr< copulaRNG_typecopulasRng_
 
static const Size maxHorizon_ = 4050
 
Probability probAtLeastNEvents (Size n, const Date &d) const override
 
std::vector< ProbabilityprobsBeingNthEvent (Size n, const Date &d) const override
 
Real defaultCorrelation (const Date &d, Size iName, Size jName) const override
 Pearsons' default probability correlation. More...
 
Real expectedTrancheLoss (const Date &d) const override
 
virtual std::pair< Real, RealexpectedTrancheLossInterval (const Date &d, Probability confidencePerc) const
 
std::map< Real, ProbabilitylossDistribution (const Date &d) const override
 Full loss distribution. More...
 
virtual Histogram computeHistogram (const Date &d) const
 
Real expectedShortfall (const Date &d, Real percent) const override
 Expected shortfall given a default loss percentile. More...
 
Real percentile (const Date &d, Real percentile) const override
 Value at Risk given a default loss percentile. More...
 
virtual ext::tuple< Real, Real, RealpercentileAndInterval (const Date &d, Real percentile) const
 
std::vector< RealsplitVaRLevel (const Date &date, Real loss) const override
 
virtual std::vector< std::vector< Real > > splitVaRAndError (const Date &date, Real loss, Probability confInterval) const
 
 ~RandomLM () override=default
 

Additional Inherited Members

- Public Types inherited from Observer
typedef set_type::iterator iterator
 
- 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 ()
 
- Protected Attributes inherited from LazyObject
bool calculated_ = false
 
bool frozen_ = false
 
bool alwaysForward_
 
- Protected Attributes inherited from DefaultLossModel
RelinkableHandle< Basketbasket_
 

Detailed Description

template<template< class, class > class derivedRandomLM, class copulaPolicy, class USNG = SobolRsg>
class QuantLib::RandomLM< derivedRandomLM, copulaPolicy, USNG >

Base class for latent model monte carlo simulation. Independent of the copula type and the generator. Generates the factors and variable samples and determines event threshold but it is not responsible for actual event specification; thats the derived classes responsibility according to what they model. Derived classes need mainly to implement nextSample (Worker::nextSample in the multithreaded version) to compute the simulation event generated, if any, from the latent variables sample. They also have the accompanying event trait to specify.

Definition at line 96 of file randomdefaultlatentmodel.hpp.

Member Typedef Documentation

◆ copulaRNG_type

typedef LatentModel<copulaPolicy>::template FactorSampler<USNG> copulaRNG_type
private

Definition at line 102 of file randomdefaultlatentmodel.hpp.

Constructor & Destructor Documentation

◆ RandomLM()

RandomLM ( Size  numFactors,
Size  numLMVars,
copulaPolicy  copula,
Size  nSims,
BigNatural  seed 
)
protected

Definition at line 104 of file randomdefaultlatentmodel.hpp.

◆ ~RandomLM()

~RandomLM ( )
overridedefault

Member Function Documentation

◆ update()

void update ( )
overrideprotectedvirtual

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 108 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ performCalculations()

void performCalculations ( ) const
overrideprotectedvirtual

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

Implements LazyObject.

Definition at line 116 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ performSimulations()

void performSimulations ( ) const
protected

Definition at line 123 of file randomdefaultlatentmodel.hpp.

+ Here is the caller graph for this function:

◆ getSim()

const std::vector< simEvent< derivedRandomLM< copulaPolicy, USNG > > > & getSim ( const Size  iSim) const
protected

Definition at line 141 of file randomdefaultlatentmodel.hpp.

◆ getEventRecovery()

Real getEventRecovery ( const simEvent< derivedRandomLM< copulaPolicy, USNG > > &  evt) const
protected

Definition at line 145 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ probAtLeastNEvents()

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

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

Reimplemented from DefaultLossModel.

Definition at line 227 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ probsBeingNthEvent()

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

Order of results refers to the simulated (super)pool not the basket's pool. Notice that this statistic suffers from heavy dispersion. To see techniques to improve it (not implemented here) see: Joshi, M., D. Kainth. 2004. Rapid and accurate development of prices and Greeks for nth to default credit swaps in the Li model. Quantitative Finance, Vol. 4. Institute of Physics Publishing, London, UK, 266-275 and: Chen, Z., Glasserman, P. 'Fast pricing of basket default swaps' in Operations Research Vol. 56, No. 2, March/April 2008, pp. 286-303

Reimplemented from DefaultLossModel.

Definition at line 254 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ defaultCorrelation()

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

Pearsons' default probability correlation.

Reimplemented from DefaultLossModel.

Definition at line 297 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ expectedTrancheLoss()

Real expectedTrancheLoss ( const Date d) const
overrideprotectedvirtual

Reimplemented from DefaultLossModel.

Definition at line 338 of file randomdefaultlatentmodel.hpp.

◆ expectedTrancheLossInterval()

std::pair< Real, Real > expectedTrancheLossInterval ( const Date d,
Probability  confidencePerc 
) const
protectedvirtual

Definition at line 345 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ lossDistribution()

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

Full loss distribution.

Reimplemented from DefaultLossModel.

Definition at line 384 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ computeHistogram()

Histogram computeHistogram ( const Date d) const
protectedvirtual

Definition at line 401 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ expectedShortfall()

Real expectedShortfall ( const Date d,
Real  percentile 
) const
overrideprotectedvirtual

Expected shortfall given a default loss percentile.

Reimplemented from DefaultLossModel.

Definition at line 443 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ percentile()

Real percentile ( const Date d,
Real  percentile 
) const
overrideprotectedvirtual

Value at Risk given a default loss percentile.

Reimplemented from DefaultLossModel.

Definition at line 525 of file randomdefaultlatentmodel.hpp.

◆ percentileAndInterval()

ext::tuple< Real, Real, Real > percentileAndInterval ( const Date d,
Real  percentile 
) const
protectedvirtual

Returns the VaR value for a given percentile and the 95 confidence interval of that value.

Definition at line 538 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

◆ splitVaRLevel()

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

Distributes the total VaR amount along the portfolio counterparties. The passed loss amount is in loss units.

Reimplemented from DefaultLossModel.

Definition at line 621 of file randomdefaultlatentmodel.hpp.

◆ splitVaRAndError()

std::vector< std::vector< Real > > splitVaRAndError ( const Date date,
Real  loss,
Probability  confInterval 
) const
protectedvirtual

Distributes the total VaR amount along the portfolio counterparties.

Provides confidence interval for split so that portfolio optimization can be performed outside those limits.

The passed loss amount is in loss units.

Definition at line 636 of file randomdefaultlatentmodel.hpp.

+ Here is the call graph for this function:

Member Data Documentation

◆ seed_

BigNatural seed_
private

Definition at line 205 of file randomdefaultlatentmodel.hpp.

◆ numFactors_

const Size numFactors_
protected

Definition at line 207 of file randomdefaultlatentmodel.hpp.

◆ numLMVars_

const Size numLMVars_
protected

Definition at line 208 of file randomdefaultlatentmodel.hpp.

◆ nSims_

const Size nSims_
protected

Definition at line 210 of file randomdefaultlatentmodel.hpp.

◆ simsBuffer_

std::vector<std::vector<simEvent<derivedRandomLM<copulaPolicy, USNG > > > > simsBuffer_
mutableprotected

Definition at line 213 of file randomdefaultlatentmodel.hpp.

◆ copula_

copulaPolicy copula_
mutableprotected

Definition at line 215 of file randomdefaultlatentmodel.hpp.

◆ copulasRng_

ext::shared_ptr<copulaRNG_type> copulasRng_
mutableprotected

Definition at line 216 of file randomdefaultlatentmodel.hpp.

◆ maxHorizon_

const Size maxHorizon_ = 4050
staticprotected

Definition at line 219 of file randomdefaultlatentmodel.hpp.