Skip to content

Instantly share code, notes, and snippets.

@TsaiKoga
Created June 2, 2018 09:53
Show Gist options
  • Save TsaiKoga/979ab7975c5b787a5e1192b379a05e5c to your computer and use it in GitHub Desktop.
Save TsaiKoga/979ab7975c5b787a5e1192b379a05e5c to your computer and use it in GitHub Desktop.
Return the Hurst Exponent of the time series vector ts
def hurst(ts):
"""
Return the Hurst Exponent of the time series vector ts
"""
# Create the range of lag values
lags = range(2, 100)
# Calculate the array of the variance of the lagged differences
tau = [sqrt(std(substract(ts[lag:], ts[:-lag]))) for lag in lags]
# Use linear fit to estimate the Hurst Exponent
poly = polyfit(log(lags), log(tau), 1)
# Return Hurst exponent from polyfit output
return poly[0]*2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment