VBA BS期权定价:为什么会出现编译错误?

时间:2019-05-12 13:35:57

标签: excel vba

我正在尝试使用此VBA代码为美国或欧洲期权定价...但是我遇到了

  

“编译错误:找不到项目或库”

,突出显示dt =T/n。 我无法确定出什么问题了。希望有人比我能指出我所忽略的东西。

 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

0 个答案:

没有答案