Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How do I access previous values for USEquityPricing within my make_pipeline calculations?

I want to be able to compare the current price with yesterday's SMA so I can tell if the price has crossed it, then use that as a filter. I can't figure out how to do that with the dataset and pipeline framework.

Any help would be great

2 responses

Hello,

Create a custom factor with two outputs, the current value and the previous one:

class SMA(CustomFactor):  
    inputs = [USEquityPricing.close]  
    outputs = ['value', 'value_p']  
    def compute(self, today, assets, out, close):  
        N = self.window_length -1  
        sma_vector = talib.MA(close, timeperiod=N)

        out.value[:] = sma_vector [-1]  
        out.value_p[:] = sma_vector [-2]  

Thank you!