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

简介: python-优矿-hurst指数与期货33品种的预测
#编写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)

image.png


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


目录
相关文章
|
4月前
|
数据挖掘 Python
【视频】随机波动率SV模型原理和Python对标普SP500股票指数预测|数据分享
【视频】随机波动率SV模型原理和Python对标普SP500股票指数预测|数据分享
|
2月前
|
Python
指数平滑法详解与Python代码示例
指数平滑法详解与Python代码示例
|
3月前
|
Python
|
4月前
|
机器学习/深度学习 数据采集 数据可视化
python用回归、arima、随机森林、GARCH模型分析国债期货波动性、收益率、价格预测
python用回归、arima、随机森林、GARCH模型分析国债期货波动性、收益率、价格预测
|
4月前
|
Python
Python随机波动率(SV)模型对标普500指数时间序列波动性预测
Python随机波动率(SV)模型对标普500指数时间序列波动性预测
|
4月前
|
算法 数据库 索引
Python时间序列选择波动率预测指数收益算法分析案例
Python时间序列选择波动率预测指数收益算法分析案例
Python时间序列选择波动率预测指数收益算法分析案例
|
4月前
|
资源调度 数据可视化 Python
Python随机波动模型Stochastic volatility,SV随机变分推断SVI分析标普500指数时间数据波动性可视化
Python随机波动模型Stochastic volatility,SV随机变分推断SVI分析标普500指数时间数据波动性可视化
|
4月前
|
机器学习/深度学习 算法 数据挖掘
【视频】Python基于SVM和RankGauss的低消费指数构建模型
【视频】Python基于SVM和RankGauss的低消费指数构建模型
|
4月前
|
机器学习/深度学习 数据可视化 TensorFlow
Python中TensorFlow的长短期记忆神经网络(LSTM)、指数移动平均法预测股票市场和可视化
Python中TensorFlow的长短期记忆神经网络(LSTM)、指数移动平均法预测股票市场和可视化
|
4月前
|
机器学习/深度学习 数据可视化 TensorFlow
Python中TensorFlow的长短期记忆神经网络(LSTM)、指数移动平均法预测股票市场和可视化2
Python中TensorFlow的长短期记忆神经网络(LSTM)、指数移动平均法预测股票市场和可视化