📄 fugit_binomialtree.txt
字号:
Function fugit(ByVal spot As Double, ByVal strike As Double, _
ByVal timetomaturity As Double, ByVal risk_free As Double, _
ByVal vol As Double, ByVal class As String, _
ByVal n As Integer) As Double
Dim price() As Double 'option price tree
Dim fugitarray() As Double 'fugit tree
Dim S() As Double 'stock price tree
Dim dt As Double 'time step in the tree
Dim u As Double, d As Double 'binomial tree parameters
Dim Pu As Double, Pd As Double
Dim pv As Double 'discount factor
Dim I As Integer 'running counter through the nodes
Dim j As Integer 'running counter through the time step
Dim Arraysize As Integer 'Size of array for the asset and option price tree
Dim C_P As Integer 'to indicate the option is call or put
' N is defined as integer and overflow will occur if 365 is not considered is double
dt = timetomaturity / n
pv = Exp(-risk_free * dt)
Arraysize = n + 1
'the default is a call option, unless a "p" is given to indicate put option
If class = "p" Then
C_P = -1
Else
C_P = 1
End If
' the stock price S move to S*u and S*d in the next time step of the tree
' u and d and probability of going up or down are calculated in the following
' This is the standard Cox - Rubinstein tree setup
u = Exp(vol * dt ^ (1 / 2))
d = 1 / u
Pu = (Exp(risk_free * dt) - d) / (u - d)
Pd = 1 - Pu
ReDim price(Arraysize)
ReDim fugitarray(Arraysize)
ReDim S(Arraysize)
' initialise asset prices at maturity step N
S(0) = spot * (d ^ n)
For I = 1 To n
S(I) = S(I - 1) * u / d
Next I
' initialise option values at maturity
For I = 0 To n
price(I) = Application.WorksheetFunction.Max(0#, C_P * S(I) - C_P * strike)
fugitarray(I) = 0
Next I
' stepping back the tree and applying the early exercie condition
For j = n - 1 To 0 Step -1
For I = 0 To j
price(I) = pv * (Pu * price(I + 1) + Pd * price(I))
S(I) = S(I) * u
If price(I) > (C_P * S(I) - C_P * strike) Then
fugitarray(I) = (Pu * fugitarray(I + 1) + Pd * fugitarray(I)) + dt
Else
fugitarray(I) = 0
End If
Next I
Next j
fugit = fugitarray(0)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -