码迷,mamicode.com
首页 > 编程语言 > 详细

python-期权定价

时间:2016-01-05 22:42:11      阅读:1645      评论:0      收藏:0      [点我收藏+]

标签:

 1 from math import log,sqrt,exp
 2 from scipy import stats
 3 
 4 def bsm_call_value(S0,K,T,r,sigma):
 5     S0 = float(S0)
 6     d1 = (log(S0 / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
 7     d2 = (log(S0 / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
 8     value = (S0 * stats.norm.cdf(d1,0.0,1.0) - K * exp(-r * T) * stats.norm.cdf(d2,0.0,1.0))
 9     print value
10     return value
11 
12 def bsm_vega(S0,K,T,r,sigma):
13     S0 = float(S0)
14     d1 = (log(S0 / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * sqrt(T))
15     vega = S0 * stats.norm.cdf(d1,0.0,1.0) * sqrt(T)
16     return vega
17 
18 def bsm_call_imp_vol(S0,K,T,r,C0,sigma_est,it = 100):
19     for i in range(it):
20         sigma_est -= ((bsm_call_value(S0,K,T,r,sigma_est) - C0) / bsm_vega(S0,K,T,r,sigma_est))
21     print sigma_est
22     return sigma_est
23 
24 S0 = 100
25 K = 105
26 T = 1.0
27 r = 0.05
28 sigma = 0.2
29 bsm_call_value(S0,K,T,r,sigma)

 

python-期权定价

标签:

原文地址:http://www.cnblogs.com/wn19910213/p/5103819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!