二项式欧式期权定价模型

时间:2015-06-03 12:48:33

标签: excel vba excel-vba

我使用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

以下是电子表格的布局:

enter image description here

当我运行程序时,发生了错误。

enter image description here

enter image description here

有人可以在这里解释我的程序有什么问题以及如何解决它?

2 个答案:

答案 0 :(得分:1)

您收到溢出错误。如果您查看工作表:

COMBIN(5000, 161) = 3.3E+307
COMBIN(5000, 162) = #NUM!

COMBIN(5000, 4838) = #NUM!
COMBIN(5000, 4839) = 3.3E+307

请记住,组合的数量呈指数级增长,直到它开始以反向速率下降的中间点。

答案 1 :(得分:1)

你的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。

不那么敏感