Hi Pravin,
I agree that there should be a facility to allow for longer calculations as I run into this situation quite a lot (since most of my strategies are of the "brute-force" variety). Although it's a bit tedious, what I do (as a work-around) is look to spread the calculation over many minutes by using calls to
handle_data()
and storing the intermediate results in context
. This works well for a calculation with a large outer loop (i.e. iterating through prior days or many securities/pairs) that can be segmented "cleanly" at around 45 second boundaries (to stay well within the 50 second handle_data()
timeout). You can use time.clock()
to know when to break during each iteration.
Using this method has a few caveats:
- May not be possible to trade during the first N minutes of the day until the dependent calculation completes
- Can not be used if a single (atomic) function call lasts more than 50 seconds (i.e. a solver)
- Backtesting period will be limited since an overall backtest will usually timeout after around 2 hours (as each day's lengthy calculation needs to be simulated)
Note that the before_trading_start()
timeout has been increased to 5 minutes now (as part of the Pipeline API changes) although I think there are still some outstanding issues with using history()
and set_universe()
here.
Hope this helps!
Rob