LatentModel< copulaPolicyImpl > − Generic multifactor latent variable model.

`#include <ql/experimental/math/latentmodel.hpp>`

Inherits **Observer**, and **Observable**.

**Classes**

class **FactorSampler**

**Public Member Functions**

void **update** () **
Real latentVarValue** (const std::vector<

const copulaType &

Size size

Size numFactors

Number of systemic factors.

Size numTotalFactors

Number of total free random factors; systemic and idiosyncratic.

LatentModel

LatentModel

LatentModel

LatentModel

const std::vector< std::vector<

Provides values of the factors $ a_{i,k} $.

const std::vector<

Provides values of the normalized idiosyncratic factors $ Z_i $.

Real latentVariableCorrel

Latent variable correlations:

**Protected Attributes**

std::vector< std::vector< **Real** > > **factorWeights_
Handle**<

std::vector<

Size nFactors_

Number of systemic factors.

Size nVariables_

Number of latent model variables, idiosyncratic terms or model dim.

copulaType

**Copula interface.**

typedef copulaPolicyImpl **copulaType
Probability cumulativeY** (

Probability cumulativeZ

Cumulative distribution of Z, the idiosyncratic/error factors.

Probability density

Density function of M, the market/systemic factors.

Real inverseCumulativeDensity

Inverse cumulative distribution of the systemic factor iFactor.

Real inverseCumulativeY

Real inverseCumulativeZ

Disposable

**Integration facility interface**

**Real integratedExpectedValue** (const boost::function< **Real**(const std::vector< **Real** > &v1)> &f) const **
Disposable**< std::vector<

virtual const boost::shared_ptr< LMIntegration > &

**Additional Inherited Members**

**template<class copulaPolicyImpl>**

class QuantLib::LatentModel< copulaPolicyImpl >" Generic multifactor latent variable model.

In this model set up one considers latent (random) variables $ Y_i g i n { a r r a y } { c c c c c } Y _ 1 & = & _ k M _ k a _ { 1 , k } $ described by: &r \ ... & = & ... & ... & 0number \ Y_i & = & _k + t { 1 - _ k a _ { 1 , k } ^ 2 } Z _ 1 & P h i _ { Y _ 1 } 0 n u m b M_k a_{i,k} & + t{1-_k a_{i,k}^2} Z_i & Phi_{Y_i}0number \ ... & = & ... & ... & 0number \ Y_N & = & _k M_k a_{N,k} & + t{1-_k a_{N,k}^2} Z_N & Phi_{Y_N} \nd{array} ] where the systemic $ M_k $ and idiosyncratic $ Z_i $ (this last one known as error term in some contexts) random variables have independent zero-mean unit-variance distributions. A restriction of the model implemented here is that the N idiosyncratic variables all follow the same probability law $ Phi_Z(z)$ (but they are still independent random variables) Also the model is normalized so that: $-1 a_{i,k} 1$ (technically the $Y_i$ are convex linear combinations). The correlation between $Y_i$ and $Y_j$ is then $_k a_{i,k} a_{j,k}$. $Phi_{Y_i}$ denotes the cumulative distribution function of $Y_i$ which in general differs for each latent variable.

In its single factor set up this model is usually employed in derivative pricing and it is best to use it through integration of the desired statistical properties of the model; in its multifactorial version (with typically around a dozen factors) it is used in the context of portfolio risk metrics; because of the number of variables it is best to opt for a simulation to compute model properties/magnitudes. For this reason this class template provides a random factor sample interface and an integration interface that will be instantiated by derived concrete models as needed. The class is neutral on the integration and random generation algorithms

The latent variables are typically treated as unobservable magnitudes and they serve to model one or several magnitudes g i n { a r r a y } { c c c } F _ i ( Y _ i ) & = & F _ i ( _ k M _ related to them through some function kr \ & = & F_i(M_1,..., M_k, a _ { i , k } + t { 1 - _ k a _ { i , k } ^ 2 } Z _ i ) 0 n u m b ..., M_K, Z_i) \nd{array} ] The transfer function can have a more generic form: $F_i(Y_1,....,Y_N)$ but here the model is restricted to a one to one relation between the latent variables and the modelled ones. Also it is assumed that $F_i(y_i; au)$ is monotonic in $y_i$; it can then be inverted and the relation of the cumulative probability of $F_i$ and $Y_i$ is simple: int_{infty}^b hi_{F_i} df = int_{infty}^{F_i^{-1}(b)} hi_{Y_i} dy ] If $t$ is some value of the functional or modelled variable, $y$ is mapped to $t$ such that percentiles match, i.e. $F_Y(y)=Q_i(t)$ or $y=F_Y^{-1}(Q_i(t))$. The class provides an integration facility of arbitrary functions dependent on the model states. It also provides random number generation interfaces for usage of the model in monte carlo simulations.

