Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
[Research] Is there a way to update universe inside an algo that is running?

Standard code: from tutorials

data = get_pricing(  
    stocks_in_sp500,  
    start_date='2003-08-01',  
    end_date = today,  
    frequency='daily'  
)

algo = TradingAlgorithm(initialize=initialize,  
                        handle_data=handle_data)

results = algo.run(data['price'])

The problem: Survivors Bias (if stocks_in_sp500 = sp500 as of today), due to the fact that the group of securities (stocks_in_sp500) is set for the entirety of the algo.run()

My questions: How can i update stocks_in_sp500 while my algo is running?

2 responses

Hi John Loeber,

Simplified question: Is there a function equivalent to update_universe() in the research environment?

Not really. I think your best bet is to do this in the IDE (i.e. in the algorithm platform), and to then export your backtests to the Research Platform to analyze results.