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

  • Your `min_period=12` param should be `min_periods=12` according to the docs you linked. – ajHurliman Jul 02 '19 at 04:50
  • 2 answers here : https://stackoverflow.com/questions/49521507/compute-only-the-last-exponential-weighted-moving-average-pandas/75495234#75495234 – Laurent B. Feb 18 '23 at 17:50

1 Answers1

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.

spin_cycle
  • 141
  • 1
  • 3