' Calculates European or American option prices using the Cox, Ross, Rubinstein binomial lattice ' Spot = Spot Price of the underlying ' K = Strike Price ' T = Option Maturity in Years ' rf = Interest Rate in decimal (i.e, for 5%, use 0.05) ' vol = Yearly volatility of the underlying in decimal ' n = Number of time steps ' OpType = 'C' for Call and 'P' for Put ' ExType = 'A' for American and 'E' for European Option Base 1 Function CRRTree(Spot, K, T, rf, vol, n, OpType As String, ExType As String) dt = T / n u = Exp(vol * (dt ^ 0.5)) d = 1 / u p = (Exp(rf * dt) - d) / (u - d) ' Tree for stock price Dim S() As Double ReDim S(n + 1, n + 1) As Double For i = 1 To n + 1 For j = i To n + 1 S(i, j) = Spot * u ^ (j - i) * d ^ (i - 1) Next j Next i ' Calculate Terminal Price for Calls and Puts Dim Op() As Double ReDim Op(n + 1, n + 1) As Double For i = 1 To n + 1 Select Case OpType Case "C": Op(i, n + 1) = Application.Max(S(i, n + 1) - K, 0) Case "P": Op(i, n + 1) = Application.Max(K - S(i, n + 1), 0) End Select Next i ' Calculate Remaining entries for Calls and Puts For j = n To 1 Step -1 For i = 1 To j Select Case ExType Case "A": If OpType = "C" Then Op(i, j) = Application.Max(S(i, j) - K, Exp(-rf * dt) * (p * Op(i, j + 1) + (1 - p) * Op(i + 1, j + 1))) ElseIf OpType = "P" Then Op(i, j) = Application.Max(K - S(i, j), Exp(-rf * dt) * (p * Op(i, j + 1) + (1 - p) * Op(i + 1, j + 1))) End If Case "E": Op(i, j) = Exp(-rf * dt) * (p * Op(i, j + 1) + (1 - p) * Op(i + 1, j + 1)) End Select Next i Next j CRRTree = Op(1, 1) End Function