Skip to content
All library documents

Simulating Default Times with a Stochastic Hazard Rate

Article Quant Q&A · Author: Daniel Lobo

Summary

The answer interprets the VBA snippet as an attempt to simulate default under a lognormal stochastic intensity. It describes the hazard rate as evolving multiplicatively with volatility and a Brownian shock, with a shared factor intended to correlate hazard-rate movements across entities. The correlation parameter appears to function like a factor loading, though the snippet does not make its meaning certain.

Default is sampled by comparing a uniform random draw with the probability implied by the current hazard rate over a time step, using either the small-step approximation or the exponential survival formula. The answer flags implementation problems: the time increment seems to be applied twice in the hazard update, the default interval is fixed separately, and repeated calls using the same seed may fail to produce distinct draws. This is a code interpretation, not a validated model specification; the intended factor structure and random-number behavior require confirmation.

Key ideas

  • The hazard-rate update is consistent with a multiplicative, lognormal intensity process.
  • A common factor can induce dependence among entities’ hazard-rate shocks.
  • Default sampling compares a uniform draw with the probability of default over the interval.
  • The time-step treatment appears inconsistent and may apply the interval twice.
  • The repeated seed handling and the intended correlation structure are uncertain.

Tags

Full text
# Determination of default time based on some model


# Determination of default time based on some model












I have come across below snippet of VBA code, which is basically trying to randomly generate Default time based on some model of Hazard rate

```
Seed = 7777
ReDim GaussOut(0 To Steps + 1)
CorrTerm = Sqr(1 - Correlation ^ 2)
VolTerm = (-Vol * Vol / 2) * DT
SqrDT = Sqr(DT)

While Tries < 50

    ThisHR = HR

    For i = 1 To Steps
        Gauss = gasdev(Seed)
        GaussOut(i) = Gauss * Correlation + gasdev(Seed) * CorrTerm
        ThisHR = ThisHR * Exp(VolTerm * DT + Gauss * Vol * SqrDT)
        URand = Rnd()
        If ((1 - Exp(-ThisHR * 0.25)) > URand) Then
            GaussOut(0) = i
            GaussOut(i + 1) = Tries + 1
            Tries = 51
            i = Steps + 1
        End If
    Next i
    Tries = Tries + 1
Wend
```

While I do not have any documentation of above code, based on some study, I could extract some information as below

- `DT` is step size

- `gasdev` function generates a `standard normal variate` based on some seed

- `HR` is initial Hazard rate

It appears that the Hazard rate is evolving according some model viz `ThisHR = ThisHR * Exp(VolTerm * DT + Gauss * Vol * SqrDT)`.

Could you please help me to understand what this model is? From some other discussions, it may appear that Hazard rate is assumed to follow some `Log-normal model`, but I am not sure and could not completely relate above formula with any `Log-normal model`.

Furthermore a default is assumed to happen if `((1 - Exp(-ThisHR * 0.25)) > URand)`. Why is it so?

Also above model is assumed to be using some parameters like `Correlation` and `vol`. I again failed to comprehend what these 2 parameters signifies i.e. `vol` of what? `Correlation` with what?

Any pointer on above questions will be very helpful and would really appreciate.

Thanks for your time.

## Answer by achirikhin (score 2, accepted)

https://quant.stackexchange.com/a/79266

There are many bugs in this code

Looks like it is trying to draw a default time using a lognormal stochastic intensity model,

$dh/h = Vol\times dW$,

where $dW$ is drawn such that it is correlated with some common factor. Looks like it is part of the basket default time simulation, where all hazard rate brownian motions are correlated with correlation "correlation^2" (what this code calls "correlation" is actually "beta".

The integral of this process is the line for ThisHR, but term VolTerm * DT is incorrect, because DT is already present in VolTerm. It must be only in one place.

The instantaneous default probability is $h\times dt$, so to sample the default event at the given time you need to to draw "probability" of such event, which is uniform normal (urand) and then compare it with the "sampled probability", which is either $h\times dt$, or $1-exp(-h\times dt)$, which is more correct and stable. However in the code dt is explicitly assumed 0.25 (a quarter), while other DT is not specified. They should be same.

Such generation of an exponential variable is equivalent to generation of a Gaussian variable using (in Excel) =Nomsinv(rand()).

All in all, the code seems to make 50 attempts to generate a default event. On the first successful generation it stops. In GaussOut(0) it returns the default time as the index of the time step, in GaussOut(i) it returns the number of trials that were necessary to generate such default time.

It is not clear why gasdev(Seed) is always called with the same Seed. You need to check that each invocation does produce a different random number.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.