Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
alphalens template change

I'm using the template from the alphalens tutorial here: https://www.quantopian.com/tutorials/alphalens#lesson5

I uploaded custom data points that have weekly values.

I'm trying to get the difference from the most recent value from the value a certain N weeks ago and then run that through the 5 years of history I uploaded. My (-'4w') below is clearly not correct, but I don't know how to code this in the notebook.

Should I drop data into a list? Or perhaps do a data.history in the notebook somewhere?

Appreciate the help!

def make_pipeline():  
    eroctoday = roc.eroc.latest  
    erocpast = roc.eroc.latest(-'4w')  
    erocdifference = eroctoday-erocpast  
    return Pipeline(  
        columns = {'erocdifference': erocdifference, 'sector': sector},  
        screen = QTradableStocksUS() & erocdifference.notnull() & sector.notnull()  
    )

factor_data = run_pipeline(make_pipeline(), '2015-1-1', '2016-1-1')  
pricing_data = get_pricing(factor_data.index.levels[1], '2015-1-1', '2016-6-1', fields='open_price')