Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

rescaled_range Class Reference

Estimate the hurst exponent using the rescaled range technique. More...

#include <rescaled_range.h>

Inheritance diagram for rescaled_range::

hurst_base List of all members.

Public Methods

void calc_hurst_est (const double *v, const size_t N, hurst_base::hurstInfo &info)
 Estimate the Hurst exponent using the rescale range calculation. More...


Private Methods

double calc_mean_ (const double *v, const size_t N)
 Calculate the mean (average). More...

double calc_RS_ (const double *v, const size_t N)
 Calculate the rescaled range for a single region of data. More...

double calc_RS_ave_ (const double *v, const size_t N, const size_t box_size)
 Calculate the R/S Average for the R/S values calculated on a set of "boxes" (regions) of size boxSize. More...


Detailed Description

Estimate the hurst exponent using the rescaled range technique.

Definition at line 15 of file rescaled_range.h.


Member Function Documentation

double rescaled_range::calc_RS_ ( const double * v,
const size_t N ) [private]
 

Calculate the rescaled range for a single region of data.

  • v a pointer to the start of the data region.
  • boxSize the size of the region (or box).

Definition at line 29 of file rescaled_range.cpp.

Referenced by calc_RS_ave_().

00031 {
00032   double RS = 0.0;
00033   if (v != 0 && boxSize > 0) {
00034     double min;
00035     double max;
00036     double runningSum;
00037     double runningSumSqr;
00038 
00039     double mean = calc_mean_( v, boxSize );
00040 
00041     min = 0.0;
00042     max = 0.0;
00043     runningSum = 0.0;
00044     runningSumSqr = 0.0;
00045     for (size_t i = 0; i < boxSize; i++) {
00046       double devFromMean = v[i] - mean;
00047       runningSum = runningSum + devFromMean;
00048       runningSumSqr = runningSumSqr + (devFromMean * devFromMean);
00049       if (runningSum < min)
00050         min = runningSum;
00051       if (runningSum > max)
00052         max = runningSum;
00053     }
00054     double variance = runningSumSqr / static_cast<double>(boxSize);
00055     double stdDev = sqrt( variance );
00056 
00057     double range = max - min;
00058     RS = range / stdDev;
00059   }
00060   
00061   return RS;
00062 } // calc_RS

double rescaled_range::calc_RS_ave_ ( const double * v,
const size_t N,
const size_t box_size ) [private]
 

Calculate the R/S Average for the R/S values calculated on a set of "boxes" (regions) of size boxSize.

This code is based on the assumption that boxSize is an integral multiple of N, the size of the array v.

  • v the data set used to estimate the Hurst exponent
  • N the size of the data set
  • boxSize the size of the region on which the R/S calculation is performed. The R/S average is the average of the calculation on the set of regions.

Definition at line 81 of file rescaled_range.cpp.

Referenced by calc_hurst_est().

00084 {
00085   size_t i;
00086   double stdDev;
00087   double range;
00088   double RS;
00089   double RSSum;
00090   double mean;
00091   double RSAve = 0.0;
00092 
00093   size_t numBoxes = N / boxSize; 
00094   if (numBoxes > 0) {
00095     RSSum = 0;
00096     for (i = 0; i+boxSize <= N; i = i + boxSize) {
00097       const double *boxStart = &v[i];
00098       RS = calc_RS_( boxStart, boxSize );
00099       RSSum = RSSum + RS;
00100     } // for i
00101 
00102     RSAve = RSSum / static_cast<double>( numBoxes );
00103   }
00104   
00105   return RSAve;
00106 } // calc_RS_ave_

void rescaled_range::calc_hurst_est ( const double * v,
const size_t N,
hurst_base::hurstInfo & info )
 

Estimate the Hurst exponent using the rescale range calculation.

The average rescaled range is calculated on a set of regions (sometimes referred to as "boxes") which are, in this case, a power of two in size (e.g., 8, 16, 32, ...). The data set on which the Hurst exponent is estimated should be a power of two as well, so that there are an integral number of "boxes".

The log (base 2) of the RSAve is paired with the log of the region size to for a point. A set of points is used to calculate a linear regression line. The slope of this line is the estimate for the Hurst exponent.

  • v The data set on which the R/S calculation will be performed.
  • N The size of the data set.
  • info a reference variable which is returned with the information from the regression calculation (e.g., slope, error of slope, etc).

Definition at line 136 of file rescaled_range.cpp.

Referenced by wave_hurst::test(), and hurst_stocks::test().

00139 {
00140 
00141   double hurstEst = 0.0;
00142 
00143   if (v != 0 && N > 0) {
00144     const size_t minBox = 8;
00145 
00146     (info.points()).clear();
00147     size_t boxSize;
00148     for (boxSize = N; boxSize >= minBox; boxSize = (boxSize >> 1)) {
00149       double RSAve = calc_RS_ave_( v, N, boxSize );
00150       double logRSAve = log2( RSAve );
00151       double logBoxSize = log2( boxSize );
00152       (info.points()).push_back( lregress::point( logBoxSize, logRSAve ) );
00153     }
00154 
00155     // print_regression_points( info.points() );
00156 
00157     lregress lr;
00158 
00159     lregress::lineInfo lineInfo;
00160     lr.lr( info.points(), lineInfo );
00161 
00162     double slope = lineInfo.slope();
00163     double intercept = lineInfo.intercept();
00164     double slopeError = lineInfo.slopeErr();
00165 
00166     info.slope( slope );
00167     info.slopeErr( slopeError );
00168     info.intercept( intercept );
00169 
00170     // printf("slope = %7.4f +- %7.4f, intercept = %7.4f\n", 
00171     // slope, slopeError, intercept );
00172   }
00173   
00174 } // calc_hurst_est

double rescaled_range::calc_mean_ ( const double * v,
const size_t N ) [private]
 

Calculate the mean (average).

Definition at line 10 of file rescaled_range.cpp.

Referenced by calc_RS_().

00011 {
00012   double sum = 0.0;
00013 
00014   for (size_t i = 0; i < N; i++) {
00015     sum = sum + v[i];
00016   }
00017   double mean = sum / N;
00018   return mean;
00019 } // calc_mean_


The documentation for this class was generated from the following files:
Generated at Thu May 22 21:12:35 2003 for Hurst Exponent Calculation and Supporting Statistics by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001