# -*- 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 pd import numpy as np import matplotlib.pyplot as plt import statsmodels.tsa.stattools as ts import statsmodels.api as sm from statsmodels.graphics.api import qqplot from statsmodels.sandbox.stats.runs import runstest_1samp namelist=['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=0 for 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该收益序列属于随机游走