Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Exponential Moving Average in Pipeline (without talib)?

New to quantopian. How would I go about using an exponential moving average in a pipeline without using the talib library? I see this thread (https://www.quantopian.com/posts/how-to-add-exponential-weighted-moving-average-into-a-pipeline), but I'm not at all sure what value to use as the "decay rate" in order to get a result equal to a generic EMA.

Suppose we want a 21 day EMA:

ema_21 = ExponentialWeightedMovingAverage(
inputs=[USEquityPricing.close],
window_length=21,
decay_rate= ?,
)

Thanks for any help!

1 response

For anyone looking: the decay rate is the coefficient used to weight the previous bars in the E(W)MA calculation. It can be calculated as:

decay = 2 / (1 + N), where N is the window length in your MA.

So a 10-day EMA = decay of .18,
and a 50-day EMA = .04

(You might see research firms assume it to be .06, which is ~= 2/31, or the 30-day EMA)

You can put the calculation directly into your code instead of providing a decimal:

decay = 2 / (1 + window_length)  

If you'd like more, this helped me see how it's used: https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/M-N/MovAvgExponential