Created
June 2, 2018 09:53
-
-
Save TsaiKoga/979ab7975c5b787a5e1192b379a05e5c to your computer and use it in GitHub Desktop.
Return the Hurst Exponent of the time series vector ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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