Facebook
From pawelma, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 197
  1. Sub model_crr()
  2.     S0 = Cells(1, 2)
  3.     K = Cells(2, 2)
  4.     t = Cells(3, 2)
  5.     r = Cells(4, 2)
  6.     sigma = Cells(5, 2)
  7.     N = Cells(7, 2)
  8.     delta_t = t / N
  9.     Cells(8, 2) = delta_t
  10.     u = Exp(sigma * delta_t ^ 0.5)
  11.     Cells(9, 2) = u
  12.     d = 1 / u
  13.     Cells(10, 2) = d
  14.     p = (Exp(r * delta_t) - d) / (u - d)
  15.     Cells(11, 2) = p
  16.     Cells(12, 2) = 1 - p
  17.     For i = 0 To N
  18.         Cells(3, 4 + i) = i
  19.     Next i
  20.    
  21.     Dim S(100, 100) As Double
  22.    
  23.     Cells(4, 4) = S0
  24.    
  25.     For i = 1 To N
  26.         For j = 0 To i
  27.             S(i, j) = S0 * u ^ j * d ^ (i - j)
  28.             Cells(4 + i - j, 4 + i) = S(i, j)
  29.         Next j
  30.     Next i
  31.    
  32.    
  33.    
  34.    
  35. End Sub
  36.