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 38 39 40 41
|
Function tri_nom(S As Double, K As Double, rf As Double, sigma As Double, T As Double, n As Integer) As Double
Dim q_up As Double, q_down As Double, q_m As Double
Dim u As Double, d As Double, m As Double
Dim optionPrice As Variant, assetPrice As Variant
Dim dt As Double
Dim r As Double
Dim i As Integer, j As Integer
dt = T / n
'les coefficients de variation du sous jacent durant delta t
u = Exp(sigma * (2 * dt) ^ (0.5))
d = Exp(-sigma * (2 * dt) ^ (0.5))
m = 1
r = Exp(-rf * dt)
'probabilité neutre au risque
q_up = ((Exp(rf * dt / 2) - Exp(-sigma * Sqr(dt / 2))) / (Exp(sigma * Sqr(dt / 2)) - Exp(-sigma * Sqr(dt / 2)))) ^ 2
q_down = ((Math.Exp(sigma * Sqr(dt / 2)) - Exp(rf * dt / 2)) / (Exp(sigma * Sqr(dt / 2)) - Exp(-sigma * Sqr(dt / 2)))) ^ 2
q_m = 1 - q_up - q_down
'on calcul les prix du dernier états du sous jacent à la date de maturité.
ReDim optionPrice(2 * n + 1)
optionPrice(0) = Application.WorksheetFunction.Max(0, S * WorksheetFunction.Power(u, n) - K)
For i = 0 To n * 2
optionPrice(i) = Application.WorksheetFunction.Max(0, S * WorksheetFunction.Power(u, WorksheetFunction.Max((i - n), 0)) * WorksheetFunction.Power(d, WorksheetFunction.Max(n - i, 0)) - K)
Next i
'fonction backward
'Selon les la position dans le temps j
'selon l'état du monde i
For j = n - 1 To 0 Step -1
For i = 0 To (j * 2)
optionPrice(i) = r * (q_up * optionPrice(i + 2) + q_m * optionPrice(i + 1) + q_down * optionPrice(i))
Next i
Next j
tri_nom = optionPrice(0)
End Function |
Partager