Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Run code once, access data and context

I want to pick the stocks that I long/short based on some initial calculations that only need be be run once. These are based on historical pricing data so I need access to this. When I try this in the 'initialize' sub I get an error because data has not been defined?

The only way around this that I can think of is to have an if statement in my before day trading, that runs the first time and then skips the code, but this seems like a bit of a hacky way to do it - is there a built in method I should use?

1 response

Fraser,

As far as I know, you're stuck with the hacky way. Alternatively, you could sort out how to pick the stocks on a rolling basis, so that you don't have the one-time universe selection.

Grant