欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-03-20 14:46:52
...
#编写hurst指数
from numpy import std, subtract, polyfit, sqrt, log
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
from datetime import timedelta
from statsmodels import regression
from 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 hhh
namelist=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)

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

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