Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Small cap screen?

I am trying to only select small cap stocks in my algo, but I am running into trouble.

market_cap =  fundamentals.valuation.market_cap  
small_cap = ((market_cap > 15000000) & (market_cap < 100000000))

 pipe = Pipeline(  
        screen =  small_cap,  
        columns = {  
            'returns'    : returns  
        }  
    )  
5 responses

Hmmm. You may need an extra zero in each of your compare statements. I assume you want greater than $150M and less than $1B. Try adding a zero to each and see if that works.

no luck,

TypeError: __init__() takes exactly 4 arguments (3 given)  

@sean,

Can you share the full code? if not, it might be better to get market_cap as a custom factor:

from quantopian.pipeline import CustomFactor 

class MarketCap(CustomFactor):  
    inputs = [USEquityPricing.close, morningstar.valuation.shares_outstanding]  
    window_length = 1  
    def compute(self, today, assets, out, close, shares):  
        out[:] = close[-1] * shares[-1]

then in your pipeline function:

def my_pipeline(context):  
    pipe = Pipeline()  
    market_cap = MarketCap()  
    small_cap = ((market_cap > 15000000) & (market_cap < 100000000))  
    pipe.set_screen(small_cap)  
    return pipe  

Maybe try adding '.latest' to your market cap?

market_cap =  fundamentals.valuation.market_cap.latest  

@ frank
That worked, thanks