python模拟B-S期权定价模型

随机变量模拟

在当前股票指数水平S0给定的情况下,未来某个日期T的股票指数水平ST可以根据Black-Scholes-Merton公式模拟:
S_{T}=S_{0}*exp((r-0.5 \sigma^{^{2}})T+\sigma \sqrt{T}z)

r :无风险利率
σ :S的恒定波动率(= 收益率的标准差)
z:标准正态分布随机变量

#通过 standard_normal模拟几何布朗运动,随机变量呈对数正态分布
S0 = 100  
r = 0.05  
sigma = 0.25  
T = 2.0  
I = 10000  
ST1 = S0 * np.exp((r - 0.5 * sigma ** 2) * T +
        sigma * math.sqrt(T) * npr.standard_normal(I))  

#如果使用 lognormal 函数直接得出随机变量值,必须向函数提供均值和标准差,通过 lognormal模拟几何布朗运动:
ST2 = S0 * npr.lognormal((r - 0.5 * sigma ** 2) * T,
                        sigma * math.sqrt(T), size=I)  

#使用 scipy.stats子库和 print_statistics 比较模拟结果的分布特性
import scipy.stats as scs
def print_statistics(a1, a2):
    """
    Print selected statistics
    """
    sta1 = scs.describe(a1)
    sta2 = scs.describe(a2)
    print('%14s %14s %14s' % ('statistic', 'data set 1', 'data set 2'))
    print(45 * '-')
    print('%14s %14.3f %14.3f' % ('size', sta1[0], sta2[0]))
    print('%14s %14.3f %14.3f' % ('min', sta1[1][0], sta2[1][0]))
    print('%14s %14.3f %14.3f' % ('max', sta1[1][1], sta2[1][1]))
    print('%14s %14.3f %14.3f' % ('mean', sta1[2], sta2[2]))
    print('%14s %14.3f %14.3f' % ('std', np.sqrt(sta1[3]), np.sqrt(sta2[3])))
    print('%14s %14.3f %14.3f' % ('skew', sta1[4], sta2[4]))
    print('%14s %14.3f %1

你可能感兴趣的:(quant)