1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
Function Option_Value_3D(Vol, Int_Rate, PType, Strike, Expiration, NAS)
' NAS is number of asset steps
ReDim S(0 To NAS) As Double ' Asset array
dS = 2 * Strike / NAS ' 'Infinity' is twice the strike
dt = 0.9 / Vol ^ 2 / NAS ^ 2 ' For stability
NTS = Int(Expiration / dt) + 1 ' Number of time steps
dt = Expiration / NTS ' To ensure that expiration is an integer number of time steps away
ReDim V(0 To NAS, 0 To NTS) As Double ' Option value array
q = 1
If PType = "P" Then q = -1 ' Test for call or put
For i = 0 To NAS
S(i) = i * dS ' Set up S array
V(i, 0) = Application.Max(q * (S(i) - Strike), 0) ' Set up payoff
Next i
For k = 1 To NTS ' Time loop
For i = 1 To NAS - 1 ' Asset loop. End points treated separately
Delta = (V(i + 1, k - 1) - V(i - 1, k - 1)) / 2 / dS ' Central difference
Gamma = (V(i + 1, k - 1) - 2 * V(i, k - 1) + V(i - 1, k - 1)) / dS / dS ' Central difference
Theta = -0.5 * Vol ^ 2 * S(i) ^ 2 * Gamma - Int_Rate * S(i) * Delta + Int_Rate * V(i, k - 1) ' Black-Scholes
V(i, k) = V(i, k - 1) - dt * Theta
Next i
V(0, k) = V(0, k - 1) * (1 - Int_Rate * dt) ' Boundary condition at S=0
V(NAS, k) = 2 * V(NAS - 1, k) - V(NAS - 2, k) ' Boundary condition at S=infinity
Next k
Option_Value_3D = V ' Output array
End Function |
Partager