Correlated Default Monte Carlo Example

Overview

The simple model of loan defaults ignores the correlations amongs the defaults. (see correlated defaults)

There are different methods that can model correlate defaults. In this example we utilize the latent variables method. Here, we model correlations between defaults in the same period. This example will ignore correlations from one period to the next.

Setting the Context

The latent variable model assumes that there is a single latent variable {% Z %}, which is normally distibuted and drives correlations among defaults.

We simulate the latent variable in the context method. It generates a single realization of the latent variable and returns it as the context for simulations for that period.

def context(date, contexts): z = random.gauss(0, 1) return {"Z":z}

Simulating a Single Loan

Now, to simulate a single default, we must simulate a new variable for each loan, labeled {% A %} as follows: {% A_i = w_i Z + \sqrt{1-w_i^2} e_i %} Here {% Z %} is the laten variable that is simulated and stored in each periods context, as above.

Next, default happens when {% A %} is less than a predetermined treshold, {% d %} {% y_i = 1 %} when {% A_i \leq d_i %} (see latent variables for details)
def simulate_item(item, contexts, date): result = {} if date > item['maturity']: return None else: w = 0.4 d=-2.0 e = random.gauss(0, 1) A = w*contexts[-1]['Z'] + math.sqrt(1-w*w) * e if A <= d: item['defaulted'] = True item['loss'] = beta.rvs(a=2.0, b=5.0).item() return item pass

Run Sample