200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > R/S方法计算Hurst指数

R/S方法计算Hurst指数

时间:2022-06-10 20:29:39

相关推荐

R/S方法计算Hurst指数

from __future__ import divisionfrom collections import Iterableimport numpy as np from pandas import Seriesimport xlrdfrom numpy import *def read_excel():# 打开文件workbook = xlrd.open_workbook(r'D:\shuju.xlsx')sheet = workbook.sheet_by_name('Sheet4')for i in range(100):list=[]for j in range(183):ctype = sheet.cell(j, i).ctype # 表格的数据类型cell = sheet.cell_value(j, i)if ctype == 2 and cell % 1 == 0.0: # ctype为2且为浮点cell = int(cell)list.append(cell)def calcHurst2(ts):if not isinstance(ts, Iterable):print('error')returnn_min, n_max = 2, len(ts)//3RSlist = []for cut in range(n_min, n_max):children = len(ts) // cutchildren_list = [ts[i*children:(i+1)*children] for i in range(cut)]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)if Sa ==0:rs = 0else:rs = Ra / SaL.append(rs)RS = np.mean(L)RSlist.append(RS)return np.polyfit(np.log(range(2+len(RSlist),2,-1)), np.log(RSlist), 1)[0]if __name__ == "__main__": print(calcHurst2(list))if __name__ == '__main__':read_excel()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。