用 pandas 计算指数移动平均线

编程入门 行业动态 更新时间:2024-10-27 08:38:19
本文介绍了用 pandas 计算指数移动平均线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试用大熊猫计算ema,但结果不好. 我尝试了两种技术来计算:

I try to calculate ema with pandas but the result is not good. I try 2 techniques to calculate :

第一种技术是熊猫函数ewn:

The first technique is the panda's function ewn:

window = 100 c = 2 / float(window + 1) df['100ema'] = df['close'].ewm(com=c).mean()

但是此函数的最后结果给出了. 2695.4,但实际结果是2656.2

But the last result of this function gives. 2695.4 but the real result is 2656.2

第二种技术是

window = 100 c = 2 / float(window + 1) df['100sma'] = df['close'].rolling(window).mean() df['100ema'] = (c * df['close']) + ((1 - c) * df['100sma'])

结果是2649.1,它比第一种技术更近,但总是不好

The result is 2649.1 it's closer than first technique but is always not good

sma函数给出了很好的结果

The sma function give the good result

**编辑**

响应为

df['100ema'] = pd.Series.ewm(df['close'], span=window).mean()

推荐答案

如果要计算EWMA或Python中的任何技术指标,建议使用 ta-lib .

If you want to calculate EWMA or any technical indicator in Python, I recommend using ta-lib.

更多推荐

用 pandas 计算指数移动平均线

本文发布于:2023-10-15 02:25:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:平均   指数   pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!