Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to set top and bottom constrains?

Hello,
I've recently tried to set a limited number of long and short positions. However, I can't find the correct indentation.
I would like to only place trades in the top 10 longs and top 5 shorts. Please help...

4 responses

hi Dan,

Something like the below might work for you. Where you use ".top" and ".bottom" to differentiate.

go_longs = (base_universe & ROA_long & ROE_long & PE_long & EPS_Growth_long & Current_R_long & debt_to_marketcap_long) | (base_universe & sector & dividentyield_long) #& bullish_intensity

go_shorts = (base_universe & sector & ROA_short & ROE_short & PE_short & EPS_Growth_short & debt_to_marketcap_short & Current_R_short ) | ( dividentyield_short & sector & base_universe)

longs = go_longs.top(10)
shorts = go_shorts.bottom(5)

picks = longs | shorts  

Thanks Daniel!

But I recieve an error:

AttributeError: 'NumExprFilter' object has no attribute 'top'

Has this question been answered? I am having the same issue.