Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trying to understand data.history with regard to EMA calculations

I've been struggling with this. I've posted a very simple algo with the same EMA calculation but feeding it different history data and getting different results. My question is, why does it matter how big my data length is if I give my EMA calculation the number it needs or more? I assumed that even if my history data length was 300 but I needed 150 I was giving it the same data that I had if my history data length was 150...the most recent 150 data points. Thanks for any comments on this.

3 responses

Exponentially weighted calculations will use as much data as you give them. It's intrinsic to their formulae.

John,

EMA in terms of digital signal processing is IIR (Infinite Impulse Response Filter).
Its value depends on starting value of filtered data.
If starting point are the same the results will be the same , if not then not.
In your case emaMIN1 will have the starting point EMA for previous 150 min not the price as emaMIN2.
If you feed the same data points

minutes1 = data.history(context.XIV, 'price', 300, frequency ='1m')[-151:-1]  

you will get same results:

2016-06-10 handle_data:12 INFO EMA2 = 29.8756933333
2016-06-10 handle_data:9 INFO EMA1 = 29.8756933333
2016-06-10 handle_data:12 INFO EMA2 = 29.8690933333
2016-06-10 handle_data:9 INFO EMA1 = 29.8690933333
2016-06-10 handle_data:12 INFO EMA2 = 29.8626333333
2016-06-10 handle_data:9 INFO EMA1 = 29.8626333333
2016-06-10 handle_data:12 INFO EMA2 = 29.8564333333
2016-06-10 handle_data:9 INFO EMA1 = 29.8564333333

Thank you. Now it makes sense.