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.

Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5c8bedf9153e854af09b6543
There was a runtime error.

Thank you!