我使用VBA创建了一个程序来计算欧洲看涨期权价格,如下所示:
Private Sub CallPrice_Click()
Dim K As Single
Dim So As Single
Dim r As Single
Dim T As Single
Dim sigma As Single
Dim u As Single
Dim d As Single
Dim p As Single
Dim CP As Single
Dim M As Single
Dim S As Single
Dim CB As Double
Dim n As Integer
Dim i As Integer
K = Cells(2, 2)
So = Cells(3, 2)
r = Cells(4, 2)
T = Cells(5, 2)
sigma = Cells(6, 2)
n = Cells(7, 2)
u = Exp(sigma * Sqr(T / n))
d = 1 / u
p = (Exp(r * T / n) - d) / (u - d)
CP = 0
For i = 0 To n Step 1
M = WorksheetFunction.Max(So * (u ^ i) * d ^ (n - i) - K, 0)
CB = WorksheetFunction.Combin(n, i)
S = M * CB * (p ^ n) * (1 - p) ^ (n - i)
CP = CP + S
Next i
Cells(9, 2) = CP / (1 + r) ^ n
End Sub
以下是电子表格的布局:
当我运行程序时,发生了错误.
有人可以在这里解释我的程序有什么问题以及如何解决它?
最佳答案 你的S等式是否正确?它似乎应该是:
S = M * CB * (p ^ i) ...
代替
S = M * CB * (p ^ n) ...
如果你的等式确实是错误的,那么你可以使用BINOMDIST而不是COMBIN,因为根据定义:
Binom_Dist(i, n, p, False) = (p ^ i) * (1 - p) ^ (n - i) * Combin(n, i)
所以你的代码是:
S = M * WorksheetFunction.Binom_Dist(i, n, p, False)
代替
CB = WorksheetFunction.Combin(n, i)
S = M * CB * (p ^ n) * (1 - p) ^ (n - i)
BINOMDIST对大n不敏感,i.