Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to Handle Large Initial Computations

Hi all,
I'm quite new to Quantopian, so I don't know all the tips and tricks. I'm writing an algo that uses about two years of historical data to prep before trading. Unfortunately, this takes a while. I would have liked to put it in initialize(), but I need the history function, so I create a method that's called on a schedule and put a flag so it only runs once. However, I often see an error complaining the handle_data is taking too long. Is there a way around this?
Thanks,
Aaron

2 responses

Hi Aaron, please use this Timing Code to verify the culprit, I would like to know the average.
If it is history(), would someone from Q please let us know the ETA on your work in speeding up history().
If that is a ways out, I have a workaround that takes quite a few lines and isn't exactly elegant nor vetted by others. It pulls the full history first time, then only appends last bar each bar and trims to given length. I'm not sure that's what's up here, so let's be sure, do verify, thanks.

before_trading_start() has a 5 min time-out. It may not support history() though, in which case you'd have to store a copy of your trailing window in context and do your computation on the second day of the backtest (or live trading run).