Page 238 - Writing Excel Macros with VBA, 2nd Edition
P. 238

Yield Curve Models                                       221

**************************************************************************
To make this code ready-to-use, we retrieve the market data in the body of the procedure. See
Figures 6.1 and 6.2.
**************************************************************************

Redim Fwd!(p),discFwd!(p),caplet!(p),volCaplet!(p)
Redim sumcap!(p),cap!(p),sumfloor!(p),floor!(p),capit!(p)

ReDim correl#(p - 1, p - 1)
Dim i As Long
For i = 1 To p - 1

       For j = i To p - 1
              correl(i, j) = Exp(-0.1 * (j - i) *t)
              correl(j, i) = correl(i, j)

       Next
Next

Fwd(0) = 0.04: discFwd(0) = 1 / (1 + Fwd(0) * t)

For i = 1 To p - 1
       Fwd(i) = 0.04 * Exp(0.01 * i)
       discFwd(i) = discFwd(i - 1) / (1 + Fwd(i) * 0.25)

Next

volCaplet(1) = 0.135
volCaplet(2) = 0.14
volCaplet(3) = 0.145
volCaplet(4) = 0.1425
For i = 5 To 10

       volCaplet(i) = 0.14 - (i - 5) * 0.002
Next i
For i = 11 To p - 1

       volCaplet(i) = 0.128
Next i

Dim d1#, d2#
For i = 1 To p - 1

       d1 = volCaplet(i) * Sqr(i * t) / 2
       d2 = d1 - volCaplet(i) * Sqr(i * t)
       caplet(i) = (norm(d1) - norm(d2)) * t * discFwd(i)
Next

***********************************************************************
corr is an array of variant type: each element is a correlation matrix
Each trig(i) is the Cholesky decomposition of corr(i)
Since there are (p-1) steps in one scenario, we need p-1 correlation matrices.
Remember that, at each step, the correlation matrix is shifted, so are volCaplet(i) and Fwd(i)
***********************************************************************

ReDim corr(p - 1) As Variant
ReDim trig(p - 1) As Variant

For i = 1 To p - 1
       corr(i) = DoubleToVarArray(drift(Correl, i - 1))
       trig(i) = Cholesky(VarToDoubleArray(corr(i)))

                    www.it-ebooks.info
   233   234   235   236   237   238   239   240   241   242   243