期權(quán)的蒙特卡洛模擬

說明:本系列實驗全部在優(yōu)礦平臺上進行。

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 '期權(quán)價格(蒙特卡洛) : %.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'期權(quán)蒙特卡洛模擬',fontproperties=font,fontsize=18)
pylab.legend([u'均值',u'95%置信區(qū)間上界',u'95%置信區(qū)間下界'],prop=font)
pylab.xlabel(u'模擬次數(shù)',fontproperties=font,fontsize=15)
pylab.ylabel(u'價格',fontproperties=font,fontsize=15)
pylab.grid(True)
Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容