Merge pull request #671 from tesla1060/master

black formula was incorrect.
This commit is contained in:
vn.py 2018-01-05 09:30:34 +08:00 committed by GitHub
commit 5b92888b6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,10 +46,10 @@ def calculatePrice(f, k, r, t, v, cp):
# 如果波动率为0则直接返回期权空间价值 # 如果波动率为0则直接返回期权空间价值
if v <= 0: if v <= 0:
return max(0, cp * (f - k)) return max(0, cp * (f - k))
d1 = (log(f / k) + (0.5 * pow(v, 2) + r) * t) / (v * sqrt(t)) d1 = (log(f / k) + (0.5 * pow(v, 2)) * t) / (v * sqrt(t))
d2 = d1 - v * sqrt(t) d2 = d1 - v * sqrt(t)
price = cp * (f * cdf(cp * d1) - k * cdf(cp * d2) * exp(-r * t)) price = cp * (f * cdf(cp * d1) - k * cdf(cp * d2)) * exp(-r * t)
return price return price
#---------------------------------------------------------------------- #----------------------------------------------------------------------