计算指数移动平均线

计算指数移动平均线

本文介绍了用 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 计算指数移动平均线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 21:54