Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
problem w/ Sector().eq() - any ideas?

With the code attached, I get no trades. Any idea why?

def regression_pipeline():  
    QTU = QTradableStocksUS()  
    sectors = [101,102,103,104,205,206,207,308,309,310,311]  
    sector_ETFs = symbols('XLB',  
                          'XLY',  
                          'XLF',  
                          'IYR',  
                          'XLP',  
                          'XLV',  
                          'XLU',  
                          'IYZ',  
                          'XLE',  
                          'XLI',  
                          'XLK'  
                          )  
    alpha = None  
    for s,e in zip(sectors,sector_ETFs):  
        if alpha == None:  
            alpha = RollingPearsonOfReturns(  
                    target=e,  
                    returns_length=2,  
                    correlation_length=8,  
                    mask=Sector().eq(s)&QTU  
                    ).zscore()  
        else:  
            alpha += RollingPearsonOfReturns(  
                    target=e,  
                    returns_length=2,  
                    correlation_length=8,  
                    mask=Sector().eq(s)&QTU  
                    ).zscore()  
    pipe = Pipeline(columns = {  
        'alpha': alpha,  
    },  
    screen = QTU)  
    return pipe
4 responses

When you add a number to nan in python it's equal to nan.

When you're adding the alphas together, the nan's from the other sectors are getting added to the sector you're looking at and making all of the alphas nan.

A custom factor to add the alpha's together would be the way to fix this as you could safely handle the nan's.

Thanks Dale -

I fixed things in a different way (see attached backtest).

Great work, Grant. I always appreciate your posts and always learn a ton of different approaches from your methods. Thanks

Thanks Daniel. Glad that you've benefited.