理论参考:http://www.360doc.com/content/16/0409/15/20041187_549224354.shtml
代码实现:
def calcHurst2(x):
if not isinstance(x,Iterable):
print(‘error’)
return
n_min,n_max=2,len(x)//3
RSlist=[]
n=[]
for cut in range(n_min,n_max):#cut:片的大小
children=len(x)//cut #children为子区间的大小
children_list=[x[i*children:(i+1)*children] for i in range(cut)]#分片
n.append(children)
L=[]
for a_children in children_list:
Ma=np.mean(a_children)
Xta=Series(map(lambda x:x-Ma,a_children)).cumsum() #累计离差
Ra=max(Xta)-min(Xta)
sa=np.std(a_children)
rs=Ra/sa
L.append(rs)
RS=np.mean(L)
RSlist.append(RS)
return np.polyfit(np.log(n),np.log(RSlist),1)[0]
可以用我的邀请链接注册tushare:https://tushare.pro/register?reg=231214
三 解读:
解读来源:https://wenku.baidu.com/view/247a1eb0fd0a79563c1e72c0.html