I want at most 20 securities output to trade. If there are ever less than 20 with my factors that is okay, but at most I need/want 20.
I want at most 20 securities output to trade. If there are ever less than 20 with my factors that is okay, but at most I need/want 20.
more info. i have some masks going on that grab the is_tradeable. but how do i get the top 20 of is_tradeable to be the output?
Use the 'top' method on any of your factors to create a filter. See https://www.quantopian.com/help#quantopian_pipeline_factors_Factor and scoll a few paragraphs down. Then use that as a screen something like this
screen = mktcap.top(20, mask=is_tradeable)
That will give you the top 20 by market cap. You could also get the top 20 sorted by any other factor in a similar way.
I've attached a copy of your notebook with this change. Now your "Number of securities that passed the filter:" return 20. It may be less than 20 if there are fewer that pass the 'is_tradable' filter, but there will never be more than 20.