[英]python: calculating exponential moving average
While calculating a simple moving average is as simple as the following:虽然计算简单的移动平均线很简单,但如下所示:
MAs = closes.rolling(window=MAsWin).mean()
I cannot really find out how to calculate the exponential moving average.我真的不知道如何计算指数移动平均线。 I tried many variations of the following but without luck:
我尝试了以下许多变体,但没有运气:
MAs = closes.rolling(window= MAsWin, win_type='exponential').mean(std=0.1)
Any help is appreciated.任何帮助表示赞赏。 Thank you.
谢谢你。
I used pandas to calculate EMA.我使用 pandas 来计算 EMA。 Here is the documentation of EMA function in pandas library https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.ewma.html And down below there is a similar problem, hope it helps You a bit calculate exponential moving average in python
Here is the documentation of EMA function in pandas library https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.ewma.html And down below there is a similar problem, hope it helps You有点计算 python 中的指数移动平均线
Try with pd.DataFrame.ewm
:尝试使用
pd.DataFrame.ewm
:
MAs = closes.ewm(span=MAsWin, adjust=False).mean()
Ref https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.ewm.html参考https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.ewm.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.