Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Saving State and Recovering from Failure

I am attempting to figure out how to save my algorithms trading state and recover from failure correctly. I have a rather complex algorithm I'm putting together which has different reasons for buying different stocks. I need to save the reason I bought a stock because it tells me what signals I need to use to determine if I should sell a stock.

I don't do day-trading, so I don't really care about minute-data or even minute-based decisions. The minimum time I will ever hold a stock is 7 days (5 bars). The maximum time I might hold a stock is indefinitely. How long I hold a stock is highly dependent on why I bought the stock. If the algorithm is doing live trading, I cannot afford to lose that information. How do I make sure I keep this information around even on restarts of the trading system? Do I need to send the data to my own server somewhere for storage?

1 response

My understanding is that if you use context (e.g. context.my_stuff), anything you store there will persist; you can use it to maintain state. However, if you stop the algo or it crashes due to a bug, I think you'll lose the data (although you might be able to use https://www.quantopian.com/help#quantopian_research_get_live_results to pull some of it into the research platform).

There is no way to write results out to disk, and certainly not out to your own server (since Quantopian can't allow export/download, due to data licensing restrictions).