python-优矿-hurst指数与期货33品种的预测

来源:互联网 发布:怎么取消淘宝退款申请 编辑:程序博客网 时间:2024/04/27 17:34
#编写hurst指数from numpy import std, subtract, polyfit, sqrt, logimport numpy as npimport pandas as pdfrom matplotlib import pyplot as pltfrom datetime import timedeltafrom statsmodels import regressionfrom lib.hurst import *#data=DataAPI.MktIdxdGet(tradeDate=u"",indexID=u"",ticker=u"000300",beginDate=u"",endDate=u"",exchangeCD=u"XSHE,XSHG",field=u"",pandas="1")['closeIndex'][-1500:]#data=DataAPI.MktEqudGet(tradeDate=u"",secID=u"",ticker=u"000001",beginDate=u"",endDate=u"",isOpen="",field=u"",pandas="1")['closePrice'][-1500:]def get_hurst(data):        #data=data[-500:]        #data.index=range(len(data))        hhh=[]        for i in range(len(data)):             if i>220  :                    new_data=data[i-220:i]                    hhh.append(hurst(new_data,5))        #hhh=pd.Series(hhh)        #ma1_hhh=hhh.rolling(1).mean()        #ma5_hhh=hhh.rolling(20).mean()        #ma20_hhh=hhh.rolling(100).mean()        #plt.plot(ma1_hhh)        #plt.plot(ma5_hhh)        #plt.plot(ma20_hhh)        #plt.show()        fig,ax1=plt.subplots()        data=data[221:]        data.index=range(len(data))        data.plot(figsize=(10,4),color='red',linewidth=1)        plt.grid(True)        plt.ylabel("Index")        plt.axis('tight')        ax2=ax1.twinx()        hhh=pd.Series(hhh)        ma1_hhh=hhh.rolling(1).mean()        ma5_hhh=hhh.rolling(20).mean()        ma20_hhh=hhh.rolling(100).mean()        ma1_hhh.plot(figsize=(10,4),color='black',linewidth=1,marker='.')        ma5_hhh.plot(figsize=(10,4),color='green',linewidth=1,marker='.')        ma20_hhh.plot(figsize=(10,4),color='blue',linewidth=1,marker='.')        plt.grid(True)        plt.ylabel('Hurst Index')        plt.axis('tight')        plt.show()        return hhhnamelist=list_files(path='./期货指数')for i in namelist:    filename='./期货指数/'+i    data=pd.read_csv(filename,encoding='gbk')    data=data.ix[::,4]    print i[:2]     get_hurst(data)

计算hurst指数对期货品种的效果,如果仅仅从hurst=0.5的角度看,随机游走的很少。大部分时间应该介于均值回归或者趋势中。下次用随机游走检验,adf检验下期货品种的有效性

原创粉丝点击