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

本文介绍了一种用于评估金融市场数据随机性的方法——Hurst指数,并通过Python代码展示了如何计算该指数并将其应用于期货市场数据的分析中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#编写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)

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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云金杞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值