Hurst Exponent

All functions · nseries package

Hurst

func (s Series) Hurst(n int) Series

Hurst estimates the Hurst exponent from the rescaled range (R/S) of each trailing window of n values.

For each window it takes the deviations of the n values from the window mean and forms their cumulative sums. R is the range of those cumulative sums (maximum minus minimum), S is the population standard deviation of the window (divisor n, not n−1), and the result is H = ln(R / (S·√(π/2))) / ln n. Indices 0 to n−2 are 0, as are windows where S is 0 or R/S is not a positive number (a flat window, for example, or one containing a NaN or an infinity), and every index is 0 when n <= 1, n > len(s) or len(s) <= 1.

A window whose n values are all equal and finite gives exactly 0, whatever the rounding in its mean: the test is exact equality (==) with the latest value, never a tolerance, so -0 and +0 count as equal, and a window holding a NaN or an infinity is never flat. A window whose values differ by one ulp, or a genuine walk at a tiny magnitude, is not flat and is computed as above. Releases before this change gave about 0.86 to 0.94 on a flat window at most price levels (n = 10 to 50): the computed mean of ten copies of 0.1 is just below 0.1, so every deviation was the same tiny number and R/S came out near n−1.

The factor √(π/2) is the large-sample (Feller/Hurst) constant: for independent data, E[R/S] ≈ √(nπ/2) as n grows. It is not an Anis-Lloyd correction; HurstCorrected uses Anis and Lloyd’s exact expected value instead.

This is a single-scale estimate at window n only. The classical method computes R/S at several window sizes and takes H as the slope of the regression of log(R/S) on log(n); that regression is not provided.

Because the large-sample constant overstates E[R/S] at small n, Hurst is biased low on independent data: in simulation, white noise gives a mean H of about 0.373 at n = 10, 0.427 at n = 20, 0.461 at n = 50, 0.475 at n = 100 and 0.482 at n = 200, where 0.5 is expected. Use HurstCorrected for an estimate centred near 0.5.

R/S analysis is normally applied to increments rather than to levels: for prices, apply Hurst to returns, not to the prices themselves.

HurstCorrected

func (s Series) HurstCorrected(n int) Series

HurstCorrected estimates the Hurst exponent like Hurst but compares R/S with its exact expected value under independence (Anis and Lloyd, 1976) rather than the large-sample constant, which removes most of Hurst’s downward bias on independent data.

For each trailing window of n values, R (the range of the cumulative deviations from the window mean) and S (the population standard deviation, divisor n, as Hurst uses) are computed exactly as in Hurst, and the result is H = 0.5 + ln((R/S) / E(n)) / ln n, where E(n) = Γ((n−1)/2) / (√π·Γ(n/2)) · Σ √((n−r)/r), summed over r = 1 to n−1, is Anis and Lloyd’s (1976) exact expected R/S for independent normal values, as given by Peters, Fractal Market Analysis (1994), eq. 5.4. The gamma ratio is computed by its recurrence in steps of two, not from the gamma function (which overflows near n = 343), so E(n) is finite for every n. E(n) is computed once per call.

Where both are non-zero, HurstCorrected(n) − Hurst(n) at the same index equals, to rounding, the constant 0.5 + (ln √(π/2) − ln E(n)) / ln n: about 0.117574 at n = 10, 0.065156 at n = 20, 0.032202 at n = 50 and 0.012129 at n = 200.

On white noise HurstCorrected averages about 0.491 at n = 10, rising to 0.495 at n = 200. The small negative bias that remains comes from centring R/S rather than ln(R/S): by Jensen’s inequality, the mean of ln(R/S) is below ln E(n).

Peters’s Table A2.1 prints E(n)·(n − 0.5)/n: the factor (n − 0.5)/n is his empirical correction for the sample standard deviation, so the table’s values are E(n) times that factor, not E(n) itself.

The flat-window rule is Hurst’s too: a window whose n values are all equal and finite gives exactly 0, whatever the rounding in its mean. Releases before this change gave about 0.97 on such a window at most price levels (n = 10 to 50), for example ten copies of 0.1.

Guards, warm-up and zero cases are those of Hurst: indices 0 to n−2 are 0, as are windows where S is 0 or R/S is not a positive number, and every index is 0 when n <= 1, n > len(s) or len(s) <= 1. As with Hurst, this is a single-scale estimate at window n only, and R/S analysis is normally applied to increments (returns, for prices) rather than to levels.