我有以下代码,但出现以下错误:(
Compile error, variable not found
它无法找到 j)此外,即使我提供 MktVol 作为长度为 4 的向量,消息框也会返回N=0
Can you please help me fix my error。
Public Function EstimateAllParameters(params, MktStrike, MktVol, F, T, b)
Dim R As Double, a As Double, V As Double, N As Integer
Dim j as integer 'stops the compile error but the function returns #VALUE!
Dim ModelVol() As Double, sqdError() As Double
R = params(1)
V = params(2)
a = params(3)
N = MktVol.Length
MsgBox ("N= " & N)
For j = 1 To N
ModelVol(j) = Svol(a, b, R, V, F, MktStrike(j), T)
sqdError(j) = (ModelVol(j) - MktVol(j)) ^ 2
Next j
EstimateAllParameters = Sum(sqdError)
End Function
MktStrike
在单元格 E5:E8 中具有以下值
12
13
14
15
并MktVol
在单元格 F5:F8 中具有以下值
0.234
0.236
0.242
0.249