Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
PIPELINE OUTPUT LIMITING How do I get this to output 20 rows? Where do I need to add a filter or a screen etc.. Thanks for the help!

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.

4 responses

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.

@danwhitnable you are the man. I owe you, honestly appreciate all the help you give to me and others.

@JohnR - Glad to help.