|
Trinomial Model - Generalized VBA code -
Issued on June 04 2011 par Strategies Options
Trinomial model using VBA code
I - VBA Code
Public Function TT(CallPutFlag As String, S As Double, X As Double, T As Double, r As Double, b As Double, v As Double, n As Integer) As Variant
Dim OptionValue() As Double
ReDim OptionValue(0 To n * 2 + 1)
Dim dt As Double, u As Double, d As Double
Dim pu As Double, pd As Double, pm As Double, Df As Double
Dim i As Long, j As Long, z As Integer
If CallPutFlag = "c" Then
z = 1
ElseIf CallPutFlag = "p" Then
z = -1
End If
dt = T / n
u = Exp(v * Sqr(2 * dt))
d = Exp(-v * Sqr(2 * dt))
pu = ((Exp(b * dt / 2) - Exp(-v * Sqr(dt / 2))) / (Exp(v * Sqr(dt / 2)) - Exp(-v * Sqr(dt / 2)))) ^ 2
pd = ((Exp(v * Sqr(dt / 2)) - Exp(b * dt / 2)) / (Exp(v * Sqr(dt / 2)) - Exp(-v * Sqr(dt / 2)))) ^ 2
pm = 1 - pu - pd
Df = Exp(-r * dt)
For i = 0 To (2 * n)
OptionValue(i) = Application.Max(0, z * (S * u ^ Application.Max(i - n, 0) * d ^ Application.Max(n - i, 0) - X))
Next
For j = n - 1 To 0 Step -1
For i = 0 To (j * 2)
OptionValue(i) = (pu * OptionValue(i + 2) + pm * OptionValue(i + 1) + pd * OptionValue(i)) * Df
If AmeEurFlag = "a" Then
OptionValue(i) = Application.Max(z * (S * u ^ Application.Max(i - j, 0) * d ^ Application.Max(j - i, 0) - X), OptionValue(i))
End If
Next
Next
TT = OptionValue(0)
End Function
II - Examples
To derive the value of a call, with no dividend, just open a spreadsheet and put the formula :
"=TT(c;100;110;1;0.05;0.05;0.30;200)"
To get the value of
- a call (c)
- with a spot at 100
- a strike of 110
- a maturité of 1 year
- with annualized continuously compounded interest rate of 0.05 (5%)
- a cost of carry of 0.05 ( This is interest rate minus dividend rate, hence 0.05-0)
- using an implied annualized volatility of 0.3 (30%)
- derived with 200 steps
The outcome is then 10.02051
For a european style put with an annualized dividend rate of 0.03% thsi is
"=TT(p;100;110;1;0.05;0.02;0.30;250)"
To get the value of a
- put (p)
- with a spot at100
- a strike set at 110
- a maturity of 1 year
- using an annualized interest rate of 0.05 (5%)
- thus a cost of carry of 0.02 ( this is 0.05-0.03)
- an an annualized implied volatility of
0.3 (30%)
- for 250 steps
This leads to a put value of 16.1981
Next : Black & Scholes : A First Attempt
Previous : Trinomial Model: American Style In Tree - Let's Price With It !
OPTIONS PRICING MODEL - INDEX
OPTIONS PRICING MODEL - INDEX
OPTIONS PRICING MODEL - CHAPTER I
OPTIONS PRICING MODEL - CHAPTER II
OPTIONS PRICING MODEL - CHAPTER III Strategies Options
|
|