Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
List the Stocks obtained from Set Universe

Hi,

How would I go about listing all the stocks and stock IDs in a universe summoned by:

set_universe(universe.DollarVolumeUniverse(99.9, 100.0))

Any help is greatly appreciated!

Rich

4 responses

Hello Rich,

This works:

def initialize(context):  
    context.stocks = []  
    set_universe(universe.DollarVolumeUniverse(floor_percentile=20, ceiling_percentile=20.5))  
def handle_data(context, data):  
    context.stocks = [str(sid.symbol) for sid in data]  
    print  ', '.join(context.stocks)  

However, you might run into logging limits if your list gets too long.

Grant

thanks grant! yeah, i'm seeing problems using set universe in my testing with dates prior to 2008, so this helps generate some specific sets to test with.

a follow up, it looks like the sec object changes once a security goes from "not yet existing" to "existing" i was reusing the old sec object so i was getting weird errors after the security becomes traded

I'm curious what the errors were.

And when using set_universe(), would like to find an effect like [sid for sid in data] except before leaving initialize() to populate context.stocks.