正态性检验-基准情形
import numpy as np
np.random.seed(1000)
import scipy.stats as scs
import statsmodels.api as sm
import matplotlib.pyplot as plt
%matplotlib inline
def gen_paths(S0,r,sigma,T,M,I):
dt = float(T)/M
paths=np.zeros((M+1,I),np.float64)
paths[0]=S0
for t in range(1,M+1):
rand=np.random.standard_normal(I)
rand=(rand-rand.mean())/rand.std()
paths[t]=paths[t-1]np.exp((r-0.5sigma**2)dt+sigmanp.sqrt(dt)*rand)
return paths
S0=100.
r=0.05
sigma=0.2
T=1.0
M=50
I=250000
paths=gen_paths(S0,r,sigma,T,M,I)
plt.plot(paths[:,:10])
plt.grid(True)
plt.xlabel(‘Time Steps’)
plt.ylabel(‘Index level’)