赫斯特指数(Hurst Exponent)是一个用于描述时间序列数据的长期依赖性和自相似性的统计指标。它最初由英国水文学家哈罗德·埃德温·赫斯特(Harold Edwin Hurst)在研究尼罗河水位变化时提出。赫斯特指数的取值范围在0到1之间,其具体意义如下:
- H = 0.5:表示时间序列是随机游走的,即没有长期依赖性,类似于白噪声。
- H < 0.5:表示时间序列具有反持久性(anti-persistent behavior),即未来的趋势倾向于与过去的趋势相反。
- H > 0.5:表示时间序列具有持久性(persistent behavior),即未来的趋势倾向于与过去的趋势相同。
赫斯特指数在金融市场、地质学、气象学等领域中被广泛应用,用于分析和预测时间序列数据的行为特征。通过计算赫斯特指数,可以帮助识别数据的趋势和波动特性,从而为决策提供依据。
import numpy as np
import pandas as pd
def hurst(ts):
"""Returns the Hurst Exponent of the time series vector ts"""
# Create the range of lag values
lags = range(2, 100)
# Calculate the array of the variances of the lagged differences
tau = [np.sqrt(np.std(np.subtract(ts[lag:], ts[:-lag]))) for lag in lags]
# Use a linear fit to estimate the Hurst Exponent
poly = np.polyfit(np.log(lags), np.log(tau), 1)
# Return the Hurst exponent from the polyfit output
return poly[0]*2.0
# Example usage
if __name__ == "__main__":
# Create a random time series
ts = np.random.randn(1000)
print("Hurst Exponent:", hurst(ts))
防止自己写的代码有bug,可以直接用现成的开源方案,github上有一个现成的项目可以用。
Github Hurst Repo
