声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2189|回复: 3

[分形与混沌] 请教:HURST指数计算问题

[复制链接]
发表于 2009-8-12 11:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
小弟为MATLAB的小菜菜鸟,请假各位前辈。
我在计算HURST指数的时候,发现使用同样数据我的方法计算出来的与其他人有很大差距,别人大致在0.6左右,而我的只是在0.3左右。望前辈指教问题之所在。
coef=polyfit(log(20:length(x))',RSana(x,20:length(x),'Hurst',1),1)

相关RS程序如下:
function [logRS,logERS,V]=RSana(x,n,method,q)
if nargin<1 | isempty(x)==1
   error('You should provide a time series.');
else
   % x must be a vector
   if min(size(x))>1
      error('Invalid time series.');
   end
   x=x(:);
   % N is the time series length
   N=length(x);
end

if nargin<2 | isempty(n)==1
   n=1;
else
   % n must be either a scalar or a vector
   if min(size(n))>1
      error('n must be either a scalar or a vector.');
   end
   % n must be integer
   if n-round(n)~=0
       error('n must be integer.');
   end
   % n must be positive
   if n<=0
      error('n must be positive.');
   end
end

if nargin<4 | isempty(q)==1
   q=0;
else
    if q=='auto'
        t=autocorr(x,1);
        t=t(2);
        q=((3*N/2)^(1/3))*(2*t/(1-t^2))^(2/3);
    else
        % q must be a scalar
        if sum(size(q))>2
            error('q must be scalar.');
        end
        % q must be integer
        if q-round(q)~=0
            error('q must be integer.');
        end
        % q must be positive
        if q<0
            error('q must be positive.');
        end
    end
end


for i=1:length(n)
   
    % Calculate the sub-periods
    a=floor(N/n(i));
   
    % Make the sub-periods matrix
    X=reshape(x(1:a*n(i)),n(i),a);
   
    % Estimate the mean of each sub-period
    ave=mean(X);
   
    % Remove the mean from each sub-period
    cumdev=X-ones(n(i),1)*ave;
   
    % Estimate the cumulative deviation from the mean
    cumdev=cumsum(cumdev);
   
    % Estimate the standard deviation
    switch method
    case 'Hurst'
        % Hurst-Mandelbrot variation
        stdev=std(X);
    case 'Lo'
        % Lo variation
        for j=1:a
            sq=0;
            for k=0:q
                v(k+1)=sum(X(k+1:n(i),j)'*X(1:n(i)-k,j))/(n(i)-1);
                if k>0
                    sq=sq+(1-k/(q+1))*v(k+1);
                end
            end
            stdev(j)=sqrt(v(1)+2*sq);
        end
    case 'MW'
        % Moody-Wu variation
        for j=1:a
            sq1=0;
            sq2=0;
            for k=0:q
                v(k+1)=sum(X(k+1:n(i),j)'*X(1:n(i)-k,j))/(n(i)-1);
                if k>0
                    sq1=sq1+(1-k/(q+1))*(n(i)-k)/n(i)/n(i);
                    sq2=sq2+(1-k/(q+1))*v(k+1);
                end
            end
            stdev(j)=sqrt((1+2*sq1)*v(1)+2*sq2);
        end
    case 'Parzen'
        % Parzen variation
        if mod(q,2)~=0
            error('For the "Parzen" variation q must be dived by 2.');
        end
        for j=1:a
            sq1=0;
            sq2=0;
            for k=0:q
                v(k+1)=sum(X(k+1:n(i),j)'*X(1:n(i)-k,j))/(n(i)-1);
                if k>0 & k<=q/2
                    sq1=sq1+(1-6*(k/q)^2+6*(k/q)^3)*v(k+1);
                elseif k>0 & k>q/2
                    sq2=sq2+(1-(k/q)^3)*v(k+1);
                end
            end
            stdev(j)=sqrt(v(1)+2*sq1+2*sq2);
        end
    otherwise
        error('You should provide another value for "method".');
    end
   
    % Estiamte the rescaled range
    rs=(max(cumdev)-min(cumdev))./stdev;
   
    clear stdev
   
    % Take the logarithm of the mean R/S
    logRS(i,1)=log10(mean(rs));
   
    if nargout>1
        
        % Initial calculations fro the log(E(R/S))
        j=1:n(i)-1;
        s=sqrt((n(i)-j)./j);
        s=sum(s);
        
        % The estimation of log(E(R/S))
        logERS(i,1)=log10(s/sqrt(n(i)*pi/2));
        
        % Other estimations of log(E(R/S))
        %logERS(i,1)=log10((n(i)-0.5)/n(i)*s/sqrt(n(i)*pi/2));
        %logERS(i,1)=log10(sqrt(n(i)*pi/2));
        
    end
   
    if nargout>2
        % Estimate V
        V(i,1)=mean(rs)/sqrt(n(i));
    end

end
回复
分享到:

使用道具 举报

 楼主| 发表于 2009-8-12 11:37 | 显示全部楼层
在使用数据时,我使用过指数的对数收益率,也使用过对数收益率AR(1)的残差,但都是跟别人差距很大,望前辈指教。
发表于 2013-12-16 10:07 | 显示全部楼层
求RS代码过程的解释?
发表于 2014-2-13 17:25 | 显示全部楼层
yejian111222 发表于 2009-8-12 11:37
在使用数据时,我使用过指数的对数收益率,也使用过对数收益率AR(1)的残差,但都是跟别人差距很大,望前辈 ...

你比没比较过你的算法和别人的有什么区别?
还是你没有拿到别人的程序,只有别人的结果?

你的程序比较长,估计很少有人会帮你逐步分析
最好找一个现成的程序,逐步比较过程量,看问题出在哪里
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-19 03:05 , Processed in 0.218548 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表