excel - 为什么我只在调试器中遇到溢出错误?
问题描述
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。
提前致谢。
解决方案
推荐阅读
- python - Is Iterable object in for statement checked(recalculated) everytime it runs?
- angular7 - `@ngrx/store` - createFeatureSelector 从未从包装器组件中调用
- android - 使用 onTouchEvent 缩放旋转和拖动位图
- vue.js - Vue-head 标题是两次
- wordpress - 在 wordpress 中显示产品目录不适用于电子商务
- c# - 控制台应用程序中的主机服务
- mysql - 如何使用输入参数搜索列并更新该列?
- c# - 插入具有一对零或一关系的对象时出错
- database - 存储产品多个计量单位的灵活解决方案
- c - 用户输入另一个数据时的数组放置