megapixel
megapixel

Reputation: 53

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.

Upvotes: 0

Views: 992

Answers (2)

Georgina Skibinski
Georgina Skibinski

Reputation: 13387

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

Upvotes: 1

Franciszek Job
Franciszek Job

Reputation: 388

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

Upvotes: 1

Related Questions