Back to Community
Bad error: unsupported operand type(s) for &: 'int' and 'Latest'

I am trying to combine filters, and I am following the tutorials, but I get the error

unsupported operand type(s) for &: 'int' and 'Latest'

I've attached the notebook, but here is the relevant code.

def make_pipeline():  
    base_universe = QTradableStocksUS()  
    '''  
    Factors  
    '''  
    roce = (  
        Fundamentals.ebit.latest / (  
            Fundamentals.total_assets.latest  
                - Fundamentals.current_liabilities.latest  
            )  
    )  
    free_cash_flow = Fundamentals.free_cash_flow.latest  
    shares_outstanding = Fundamentals.shares_outstanding.latest  
    pe_ratio = Fundamentals.pe_ratio.latest  
    shareholder_yield = Fundamentals.total_yield.latest  
    revenue_growth = Fundamentals.revenue_growth.latest  
    '''  
    Filters  
    '''  
    good_pe = (pe_ratio > 4 & pe_ratio < 11) #--> here is the error  
    low_share_count = shares_outstanding < 50000000  
    high_yield = shareholder_yield > 0.1  
    high_roce = roce > 0.1  
    high_revenue_growth = revenue_growth > 0.25  
    filters = high_yield & good_pe & low_share_count  #-> also appears here  
    '''  
    Sectors  
    '''  
    sector = Sector()  
    return Pipeline(  
        columns = {  
            'shares_outstanding': shares_outstanding,  
            'shareholder_yield': shareholder_yield,  
            'pe': pe_ratio,  
            'sector': sector,  
        },  
        screen=base_universe & filters  
    )  

And I am not sure how to fix this. Any ideas?

Loading notebook preview...
Notebook previews are currently unavailable.
2 responses

Try this:

    pe_over_lb = pe_ratio > 4  
    pe_under_ub = pe_ratio < 11  
    good_pe = pe_over_lb & pe_under_ub  

Okay, that works, thanks. And even if I do

good_pe = (pe_ratio < 11) & (pe_ratio > 4)  

it works. Guess it's something about the order/precedence it gets evaluated ...