Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Question about state stored in context

The help documentation states "context is an augmented Python dictionary used for maintaining state during your backtest or live trading session. context should be used instead of global variables in the algorithm. "

My understanding of context is that it is in-memory python dictionary, so state stored in context won't persist when algorithm is restarted. Is that correct? Is there any way I can maintain state of some variables across algorithm restarts ?

To be specific I have a variable that I store in context (say context.X). Over the course of a couple of days the value of context.X changes. If algorithm ever quits and is restarted I want to know what value was stored last in context.X.

3 responses

Hi Leo -

As far as I know, there is no way to write out, and then retrieve data, when an algo is stopped and re-started.

Thanks for answering my question.

It's been a mystery why one cannot store and retrieve data using non-volatile memory. It is a very basic computing operation. Note that you can copy-and-paste data into the algo, if this would help. However, it would be a manual operation. If you only need to capture a limited amount of data, perhaps you could write it out to the log? Another approach would be to write the data to the record function; the recorded variable data are available in the research platform.