2
$\begingroup$

I am working on understanding the Hurst exponent calculation by Ernest Chan; however, the description of the algorithm does not match the Python implementation.

Chan [Algorithmic Trading: Winning Strategies and Their Rationale] outlines following steps for Hurst Exponent computation using R/S method:

β–ͺ Divides the time series of length 𝑁 into 2π‘˜ (π‘˜ = 0,1,2…) adjacent subperiods of the same length 𝑛, such that 2π‘˜ Γ— 𝑛 = 𝑁.

β–ͺ For each sub period of length 𝑛, a partial time series is created based on various subperiods, 𝑋 = 𝑋1,𝑋2,…𝑋𝑛.

β–ͺ Arithmetic mean (π‘₯Μ… = 1 𝑛 βˆ‘ 𝑋𝑖 𝑛 𝑖=1 ) is calculated and a new mean-adjusted series (π‘Œ 𝑑 = π‘₯𝑑 βˆ’ π‘₯Μ…) column is constructed.

β–ͺ Cumulated deviations from the arithmetic mean are noted in a new series (𝑍𝑑 = βˆ‘ π‘Œ 𝑑 𝑑 𝑑=1 ).

β–ͺ An adjusted range is calculated by 𝑅(𝑛) = max(𝑍1,𝑍2,…𝑍𝑛) βˆ’ min (𝑍1,𝑍2,…𝑍𝑛)

β–ͺ Standard deviation is computed 𝑆(𝑛) = √1 𝑛 βˆ‘ (𝑋𝑖 βˆ’ π‘₯Μ…)2 𝑛 𝑖=1

β–ͺ Each adjusted range 𝑅(𝑛) is then standardized by corresponding standard deviation 𝑆(𝑛), to form the rescaled range 𝑅(𝑛)/𝑆(𝑛)

β–ͺ An average rescaled range over all the partial time series of length 𝑛 is calculated The process is repeated iteratively using π‘˜ = 0,1,2… for each length 𝑛 = 𝑁/2π‘˜ of subperiods.

from numpy import *
from pylab import plot, show
# first, create an arbitrary time series, ts
ts = [0]
for i in range(1,100000):
    ts.append(ts[i-1]*1.0 + random.randn())
# calculate standard deviation of differenced series using various lags
lags = range(2, 20)
tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]
# plot on log-log scale
plot(log(lags), log(tau)); show()
# calculate Hurst as slope of log-log plot
m = polyfit(log(lags), log(tau), 1)
hurst = m[0]*2.0
print 'hurst = ',hurst

Could someone please explain the difference of the description and the implementation in case my math is not good enough? Or are these different ways to implement the Hurst expoenent?

$\endgroup$

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.