期权的蒙特卡洛模拟

说明:本系列实验全部在优矿平台上进行。

import seaborn as sns
from CAL.PyCAL import *
import numpy as np
import scipy
spot = 2.45
strike = 2.50
maturity = 0.25
r = 0.05
vol = 0.25
def call_option_pricer_monte_carlo(spot,strike,maturity,r,vol,numOfPath=5000):
    randomSeries=scipy.random.randn(numOfPath)
    s_t=spot*np.exp((r-0.5*vol**2)*maturity+randomSeries*vol*np.sqrt(maturity))
    sumValue=np.maximum(s_t-strike,0.0).sum()
    price=np.exp(-r*maturity)*sumValue/numOfPath
    return price
print '期权价格(蒙特卡洛) : %.4f' % call_option_pricer_monte_carlo(spot, strike, maturity, r, vol)
pathScenario = range(1000, 50000, 1000)
numOfTrials = 100

confidenceIntervalUpper = []
confidenceIntervalLower = []
means = []
for scenario in pathScenario:
    res=np.zeros(numOfTrials)
    for i in range(numOfTrials):
        res[i]=call_option_pricer_monte_carlo(spot,strike,maturity,r,vol,numOfPath=scenario)
    means.append(res.mean())
    confidenceIntervalUpper.append(res.mean()+1.96*res.std())
    confidenceIntervalLower.append(res.mean()-1.96*res.std())
pylab.figure(figsize=(12,8))
table=np.array([means,confidenceIntervalUpper,confidenceIntervalLower]).T
pylab.plot(pathScenario,table)
pylab.title(u'期权蒙特卡洛模拟',fontproperties=font,fontsize=18)
pylab.legend([u'均值',u'95%置信区间上界',u'95%置信区间下界'],prop=font)
pylab.xlabel(u'模拟次数',fontproperties=font,fontsize=15)
pylab.ylabel(u'价格',fontproperties=font,fontsize=15)
pylab.grid(True)
Paste_Image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容