# Function Op() As Double ReDim Op(N +

Function Price(Spot, K, T, r, sigma, N, OpType As String, ExType As String)dt = T / Nu = Exp(sigma * (dt ^ 0.5))d = 1 / uq = (Exp(r * dt) – d) / (u – d) Dim S() As DoubleReDim S(N + 1, N + 1) As DoubleFor i = 1 To N + 1 For j = i To N + 1 S(i, j) = Spot * u ^ (j – i) * d ^ (i – 1) Next jNext iDim Op() As DoubleReDim Op(N + 1, N + 1) As Double For i = 1 To N + 1Select 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 SelectNext iFor 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(-r * dt) * (q * Op(i, j + 1) + (1 – q) * Op(i + 1, j + 1))) ElseIf OpType = “P” Then Op(i, j) = Application.Max(K – S(i, j), Exp(-r * dt) * (q * Op(i, j + 1) + (1 – q) * Op(i + 1, j + 1))) End If Case “E”: Op(i, j) = Exp(-r * dt) * (q * Op(i, j + 1) + (1 – q) * Op(i + 1, j + 1)) End Select Next iNext jPrice = Op(1, 1)End Function

x

Hi!
I'm Owen!

Would you like to get a custom essay? How about receiving a customized one?

Check it out