Hurst指数python实现

 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 

 

转载于:https://www.cnblogs.com/ningjing213/p/10745772.html

你可能感兴趣的:(python)