Table of Contents

Class DefaultLatentModel<TCopula, TInitTraits>

Namespace
NanoQL.Experimental
Assembly
NanoQL.dll

The default-event latent model: a latent model of a portfolio's joint default events, a name defaulting by a date when its latent variable falls below the inverse of its default probability. It models the events alone, no severity or exposure; the basket's names and the model's variables correspond by index.

[Experimental("NQL0001")]
public class DefaultLatentModel<TCopula, TInitTraits> : LatentModel<TCopula, TInitTraits> where TCopula : struct, ICopulaPolicy<TCopula, TInitTraits> where TInitTraits : struct

Type Parameters

TCopula

The copula policy.

TInitTraits

The policy's initialization parameters.

Inheritance
LatentModel<TCopula, TInitTraits>
DefaultLatentModel<TCopula, TInitTraits>
Derived
Inherited Members

Remarks

Unsealed and immutable. ResetBasket(Basket) returns a copy bound to a basket, where QuantLib's model holds a mutable pointer to one; bound to a basket with realized defaults, the copy keeps the live names' rows. A curve read before its reference date is a default probability of 0, where QuantLib's refuses it ("negative time").

ProbAtLeastNEvents(int, Date) sums over every default configuration, 2ⁿ per integration node, counting them in QuantLib's BigNatural, 32 bits under MSVC: from 32 names its count is 0 and its probability of one or more defaults 0, and an order above 30 shifts a 32-bit 1 past its sign (defaultprobabilitylatentmodel.hpp:295-309), both refused. DefaultCorrelation(Date, int, int) divides by the product of the probabilities and their complements, 0/0 at a probability of 0 or 1, refused.

Constructors

DefaultLatentModel(IReadOnlyList<IReadOnlyList<double>>, LatentModelIntegrationType, TInitTraits)

Initializes a new instance of the DefaultLatentModel<TCopula, TInitTraits> class.

public DefaultLatentModel(IReadOnlyList<IReadOnlyList<double>> factorWeights, LatentModelIntegrationType integralType, TInitTraits initTraits = default)

Parameters

factorWeights IReadOnlyList<IReadOnlyList<double>>

The weights of each variable on the independent factors.

integralType LatentModelIntegrationType

The integration.

initTraits TInitTraits

The copula's initialization parameters.

Exceptions

ArgumentException

As LatentModel<TCopula, TInitTraits>'s constructor.

ArgumentOutOfRangeException

integralType isn't a member of its type, or there are more than 15 factors.

DefaultLatentModel(double, int, LatentModelIntegrationType, TInitTraits)

Initializes a new instance of the DefaultLatentModel<TCopula, TInitTraits> class on one factor of a market correlation: QuantLib's quote constructor.

public DefaultLatentModel(double correlation, int nVariables, LatentModelIntegrationType integralType, TInitTraits initTraits = default)

Parameters

correlation double

The correlation, whose square root is every variable's weight.

nVariables int

The number of variables.

integralType LatentModelIntegrationType

The integration.

initTraits TInitTraits

The copula's initialization parameters.

Exceptions

ArgumentException

As FromCorrelation(double, int, TInitTraits).

ArgumentOutOfRangeException

integralType isn't a member of its type.

Properties

Basket

Gets the basket the model is bound to, or null before it is bound.

public Basket? Basket { get; }

Property Value

Basket

Integration

Gets the model's integration.

protected override LMIntegration Integration { get; }

Property Value

LMIntegration

Methods

CondProbProduct(double, double, int, int, ReadOnlySpan<double>)

The product of two names' conditional default probabilities, a step of the correlation.

protected double CondProbProduct(double invCumYProb1, double invCumYProb2, int iName1, int iName2, ReadOnlySpan<double> mktFactors)

Parameters

invCumYProb1 double

The first name's inverse cumulative unconditional probability.

invCumYProb2 double

The second name's.

iName1 int

The first name.

iName2 int

The second name.

mktFactors ReadOnlySpan<double>

The factors' values.

Returns

double

The product.

ConditionalDefaultProbability(Date, int, ReadOnlySpan<double>)

A name's default probability by a date conditional on the factors' values.

