Overview
One of the primary methods to fit a single sector latent variable credit default model is the method of Maximum Likelihood.
See Loffler for a full exposition.
Likelihood One Sector
At a given time {% t %} and a given realization of the latent variable {% Z %}, the probability of {% D_{t} %} defaults in {% N_{t} %} is
{% \binom{N_{t}}{D_{t}} p(Z)^{D_{t}} (1-p(Z))^{N_{t} - D_{t}} %}
The probability of the given realization of the {% Z %} is {% \frac{d \Phi(Z)}{dx} dx %}.
Then multiplying and summing (integrating) we get
{% L_{t} = \displaystyle \int_{- \infty}^{\infty} \binom{N_{t}}{D_{t}} p(Z)^{D_{t}} (1-p(Z))^{N_{t} - D_{t}} d \Phi(Z) %}
where the integral here is a
Riemann Stieltjes Integral.
Here
{% d\Phi = \sqrt{1/2\pi \sigma^2 } \times e ^{-0.5 [(x-\mu)/\sigma]^2} dx %}
This integral can be approximated using the Gauss Hermite Quadrature
The Likelihood over the entire time period is given by
{% L = \Pi_{t=1}^T L_{t} %}
and hence the log-likelihood is
{% ln L = \sum_{t=1}^T ln \int_{- \infty}^{\infty} \binom{N_{t}}{D_{t}} p(Z)^{D_{t}} (1-p(Z))^{N_{t} - D_{t}} d \Phi(Z) %}
Likelihood One Sector
We encode the data as an array of sample points. Each sample point is an array where the first number represents {% N_{t} %} and the second number is {% D_{t} %}. Each data point represents a separate point in time.
let data = [
[1064,0],
[1327,2],
];
For a given time point, and a given value of {% p %} and {% w %}, we need to construct a function which computes
{% \binom{N_{t}}{D_{t}} p(Z)^{D_{t}} (1-p(Z))^{N_{t} - D_{t}} %}
The following code implements this.
let cb = await import('/lib/combinatorics/v1.0.0/combinatorics.mjs');
let getIntegrand = function(N, D, p, w){
return function(x){
let combinations = cb.combinations(N,D);
let condProb = ml.conditionalProbability(x,p,w);
return combinations * Math.pow(condProb, D) * Math.pow(1-condProb,N-D);
}
}
Next, we need to compute the given integral, take the logarithm and then sum.
let sum = 0;
for(let item of data){
let integrand = getIntegrand(item[0], item[1],p,w);
let integral = ml.gaussHermite(integrand);
let logLike1 = Math.log(integral);
sum+=logLike1;
}