Simulating Default with Bernoulli Distribution

Overview

The Bernoulli Model of Pd can be used to simlulate default.

Bernoulli Distribution

The simplest way to simulate a default over a given time frame is to model the default as a Bernoulli variable. (see the Bernoulli Distribution). A Bernoulli variable is a random variable that takes only one of two values, with probabilities p, and (1-p).

In the case of default, one could label default of asset i in a portfolio as
{% Default = D_i %}
Then the probability of default is labeled {% PD_i %}

Implementation

A simple way to simulate a 0-1 event such as default is to simulate a number from 0 to 1 with a uniform distribution, and if the simulated number is less than the probability of default, then take that as a default, otherwise take it to be no default.

//probability of default let pd = 0.01; let di; let u = Math.random(); if(u<pd) di=1; else di = 0;

Bernoulli API

The bernoulli module can also be used to simulate default.

let bl = await import('/code/bernoulli/v1.0.0/bernoulli.mjs'); //probability of default let pd = 0.01; let di = bl.random(pd);