'=========================================================================
Public Function impVol(OptPrice As Double, S As Double, T As Double, x As Double, r As Double, Tol As Double) As Double
'=========================================================================
vol0 = impPutVol(0, S, T, x, r)
vol1 = impPutVol(OptPrice, S, T, x, r)
f0 = CrankN(vol0) - OptPrice
f1 = CrankN(vol1) - OptPrice
vol2 = vol1 - f1 * ((vol1 - vol0) / (f1 - f0))
f2 = CrankN(vol2) - OptPrice
Do While (f2 > Tol)
If f0 * f2 >= 0 Then
vol0 = vol2
f0 = CrankN(vol0) - OptPrice
Else
vol1 = vol2
f1 = CrankN(vol1) - OptPrice
End If
vol2 = vol1 - f1 * ((vol1 - vol0) / (f1 - f0))
f2 = CrankN(vol2) - OptPrice
Loop
impVol = vol2
End Function
'==============================
Function CrankN(v)
Dim m As Integer, n As Integer
Dim S As Double, k As Double, r As Double, T As Double
Dim dt As Double, ds As Double
Dim sMax As Double
Dim i As Single, j As Single
Dim pik As Variant
n = Range("NTimeSteps").Cells(1, 1)
m = Range("NPriceSteps").Cells(1, 1)
S = Range("Price").Cells(1, 1)
k = Range("Strike").Cells(1, 1)
r = Range("RFRate").Cells(1, 1)
T = Range("TMat").Cells(1, 1)
dt = T / n
sMax = Range("MaxUPrice").Cells(1, 1)
ds = sM

这是一个用VBA编写的公共函数,用于通过Secant方法和Crank Nicholson算法计算美式期权的隐含波动率。函数涉及了多个辅助函数,如CrankN、MartixTri、Itp等,它们共同完成数值求解过程,考虑了利率、期权价格、标的资产价格、期限等相关参数。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



