ブラックショールズモデルを使ってヨーロピアンオプションを計算するpythonコード
コード
import numpy as np from scipy import stats def bs_model(S,x,r,sigma,T): d1 = (np.log(S/x) + (r + 0.5 * sigma ** 2)*T)/(sigma*pow(T, 1/2)) d2 = (np.log(S/x) + (r - 0.5 * sigma ** 2)*T)/(sigma*pow(T, 1/2)) call = S * stats.norm.cdf(d1) - x * np.exp(-r*T) * stats.norm.cdf(d2) put = x * np.exp(-r*T) * stats.norm.cdf(-d2) - S * stats.norm.cdf(-d1) return call,put
bs_model(50, 50, 0.1, 0.5, 0.5) (8.131599054232979, 5.693070279268685)