这是以前算Hurst指数的,其中binMethod是指用数据长度的约数分组、还是用所有不大于长度一半的数分组
function [H,RS,V]=hurst(data,binMethod)
%function: compute hurst component:H, R/S and respect bin length-n:RS, V statistics
%input: data: column vector
% binMethod: scalar numer,group methods for data,0 for "divisor"/1 for "all"
%output: H:1*1 value,hurst component
% RS:N*2 matrix, column1: bin length, column2: RS
% V:V statistics
% to be done: indivisual test
% R/S analysis requires time series has no self correlation
obsNum=length(data);
if binMethod==0
tmp=divisor(obsNum);
n=tmp(tmp>=2 & tmp<=obsNum/2);
elseif binMethod==1
n=2:floor(obsNum/2);
else
error('binMethod should be ''divisor'' or ''all''');
end
RS=zeros(length(n),2);
RS(:,1)=n;
for ii=1:length(n)
binLength=n(ii);
bins=floor(obsNum/binLength);
binData=reshape(data((end-bins*binLength+1):end),binLength,bins);
binMean=mean(binData);
binStd=std(binData,1);
cumDev=cumsum(binData-repmat(binMean,binLength,1));
R=max(cumDev)-min(cumDev);
RS(ii,2)=mean(R./binStd);
end
coef=regress(log(RS(:,2)),[ones(size(RS,1),1) log(RS(:,1))]);
H=coef(2);
V=RS(:,2)./sqrt(RS(:,1));
end
|