Exponential Weighted Moving Average using Pandas
Asked Answered
T

1

11

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

Tissue answered 25/2, 2017 at 11:8 Comment(2)
Your min_period=12 param should be min_periods=12 according to the docs you linked.Secluded
2 answers here : #49522007Bullough
V
14

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.

Vincenty answered 25/5, 2017 at 3:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.