Hurst指数

理论参考: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]

猜你喜欢

转载自blog.csdn.net/weixin_43055882/article/details/86622527