楼主: orochim44
4164 6

[问答] 请问如何用MATLAB计算大盘的HURST [推广有奖]

  • 0关注
  • 0粉丝

讲师

77%

还不是VIP/贵宾

-

威望
0
论坛币
99 个
通用积分
4.7570
学术水平
1 点
热心指数
2 点
信用等级
1 点
经验
521 点
帖子
433
精华
0
在线时间
463 小时
注册时间
2009-9-8
最后登录
2025-4-23

楼主
orochim44 在职认证  发表于 2012-5-17 20:37:58 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请问如何用MATLAB计算大盘的HURST指数?能给出详细的步骤吗?程序如下,说的详细点,谢谢!
很多人都想知道股市Hurst指数变化,但是股软没有这个功能,我自己找了一个hurst的函数工具,写了一个计算股市的,比较简单,可以实现对股市的hurst指数计算,发到这里共享一下,供抛砖引玉,希望理想的高手多多指点,这个程序有些问题,算出来的指数会大于1,我暂时没有办法,请高手多多指教。

使用的时候,注意参数n的调节,n大了曲线会比较平滑,i是开始计算日
r=x(3000:end,2);意思是取数据文件的第二列的大盘指数,从3000行开始。
999999.txt是数据文件,可以从通达信导出
程序在matlab2009下执行没有问题,别的不敢保证

附图可以这么看,hurst指数小于0.7时,行情将发生反转,逐渐增加时今天的行情对明天的行情影响增加,小于是反之,数据截止到昨天。
n取的是10,也就是10天的移动hurst指数
复制内容到剪贴板 代码:%
%clear;
tic;
x=load('999999.txt');
r=x(3000:end,2);
%r=zscore(r);
qishu=length(r);
n=12;
i=100;
h=zeros(qishu-1,1);
for i=i-n:qishu;
data=reshape(r(i-n+1:i,1),1,n);
%rs=polyfit(log10(i-n:i)',RSana(r,i-n:i,'Hurst',1),1);
rs=hurst_exponent(data);
h(i,1)=rs(:,1);
%h(i,1)=hurst_exponent(data);
end
subplot(2,1,1); plot(h(100:end,1))
grid on;
title('HURST指数')
subplot(2,1,2); plot(r(100:end,1))
title('上证指数')
hold on;
grid on;
toc;

以下的代码请保存为hurst_exponent.m
复制内容到剪贴板 代码:%Hurst 指数的计算
% The Hurst exponent
%--------------------------------------------------------------------------
% The first 20 lines of code are a small test driver.
% You can delete or comment out this part when you are done validating the
% function to your satisfaction.
%
% Bill Davidson, quellen@yahoo.com
% 13 Nov 2005

% function []=hurst_exponent()
% disp('testing Hurst calculation');
%
% % n=100;
% % data=rand(1,n);
% load gx.txt
% for n=1:967;
%     data(1,n)=sum(gx(n,2:7));
% end
% %data=reshape(data,1,967);
% plot(data);
%
% hurst=estimate_hurst_exponent(data);
%
% [s,err]=sprintf('Hurst exponent = %.2f',hurst);disp(s);

%--------------------------------------------------------------------------
% This function does dispersional analysis on a data series, then does a
% Matlab polyfit to a log-log plot to estimate the Hurst exponent of the
% series.
%
% This algorithm is far faster than a full-blown implementation of Hurst's
% algorithm.  I got the idea from a 2000 PhD dissertation by Hendrik J
% Blok, and I make no guarantees whatsoever about the rigor of this approach
% or the accuracy of results.  Use it at your own risk.
%
% Bill Davidson
% 21 Oct 2003

function [hurst] = hurst_exponent(data0)   % data set

data=data0;         % make a local copy

[M,npoints]=size(data0);

yvals=zeros(1,npoints);
xvals=zeros(1,npoints);
data2=zeros(1,npoints);

index=0;
binsize=1;

while npoints>4
   
    y=std(data);
    index=index+1;
    xvals(index)=binsize;
    yvals(index)=binsize*y;
   
    npoints=fix(npoints/2);
    binsize=binsize*2;
    for ipoints=1:npoints % average adjacent points in pairs
        data2(ipoints)=(data(2*ipoints)+data((2*ipoints)-1))*0.5;
    end
    data=data2(1:npoints);
   
end % while

xvals=xvals(1:index);
yvals=yvals(1:index);

logx=log(xvals);
logy=log(yvals);

p2=polyfit(logx,logy,1);
hurst=p2(1); % Hurst exponent is the slope of the linear fit of log-log plot

return;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB matla hurst atlab Urs 大盘 计算 如何

沙发
zhuqiandai2012 发表于 2012-5-17 20:47:25
用R直接调用就可以。。。。。。。。。。。。。。。。

藤椅
orochim44 在职认证  发表于 2012-5-17 23:19:49
zhuqiandai2012 发表于 2012-5-17 20:47
用R直接调用就可以。。。。。。。。。。。。。。。。
能说的再详细点吗?本人很菜的

板凳
orochim44 在职认证  发表于 2012-5-18 00:29:54
希望能够说的详细点

报纸
lanlingrd 学生认证  发表于 2016-1-19 17:08:37
计算出来的结果好像有问题 呢,有大于1的,是怎么处理的?

地板
matlab-007 发表于 2016-8-27 20:33:40
% The Hurst exponent
%--------------------------------------------------------------------------
% The first 20 lines of code are a small test driver.
% You can delete or comment out this part when you are done validating the
% function to your satisfaction.
%
% Bill Davidson,
% 13 Nov 2005

function []=hurst_exponent()
disp('testing Hurst calculation');

n=100;
data=rand(1,n);
plot(data);

hurst=estimate_hurst_exponent(data);

[s,err]=sprintf('Hurst exponent = %.2f',hurst);disp(s);

%--------------------------------------------------------------------------
% This function does dispersional analysis on a data series, then does a
% Matlab polyfit to a log-log plot to estimate the Hurst exponent of the
% series.
%
% This algorithm is far faster than a full-blown implementation of Hurst's
% algorithm.  I got the idea from a 2000 PhD dissertation by Hendrik J
% Blok, and I make no guarantees whatsoever about the rigor of this approach
% or the accuracy of results.  Use it at your own risk.
%
% Bill Davidson
% 21 Oct 2003

function [hurst] = estimate_hurst_exponent(data0)   % data set

data=data0;         % make a local copy

[M,npoints]=size(data0);

yvals=zeros(1,npoints);
xvals=zeros(1,npoints);
data2=zeros(1,npoints);

index=0;
binsize=1;

while npoints>4
   
    y=std(data);
    index=index+1;
    xvals(index)=binsize;
    yvals(index)=binsize*y;
   
    npoints=fix(npoints/2);
    binsize=binsize*2;
    for ipoints=1:npoints % average adjacent points in pairs
        data2(ipoints)=(data(2*ipoints)+data((2*ipoints)-1))*0.5;
    end
    data=data2(1:npoints);
   
end % while

xvals=xvals(1:index);
yvals=yvals(1:index);

logx=log(xvals);
logy=log(yvals);

p2=polyfit(logx,logy,1);
hurst=p2(1); % Hurst exponent is the slope of the linear fit of log-log plot

return;

7
scutyy 发表于 2016-8-28 16:46:05 来自手机
orochim44 发表于 2012-5-17 20:37
请问如何用MATLAB计算大盘的HURST指数?能给出详细的步骤吗?程序如下,说的详细点,谢谢!
很多人都想知道 ...
hurst指数是什么?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-2 17:08