Function CRRTree(Spot, K, T, r, sigma, N, OpType As String, ExType As String)

dt = T / N

u = Exp(sigma * (dt ^ 0.5))

d = 1 / u

q = (Exp(r * dt) – d) / (u – d)

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

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

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(-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 i

Next j

CRRTree = Op(1, 1)

End Function

Function CRRTree_Barrier(Spot, H, K, T, r, sigma, N, OpType As String)

dt = T / N

u = Exp(sigma * (dt ^ 0.5))

d = 1 / u

q = (Exp(r * dt) – d) / (u – d)

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

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

For j = N To 1 Step -1

For i = 1 To j

If OpType = “C” And S(i, j) > H Then

Op(i, j) = Exp(-r * dt) * (q * Op(i, j + 1) + (1 – q) * Op(i + 1, j + 1))

ElseIf S(i, j) H Then

Op(i, j) = Exp(-r * dt) * (q * Op(i, j + 1) + (1 – q) * Op(i + 1, j + 1))

ElseIf S(i, j)