Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to remove delisted stock symbols from history()?

It seems that my algo keeps trying to order stocks that no longer exist via history(). How do I avoid this? An example is "MLNM" being ordered circa 2008. Basically 2008 causes me to order a bunch of stocks that no longer exist and no transactions take place via the backtest.

1 response

I think I figured out a way:

prices = history(bar_count=200, frequency='1d', field='price').dropna(axis=1)  
g = prices.mean()

symbols = []  
for sec in g.index:  
    if sec in data and data[sec].sid.end_date >= get_datetime():  
        symbols.append(sec)  
g = g[symbols]