|
Sub eltb()
spxmu = Range("f2:f71").Value
call_vol = Range("d2:d71").Value
put_vol = Range("e2:e71").Value
c90 = Range("i2:i71").Value
p10 = Range("j2:j71").Value
'Range("x1") = Val(p10(1, 1))
Dim etlm(1 To 70) As Double
For i = 1 To 70
sum = 0
n = 0
For j = 1 To 10000
temp_rp = RndNorm1(Val(spxmu(i, 1)), Val(put_vol(i, 1)) / 100)
If temp_rp < p10(i, 1) Then
sum = sum + temp_rp
n = n + 1
End If
Next j
etlm(i) = sum / n
Next i
Range("l2:l71") = Application.Transpose(etlm)
End Sub
Function RndNorm1(Mean As Double, Std As Double)
Dim V1 As Double, V2 As Double, r As Double
Do
V1 = 2 * Rnd - 1
V2 = 2 * Rnd - 1
r = V1 ^ 2 + V2 ^ 2
Loop Until r < 1
RndNorm1 = Mean + V2 * Sqr(-2 * Log(r) / r) * Std
End Function
运行时提示溢出,感觉应该是10000的循环那里出了问题,但是改了数据类型仍然不行,向高手求助!
|
|