I am trying to test Hurst exponent in different time lag range. However, i got negative values in some time lag range which is weird, because the Hurst exponent should have values within the range from 0 to 1.
This is the Python code to calculate the Hurst exponent:
*calculate Hurst*
lag1 = 2
lags = range(lag1, 20)
tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag in lags]
plot(log(lags), log(tau)); show()
m = polyfit(log(lags), log(tau), 1)
hurst = m[0]*2
print 'hurst = ',hurst
When lags = range(200,300)
, the Hurst exponent is -0.035. My data length is 1643. The log-log plot looks like this, which is not linear:
Is there something wrong with the code or anyone know any good package to test hurst exponent in R or python?