python-33品种随机游走检验

来源:互联网 发布:linux oracle em 启动 编辑:程序博客网 时间:2024/04/20 09:07
# -*- coding: utf-8 -*-"""Created on Thu Jun 22 17:03:16 2017@author: yunjinqi  E-mail:yunjinqi@qq.com  Differentiate yourself in the world from anyone else."""import pandas as pdimport numpy as npimport matplotlib.pyplot as pltimport statsmodels.tsa.stattools as tsimport statsmodels.api as smfrom statsmodels.graphics.api import qqplotfrom statsmodels.sandbox.stats.runs import runstest_1sampnamelist=['cu','al','zn','pb','sn','au','ag','rb','hc','bu','ru','m9','y9','a9',              'p9','c9','cs','jd','l9','v9','pp','j9','jm','i9','sr','cf',              'zc','fg','ta','ma','oi','rm','sm']j=0for i in namelist:        filename='C:/Users/HXWD/Desktop/数据/'+i+'.csv'    data=pd.read_csv(filename,encoding='gbk')    data.columns=['date','open','high','low','close','amt','opi']    data.head()    data=np.log(data['close'])    r=data-data.shift(1)    r=r.dropna()    #print(r)    x = np.array(r)    x[x>=0]=1    x[x<0]=0    t=runstest_1samp(x)    if abs(t[0])<1.96 and t[1]>0.05:        print('{}该收益序列属于随机游走'.format(i))

结果:

sn该收益序列属于随机游走
rb该收益序列属于随机游走
hc该收益序列属于随机游走
cs该收益序列属于随机游走
jd该收益序列属于随机游走
l9该收益序列属于随机游走
pp该收益序列属于随机游走
j9该收益序列属于随机游走
jm该收益序列属于随机游走
i9该收益序列属于随机游走
zc该收益序列属于随机游走
ta该收益序列属于随机游走
ma该收益序列属于随机游走
oi该收益序列属于随机游走
rm该收益序列属于随机游走
sm该收益序列属于随机游走

原创粉丝点击