Now let $Phi_Z(z)$ be the cumulated distribution function of (all equal as mentioned) $Z_i$. For a given realization of $M_k$, this determines the distribution of $y$: Prob (Y_i < y|M_k) = Phi_Z t(ight) qquad ox{or} qquad ac{y-_k a_{i,k}M_k} {t{1-_k a_{i,k}^2}} Prob (t_i < t|M) = Phi_Z t( ac {F_{Y_{i}}^{-1}(Q_i(t))-_kight) ] The distribution functions a_{i,k}M_k} {t{1-_k a_{i,k}^2}} of $ M_k, Z_i $ are specified in specific copula template classes. The distribution function of $ Y_i $ is then given by the convolution F_{Y_{i}}(y) = Prob(Y_i<y) = int_{-infty}^infty

This convolution can also be written F_{Y_{i}}(y) = Prob (Y_i < y) = int_{-infty}^infty

The policy class template separates the copula function (the distributions involved) and the functionality (i.e. what the latent model represents: a default probability, a recovery...). Since the copula methods for the probabilities are to be called repeatedly from an integration or a MC simulation, virtual tables are avoided and template parameter mechnics is preferred.

There is nothing at this level enforncing the requirement on the factor distributions to be of zero mean and unit variance. Thats the user responsibility and the model fails to behave correctly if it is not the case.

Derived classes should implement a modelled magnitude (default time, etc) and will provide probability distributions and conditional values. They could also provide functionality for the parameter inversion problem, the (e.g.) time at which the modeled variable first takes a given value. This problem has solution/sense depending on the transfer function $F_i(Y_i)$ characteristics.

To make direct integration and simulation time efficient virtual functions have been avoided in accessing methods in the copula policy and in the sampling of the random factors

**LatentModel (const std::vector< std::vector< Real > > & factorsWeights, const typename copulaType::initTraits & ini =** `copulaType::initTraits()`**)** `[explicit]`

Constructs a LM with an arbitrary number of latent variables and factors given by the dimensions of the passed matrix.

**Parameters:**

*factorsWeights* Ordering is factorWeights_[iVar][iFactor] *
ini* Initialization variables. Trait type from the copula policy to allow for static policies (this solution needs to be revised, possibly drop the static policy and create a policy member in

**LatentModel (const std::vector< Real > & factorsWeight, const typename copulaType::initTraits & ini =** `copulaType::initTraits()`**)** `[explicit]`

Constructs a LM with an arbitrary number of latent variables depending only on one random factor but contributing to each latent variable through different weights.

**Parameters:**

*factorsWeight* Ordering is factorWeights_[iVariable] *
ini* Initialization variables. Trait type from the copula policy to allow for static policies (this solution needs to be revised, possibly drop the static policy and create a policy member in

**LatentModel (const Real correlSqr, Size nVariables, const typename copulaType::initTraits & ini =** `copulaType::initTraits()`**)** `[explicit]`

Constructs a LM with an arbitrary number of latent variables depending only on one random factor with the same weight for all latent variables.

correlSqr is the weight, same for all.

ini is a trait type from the copula policy, to allow for static policies (this solution needs to be revised, possibly drop the static policy and create a policy member in **LatentModel**)

**LatentModel (const Handle< Quote > & singleFactorCorrel, Size nVariables, const typename copulaType::initTraits & ini =** `copulaType::initTraits()`**)** `[explicit]`

Constructs a LM with an arbitrary number of latent variables depending only on one random factor with the same weight for all latent variables. The weight is observed and this constructor is intended to be used when the model relates to a market value.

singleFactorCorrel is the weight/mkt-factor, same for all.

ini is a trait type from the copula policy, to allow for static policies (this solution needs to be revised, possibly drop the static policy and create a policy member in **LatentModel**)

**void update ()** `[virtual]`

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

**Probability cumulativeY (Real val, Size iVariable) const**

Cumulative probability of the $ Y_i $ modelled latent random variable to take a given value.

**Real inverseCumulativeY (Probability p, Size iVariable) const**

Inverse cumulative value of the i-th random latent variable with a given probability.

**Real inverseCumulativeZ (Probability p) const**

Inverse cumulative value of the idiosyncratic variable with a given probability.

**Disposable<std::vector<Real> > allFactorCumulInverter (const std::vector< Real > & probs) const**

All factor cumulative inversion. Used in integrations and sampling. Inverts all the cumulative random factors probabilities in the model. These are all the systemic factors plus all the idiosyncratic ones, so the size of the inversion is the number of systemic factors plus the number of latent modelled variables

**Real latentVarValue (const std::vector< Real > & allFactors, Size iVar) const**

The value of the latent variable Y_i conditional to (given) a set of values of the factors.

The passed allFactors vector contains values for all the independent factors in the model (systemic and idiosyncratic, in that order). A full sample is required, i.e. all the idiosyncratic values are expected to be present even if only the relevant one is used.

**Real integratedExpectedValue (const boost::function< Real(const std::vector< Real > &v1)> & f) const**

Integrates an arbitrary scalar function over the density domain(i.e. computes its expected value).

**Disposable<std::vector<Real> > integratedExpectedValue (const boost::function< Disposable< std::vector< Real > >(const std::vector< Real > &v1)> & f) const**

Integrates an arbitrary vector function over the density domain(i.e. computes its expected value).

Generated automatically by Doxygen for QuantLib from the source code.