import numpy as np import matplotlib.pyplot as plt # 设置参数 T = 1.0 # 终止时间 N = 1000 # 时间步数 dt = T / N # 每一步的时间间隔 sigma = 0.2 # 波动率 S0 = 100 # 初始价格 # 生成布朗运动路径 t = np.linspace(0, T, N+1) # 时间点 W = np.random.randn(N) # 生成N个标准正态分布的随机数 W = np.insert(W, 0, 0) # 将初始值0插入到W的开头 W = np.cumsum(W) * np.sqrt(dt) # 计算布朗运动的累加和并乘以sqrt(dt) # 计算参考价格路径 S = S0 + sigma * W # 绘制参考价格变化 plt.figure(figsize=(10, 6)) plt.plot(t, S) plt.title('Reference Price Path') plt.xlabel('Time') plt.ylabel('Price') plt.grid(True) plt.show()