Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
adding ETFs to filtered stocks

Hi, I am new to quantopian and just starting to learn how to build my first algo. I like to pick the top 3000 stocks by market cap. In addition, I like to add quite a number of (US+foreign) ETFs (whose market cap might not make to the top 3000) to that list before running a ranking of features. How could I do that? Thanks

2 responses

First off, welcome!

To add fixed or static assets to your universe of potential stocks use the StaticAssets filter. (see the docs https://www.quantopian.com/help#built-in-filters ).

Something like this

    # Base universe set to the QTradableStocksUS  
    # This is includes only stocks and is recommended as a base for most trading universes  
    base_universe = QTradableStocksUS()  


    # Select largest 3000 stocks by market cap from the initial base  
    # Use base_universe as a mask to begin with that subset of stocks  
    top_3000 = MarketCap(mask=base_universe).top(3000)


    # Select some fixed ETFs  
    my_etfs = StaticAssets(symbols('SPY', 'VTI', 'GSIE'))  


    # my universe is the top 3000 plus my etfs  
    my_universe = top_3000 | my_etfs

Check out the attached algo to see it run. Good luck.

Thank you!