基础统计代码实现

基础统计代码实现

def print_statics(array):
    sta=scs.describe(array)
    print("%14s %15s" %('statistic','value'))
    print(30*"_")
    print ("%14s %15.5f" % ('size',sta[0]))
    print("%14s %15.5f" % ('min',sta[1][0]))
    print("%14s %15.5f" % ('max',sta[1][1]))
    print("%14s %15.5f" % ('mean',sta[2]))
    print("%14s %15.5f" % ('std',np.sqrt(sta[3])))
    print("%14s %15.5f" % ('skew',sta[4]))
    print("%14s %15.5f" % ('kurtosis',sta[5]))

print_statics(log_returns.flatten())

plt.hist(log_returns.flatten(),bins=70,density=True,label='frequency')
plt.grid(True)
plt.xlabel('log-return')
plt.ylabel('frequency')
x=np.linspace(plt.axis()[0],plt.axis()[1])
plt.plot(x,scs.norm.pdf(x,loc=r/M,scale=sigma/np.sqrt(M)),'r',lw=2.0,label='pdf')
plt.legend()

sm.qqplot(log_returns.flatten()[::500],line='s')
plt.grid(True)
plt.xlabel('theoretical quantiles')
plt.ylabel('sample quantiles')

©️2020 CSDN 皮肤主题: 游动-白 设计师:上身试试 返回首页