1
$\begingroup$

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

  1. DT is step size
  2. gasdev function generates a standard normal variate based on some seed
  3. 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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Thanks for the explanation. Could you please also explain GaussOut(i) = Gauss * Correlation + gasdev(Seed) * CorrTerm? GaussOut(i) is Standard Normal variable, as can be seen from this relation. However Author use this to simulate Short rate path using Hull White One Factor model. I am just wondering why he used GaussOut instead just gasdev . Is it because he wanted to bring Correlation structure with something? Then how and what with? $\endgroup$ Commented May 6 at 7:25
  • $\begingroup$ This is how correlations are introduced using "1 factor gaussian" framework. If you have N correlated factors to simulate, then for $i$-th and $j$-th factors define $\\$ $Y_i = \beta_i Z + \sqrt{1-{\beta_i}^2} X_i$ $\\$ $Y_j = \beta_j Z + \sqrt{1-{\beta_i}^2} X_j$ where $Z$ and all $X_k, k=1..N$ are standard Normal and independent, then $Y_k$ are still standard normal, but $correl(Y_i, Y_j)=\beta_i \beta_j$ In your case you have a "homogenous" 1-factor model, where for all indices $\beta_i = \beta_j = \beta = \sqrt{\rho}$, where $\rho$ is correlation. $\endgroup$
    – achirikhin
    Commented May 6 at 10:04
  • $\begingroup$ A typo in the formula for $Y_j$. It should only contain $\beta_j$. $\endgroup$
    – achirikhin
    Commented May 6 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.