#include <rescaled_range.h>
Inheritance diagram for rescaled_range::
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... |
Definition at line 15 of file rescaled_range.h.
|
Calculate the rescaled range for a single region of data.
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 |
|
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.
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_ |
|
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.
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 |
|
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_ |