首页 > 解决方案 > 为什么我只在调试器中遇到溢出错误?

问题描述

Sub backsolve_straddle()
    Dim f_x As Double
    Dim dydx As Double
    Dim d1 As Double
    Dim d2 As Double
    Dim N_d1 As Double
    Dim N_d2 As Double
    Dim spot As Double
    Dim strike As Double
    Dim vol As Double
    Dim r As Double
    Dim tenor As Double
    Dim prem As Double
    Dim ea As Double
    Dim xr As Double
    Dim xi As Double
    Dim N_d1_neg As Double
    Dim N_d2_neg As Double
 
    spot = Worksheets("Straddle").Cells(3, 9)
    tenor = Worksheets("Straddle").Cells(5, 9)
    vol = Worksheets("Straddle").Cells(6, 9)
    r = Worksheets("Straddle").Cells(7, 9)
    prem = Worksheets("Straddle").Cells(8, 9)
    xi = Worksheets("Straddle").Cells(3, 11)
 
    ea = 100
    Do While ea > 1
        d1 = (Application.WorksheetFunction.Ln(spot / xi) + (tenor * (r + (vol ^ 2 / 2)))) / (vol * (tenor ^ 0.5))
        d2 = d1 - (vol * (tenor ^ 0.5))
        N_d1 = Application.WorksheetFunction.Norm_S_Dist(d1, True)
        N_d2 = Application.WorksheetFunction.Norm_S_Dist(d2, True)
        N_d1_neg = Application.WorksheetFunction.Norm_S_Dist(-d1, True)
        N_d2_neg = Application.WorksheetFunction.Norm_S_Dist(-d2, True)
        
        f_x = spot * N_d1 - (xi * Exp(-r * tenor) * N_d2) + (xi * Exp(-r * tenor) * N_d2_neg) - (spot * N_d1_neg) - prem
        dydx = N_d1 - N_d1_neg
        
        xr = xi - (f_x / dydx)
        ea = Abs((xr - xi) / xr)
        xi = xr
    Loop
    Worksheets("Straddle").Cells(4, 9) = xr
 End Sub

在代码行之后出现溢出错误Do While。本质上,我正在使用调试器,当我进入Do While循环时,我得到一个溢出错误。但是,当我在代码末尾添加断点并跳到该点运行代码时,我没有收到此错误。谁能指导我为什么?如果有区别,我在 Mac 上使用 Excel VBA。

提前致谢。

标签: excelvba

解决方案


推荐阅读