1 def Hurst(data): 2 n = 6 3 data = pd.Series(data).pct_change()[1:] 4 ARS = list() 5 lag = list() 6 for i in range(n): 7 m = 2 ** i 8 size = np.size(data) // m 9 lag.append(size) 10 panel = {} 11 for j in range(m): 12 panel[str(j)] = data[j*size:(j+1)*size].values 13 14 panel = pd.DataFrame(panel) 15 mean = panel.mean() 16 Deviation = (panel - mean).cumsum() 17 maxi = Deviation.max() 18 mini = Deviation.min() 19 sigma = panel.std() 20 RS = maxi - mini 21 RS = RS / sigma 22 ARS.append(RS.mean()) 23 24 lag = np.log10(lag) 25 ARS = np.log10(ARS) 26 hurst_exponent = np.polyfit(lag, ARS, 1) 27 hurst = hurst_exponent[0] 28 29 return hurst
注意:Hurst指数描述的记忆性仅对线性过程有效;对于复杂非线性过程,其记忆性需要除Hurst指数之外的其他参数来描述(Kamenshchikov 2014)。而投资品价格和收益率变化是非线性过程。