def hurst(ts):
# Create the range of lag values
window_len = 30
hurst_ts = np.zeros((0,), dtype=np.int)
for tail in range(window_len, len(ts)):
lags = range(1, window_len // 2)
# print(lags)
# Calculate the array of the variances of the lagged differences
cur_ts = ts[max(1, tail - window_len):tail]
# cur_ts = ts[:tail]
tau = [sqrt(std(subtract(cur_ts[lag:], cur_ts[:-lag]))) for lag in lags]
# print("Time series slice len: ",len(cur_ts),len(tau),lags)
# Use a linear fit to estimate the Hurst Exponent
poly = polyfit(log(lags), log(tau), 1)
# Return the Hurst exponent from the polyfit output
# print(poly[0]*2.0)
hurst_ts = np.append(hurst_ts, poly[0] * 2.0)
return hurst_ts
评论列表
文章目录