Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to create alpha factor per sector in pipeline?

Hi everyone, I am currently trying to create a momentum strategy and have positive and negative values for certain sectors. But I am having trouble to create it, can you notice the problem? Thanks a lot.

def make_pipeline():  
    universe = QTradableStocksUS()  
    pos_sectors = [101]  
    neg_sectors = [104]  
    sector = Sector()

    sector_pos = Sector().element_of(pos_sectors)  
    sector_neg = Sector().element_of(neg_sectors)  
    momentum_1 = Momentum(window_length=252, mask=sector_pos)  
    momentum_2 = Momentum(window_length=252, mask=sector_neg)  
    momentum_1_z = momentum_1.zscore(mask=universe)  
    momentum_2_z = -momentum_2.zscore(mask=universe) # changing the zscore from positive to negative

    combined_alpha = (momentum_1_z.fillna(0.0)+momentum_2_z.fillna(0.0)).rank().demean()  
    return Pipeline(  
        columns={  
            'Combined_alpha':combined_alpha  
        },  
        screen= combined_alpha.notnull() & Sector().notnull()  
    )