protected double ConditionalDefaultProbability(Date date, int iName, ReadOnlySpan<double> mktFactors)

Parameters

date Date

The date.

iName int

The name.

mktFactors ReadOnlySpan<double>

The factors' values.

Returns

double

The conditional probability.

Exceptions

NanoQLException

The model isn't bound.

ConditionalDefaultProbability(double, int, ReadOnlySpan<double>)

A name's default probability conditional on the factors' values, from its unconditional probability; the date is implicit in the probability. Below 1e-10, 0, sparing the inversion.

public double ConditionalDefaultProbability(double prob, int iName, ReadOnlySpan<double> mktFactors)

Parameters

prob double

The unconditional probability.

iName int

The name.

mktFactors ReadOnlySpan<double>

The factors' values.

Returns

double

The conditional probability.

Exceptions

ArgumentOutOfRangeException

prob isn't below 1e-10 and iName isn't one of the names, where QuantLib reads past its end.

ArgumentException

prob isn't below 1e-10 and mktFactors holds fewer values than the name's factors, where QuantLib reads past its end.

ConditionalDefaultProbabilityInvP(double, int, ReadOnlySpan<double>)

A name's default probability conditional on the factors' values, from the inverse cumulative of its unconditional probability, which an integration over the factors computes once.

public double ConditionalDefaultProbabilityInvP(double invCumYProb, int iName, ReadOnlySpan<double> m)

Parameters

invCumYProb double

The inverse cumulative of the unconditional probability, of the copula's law.

iName int

The name.

m ReadOnlySpan<double>

The factors' values.

Returns

double

The conditional probability.

Exceptions

ArgumentOutOfRangeException

iName isn't one of the names, where QuantLib reads past its end.

ArgumentException

m holds fewer values than the name's factors, where QuantLib reads past its end.

DefaultCorrelation(Date, int, int)

Pearson's correlation of two names' default indicators by a date.

public double DefaultCorrelation(Date d, int iNamei, int iNamej)

Parameters

d Date

The date.

iNamei int

The first name.

iNamej int

The second name.

Returns

double

The correlation.

Exceptions

NanoQLException

The model isn't bound, or a name's default probability is 0 or 1, where the correlation is 0/0.

ArgumentException

d is default(Date), not a date.

ArgumentOutOfRangeException

iNamei or iNamej isn't one of the bound basket's names, where QuantLib reads past its end.

ProbAtLeastNEvents(int, Date)

The probability of n or more defaults in the basket by a date.

public double ProbAtLeastNEvents(int n, Date date)

Parameters

n int

The number, at most 30.

date Date

The date.

Returns

double

The probability.

Exceptions

ArgumentOutOfRangeException

n is negative or above 30.

NanoQLException

The model isn't bound, or its basket has 32 names or more.

ArgumentException

date is default(Date), not a date.

ProbOfDefault(int, Date)

A name's unconditional default probability by a date, integrated over the factors: a trivial method for testing.

public double ProbOfDefault(int iName, Date d)

Parameters

iName int

The name.

d Date

The date.

Returns

double

The probability.

Exceptions

NanoQLException

The model isn't bound ("No portfolio basket set.").

ArgumentException

d is default(Date), not a date.

ArgumentOutOfRangeException

iName isn't one of the bound basket's names, where QuantLib reads past its end.

ResetBasket(Basket)

A copy of the model bound to a basket of its names: to the basket's live names, over its restated tranche where names have defaulted (PricingBasket), the copy keeping their rows.

public DefaultLatentModel<TCopula, TInitTraits> ResetBasket(Basket basket)

Parameters

basket Basket

The basket, of the model's number of names.

Returns

DefaultLatentModel<TCopula, TInitTraits>

The bound copy.

Exceptions

ArgumentNullException

basket is null.

NanoQLException

The basket's size isn't the model's ("Incompatible new basket and model sizes."), or every name in it has defaulted.

UnconditionalProbability(int, Date)

A name's unconditional default probability by a date, read on its curve: 0 before the curve's reference date.

protected double UnconditionalProbability(int iName, Date date)

Parameters

iName int

The name.

date Date

The date.

Returns

double

The probability.

Exceptions

NanoQLException

The model isn't bound ("No portfolio basket set.").