% The Hirst 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
% Function to your satisfaction.
%
% Bill David son, quellen@yahoo.com
% 13 Nov 2005
Function [] = hurst_exponent ()
Disp ('testing hustash calculation ');
N = 100;
Data = rand (1, N );
Plot (data );
Hirst = estimate_hurst_exponent (data );
[S, err] = sprintf ('hirst exponent = %. 2f ', hust'); disp (s );
% --------------------------------------------------------------------------
% This function does dispermissionanalysis on a data series, then does
% MATLAB polyfit to a log-log plot to estimate the Hirst exponent of
% Series.
%
% This algorithm is far faster than a full-blown Implementation of hurlsh's
% Algorithm. I got the idea from a 2000 PhD dissertation by Henderson Rik 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 David son
% 21 (Oct 2003)
Function [Hirst] = 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 );
Urst = P2 (1); % urst exponent is the slope of the Linear Fit of log-log plot
Return;