QuantRocket logo

Disclaimer

Combining Filters

Like factors, filters can be combined. Combining filters is done using the & (and) and | (or) operators. For example, let's say we want to screen for securities that are in the top 10% of average dollar volume and have a latest close price above \$20. To start, let's make a high dollar volume filter using an AverageDollarVolume factor and percentile_between:

Note: percentile_between is a Factor method returning a Filter.

Next, let's create a latest_close factor and define a filter for securities that closed above $20:

Now we can combine our high_dollar_volume filter with our above_20 filter using the & operator:

This filter will evaluate to True for securities where both high_dollar_volume and above_20 are True. Otherwise, it will evaluate to False. A similar computation can be made with the | (or) operator.

If we want to use this filter as a screen in our pipeline, we can simply pass tradeable_filter as the screen argument.

When we run this, our pipeline output now only includes ~700 securities.


Next Lesson: Masking