在做时间序列分析时,需要计算Hurst指数,由于Hurst指数计算比较复杂,刚开始懒得自己写,就在github上进行搜索,多是这个代码:
from numpy import std, subtract, polyfit, sqrt, log
def hurst(ts):
"""Returns the Hurst Exponent of the time series vector ts"""
# create the range of lag values
i = len(ts) // 2
lags = range(2, i)
# Calculate the array of the variances of the lagged differences
tau = [sqrt(std(subtract(ts[lag:], ts[:-lag]))) for lag