打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
考夫曼自适应均线(python源代码)
userphoto

2022.11.06 浙江

关注
#!/usr/bin/env python# -*- coding: utf-8 -*-import pandas as pdimport numpy as npdef KAMA(series:pd.Series, cyc:int=10, fastest:int=2, slowest:int=30)->np.float64: '''考夫曼自适应均线指标函数 series: 接受 pandas 的 Series 格式的数值 cyc: int 指定数据的计算周期 fastest: int 快线 slowest: int 慢线 输出值: np.float64 例程:kama = KAMA(series.close, cyc=10, fastest=2, slowest=30)''' length = series.shape[0] if length >= cyc: direction = (series.shift(cyc - 1) - series).abs() #价格方向 volatility = series.diff(1).abs().rolling(cyc - 1).sum() #波动幅度 efficiency_ratio = direction / volatility #效率系数 fastest_ratio, slowest_ratio = 2 / (fastest + 1), 2 / (slowest + 1) #快线/慢线系数 smooth = (efficiency_ratio * (fastest_ratio - slowest_ratio) + slowest_ratio) ** 2 #平滑系数 ama_array = np.zeros(length) first_value = True for i in range(length): if smooth[i] != smooth[i]: ama_array[i] = np.nan else: if first_value: ama_array[i] = series[i] first_value = False else: ama_array[i] = ama_array[i - 1] + smooth[i] * (series[i] - ama_array[i - 1]) return ama_array return Exception('错误警告:考夫曼自适应均线指标函数中传入的数据量不足!')
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
AMA考夫曼自适应移动平均线
两个有意思的指标:ATR和AMA
通达信考夫曼自适应均线指标公式和原理详解
經典交易策略解說
100 Fastest
【学习笔记】python实现excel数据处理
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服