user7616021
user7616021

Reputation:

Exponential Weighted Moving Average using Pandas

I need to confirm few thing related to pandas exponential weighted moving average function.

If I have a data set df for which I need to find a 12 day exponential moving average, would the method below be correct.

exp_12=df.ewm(span=20,min_period=12,adjust=False).mean()

Given the data set contains 20 readings the span (Total number of values) should equal to 20.

Since I need to find a 12 day moving average hence min_period=12. I interpret span as total number of values in a data set or the total time covered.

Can someone confirm if my above interpretation is correct? I can't get the significance of adjust.

I've attached the link to pandas.df.ewm documentation below.

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ewm.html

Upvotes: 11

Views: 26299

Answers (1)

spin_cycle
spin_cycle

Reputation: 141

Quoting from Pandas docs: Span corresponds to what is commonly called an “N-day EW moving average”.

In your case, set span=12. You do not need to specify that you have 20 datapoints, pandas takes care of that. min_period may not be required here.

Upvotes: 14

Related Questions