0

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.

mtrw
  • 34,200
  • 7
  • 63
  • 71
megapixel
  • 53
  • 4

2 Answers2

1

I used pandas to calculate 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

Franciszek Job
  • 388
  • 2
  • 9
1

Try with 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

Grzegorz Skibinski
  • 12,624
  • 2
  • 11
  • 34