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
TCopulaThe copula policy.
TInitTraitsThe 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
factorWeightsIReadOnlyList<IReadOnlyList<double>>The weights of each variable on the independent factors.
integralTypeLatentModelIntegrationTypeThe integration.
initTraitsTInitTraitsThe copula's initialization parameters.
Exceptions
- ArgumentException
As LatentModel<TCopula, TInitTraits>'s constructor.
- ArgumentOutOfRangeException
integralTypeisn'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
correlationdoubleThe correlation, whose square root is every variable's weight.
nVariablesintThe number of variables.
integralTypeLatentModelIntegrationTypeThe integration.
initTraitsTInitTraitsThe copula's initialization parameters.
Exceptions
- ArgumentException
- ArgumentOutOfRangeException
integralTypeisn'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
Integration
Gets the model's integration.
protected override LMIntegration Integration { get; }
Property Value
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
invCumYProb1doubleThe first name's inverse cumulative unconditional probability.
invCumYProb2doubleThe second name's.
iName1intThe first name.
iName2intThe second name.
mktFactorsReadOnlySpan<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
dateDateThe date.
iNameintThe name.
mktFactorsReadOnlySpan<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
probdoubleThe unconditional probability.
iNameintThe name.
mktFactorsReadOnlySpan<double>The factors' values.
Returns
- double
The conditional probability.
Exceptions
- ArgumentOutOfRangeException
probisn't below 1e-10 andiNameisn't one of the names, where QuantLib reads past its end.- ArgumentException
probisn't below 1e-10 andmktFactorsholds 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
invCumYProbdoubleThe inverse cumulative of the unconditional probability, of the copula's law.
iNameintThe name.
mReadOnlySpan<double>The factors' values.
Returns
- double
The conditional probability.
Exceptions
- ArgumentOutOfRangeException
iNameisn't one of the names, where QuantLib reads past its end.- ArgumentException
mholds 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
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
disdefault(Date), not a date.- ArgumentOutOfRangeException
iNameioriNamejisn'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
Returns
- double
The probability.
Exceptions
- ArgumentOutOfRangeException
nis negative or above 30.- NanoQLException
The model isn't bound, or its basket has 32 names or more.
- ArgumentException
dateisdefault(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
Returns
- double
The probability.
Exceptions
- NanoQLException
The model isn't bound ("No portfolio basket set.").
- ArgumentException
disdefault(Date), not a date.- ArgumentOutOfRangeException
iNameisn'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
basketBasketThe basket, of the model's number of names.
Returns
- DefaultLatentModel<TCopula, TInitTraits>
The bound copy.
Exceptions
- ArgumentNullException
basketis 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
Returns
- double
The probability.
Exceptions
- NanoQLException
The model isn't bound ("No portfolio basket set.").