You are on page 1of 1



Sunday, November 3, 2013 9:46 AM

Attribute VB_Name = "Default" Option Explicit 'Caclulates the exact default time. Uses the function presented by Richard Diamond 'during the CQF final project workshop lecture. Function DefaultTime(L As Variant, P As Variant, u As Double, T As Integer) As Double 'L - hazard rate array 'P - survival probability array 'u - Correlated random variable 'T - max tenor Dim I As Integer, j As Integer Dim Tenor As Double, dt As Double Dim C As Double Dim L_sum As Double 'generated random survival probability C = Abs(Log(1 - u)) For I = 1 To T 'hazard rates are accumulated and compared to the generated survival probability L_sum = L_sum + L(I, 1) If L_sum >= C Then Tenor = I - 1 If Tenor >= 1 Then 'delta T is calculated to find the exact fraction of the year the default occurs dt = -1 / L(I, 1) * Log((1 - u) / P(Tenor, 1)) 'dt is added to the integer part of the years' scale If dt > 1 Then DefaultTime = 0 Exit Function Else DefaultTime = Tenor + dt Exit Function End If Else 'if default occurs before the end of year 1, the function will 'return 0.5, as we assume that the default may be settled in half a year, DefaultTime = 0.5 Exit Function End If End If Next I 'if default doesn't occur before maturity, the function returns 0. DefaultTime = 0 End Function