QuantRocket logo

Disclaimer

The TradableStocksUS Universe

Now that we've covered the basic components of the Pipeline API, let's construct a pipeline that we might want to use in an algorithm.

To do so, we will create a filter to narrow down the full universe of US stocks to a subset of tradable securities, defined as those securities that meet all of the following criteria:

Former Quantopian users may notice that this universe is modeled on Quantopian's most popular universe, QTradableStocksUS, described in this archived Quantopian forum post. To reduce data dependencies, we have omitted one rule, namely that market cap must be over \$500M. See the note further down if you have a Sharadar fundamentals subscription and would like to add this market cap filter.

Creating Our Universe

Let's create a filter for each criterion and combine them together to create a TradableStocksUS filter.

Now we can define our filters. As discussed in the lesson on masking, we use masks in the later steps of our asset funnel to reduce computational load.

Note that when defining our filters, we used several Classifier methods and built-in Filters that we haven't yet seen including isnull, All, and AllPresent. Documentation on these methods is available in the API Reference for Classifiers and Filters.

If you have a Sharadar fundamentals subscription and would like to add a market cap filter to your universe to fully re-create the QTradableStocksUS universe, you can do so by adding the following line to the above function:

# also require market cap over $500M
tradable_stocks = Latest([sharadar.Fundamentals.slice(dimension='ARQ', period_offset=0).MARKETCAP], mask=tradable_stocks) >= 500e6

Code Reuse

Our universe may be useful to us in numerous notebooks and Zipline algorithms, so a practical next step is to transfer the pipeline code to a .py file to facilitate code reuse. We have done so in tradable_stocks.py. The universe can now be imported in any notebook or Zipline algorithm as follows:

We'll import and use this universe in the next lesson.


Next Lesson: Using Pipeline with Alphalens