Exponential Moving Average Pandas vs Ta-lib

I am currently writing code containing some financial calculations. In particular, some exponential moving average. To do this work, I tried Pandas and Talib:

talib_ex=pd.Series(talib.EMA(self.PriceAdjusted.values,timeperiod=200),self.PriceAdjusted.index) pandas_ex=self.PriceAdjusted.ewm(span=200,adjust=True,min_periods=200-1).mean() 

Both of them work fine, but at the beginning of the array they give different results:

200 days EMA - Talib vs Pandas

So, is there some kind of parameter to change in Pandas EWMA, or is it a mistake, and should I worry?

Thank you in advance

Luke

+5
source share
1 answer

For Taliban ema formula:

Therefore, when you use pandas, if you want to make pandas ema the same as the Taliban, you should use it like:

pandas_ex = self.PriceAdjusted.ewm (range = 200, adjust = False , min_periods = 200-1) .mean ()

Set the False parameter to the value according to the document ( https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.ewm.html ) if you want to use the same formula as talib:

When set to True (default), weighted average values ​​are calculated using weights (1-alpha) (n-1), (1-alpha) (n-2), ..., 1-alpha, 1.

When setting False, the weighted average values ​​are calculated recursively, as: weighted_average [0] = arg [0]; weighted_average [i] = (1-alpha) weighted_average [i-1] + alphaarg [i].

You can also link here: https://en.wikipedia.org/wiki/Moving_average

PS: however, in my project I still find some slight differences between the Taliban and pandas.ewm and I don’t know why else ...

+3
source

Source: https://habr.com/ru/post/1269973/


All Articles