用Python模拟Black Scholes期权定价模型 发表于 2026-08-05 | 分类于 Finance | 评论数: 本文字数: 8.7k | 阅读时长 ≈ 8 分钟 理论模型 代码1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465# Black-Scholes Put Option Price Simulationimport numpy as npimport matplotlib.pyplot as pltfrom scipy.stats import norm# 参数S0 = 40mu = 0.05sigma = 0.25K = 40T = 1r = 0.05 # 此处采用风险中性假设,即无风险利率 r = muN = 252 * 10 # 一年交易日dt = T / N# 时间轴t = np.linspace(0, T, N)# 模拟股价路径np.random.seed(99) # 随机数种子使结果可复现Z = np.random.normal(0, 1, N)S = np.zeros(N)S[0] = S0for i in range(1, N): S[i] = S[i-1] * np.exp((mu - 0.5 * sigma**2) * dt + sigma * np.sqrt(dt) * Z[i])# Black-Scholes 看跌期权def put_option_price(S, K, T, t, r, sigma): tau = T - t tau = np.maximum(tau, 1e-8) # 防止除零 d1 = (np.log(S / K) + (r + 0.5 * sigma**2) * tau) / (sigma * np.sqrt(tau)) d2 = d1 - sigma * np.sqrt(tau) P = K * np.exp(-r * tau) * norm.cdf(-d2) - S * norm.cdf(-d1) return P# 计算期权路径P = put_option_price(S, K, T, t, r, sigma)# 绘图fig, ax1 = plt.subplots(figsize=(10,6))ax1.plot(t, S, color='blue', linewidth=2, label='Stock Price')ax1.set_xlabel('Time')ax1.set_ylabel('Stock Price S', color='blue')ax1.tick_params(axis='y', labelcolor='blue')ax2 = ax1.twinx()ax2.plot(t, P, color='red', linestyle='--', linewidth=2, label='Put Option Price')ax2.set_ylabel('Put Option Price P', color='red')ax2.tick_params(axis='y', labelcolor='red')lines1, labels1 = ax1.get_legend_handles_labels()lines2, labels2 = ax2.get_legend_handles_labels()ax1.legend(lines1 + lines2, labels1 + labels2, loc='upper right')plt.title('GBM Stock Price and Black-Scholes Put Option Price')plt.grid(True, alpha=0.3)plt.tight_layout()plt.show() 运行结果上述代码的运行结果如下图所示: 打赏 微信支付 支付宝