Back to Community
Look back N days Pipeline

Hi, I am trying to create a pipeline to get the Ichimoku Cloud (a technical indicator) and also some n days close price, but I keep getting the error 'Term.getitem() expected a value of type Asset for argument 'key', but got int instead.' I tried different things but dont know how to fix it.

Loading notebook preview...
3 responses

The factor needs data like pricing or fundamentals as inputs (numbers), not a universe selection (boolean). You can filter the universe by using mask = universe.

class CloseOnN(CustomFactor):  
    # Define inputs  
    inputs = [USEquityPricing.close]  
    mask = universe  
    window_length = 0  
    # Set window_length to one more  than the number of days to look back  
    # my_close_on_10 = CloseOnN(window_length = 10+1)  
    def compute(self, today, assets, out, close):  
        out[:] = close[0]

Hi Tentor, thanks for the answer. By the way, do you how to access to the past data of an indicator. I would like to compare the 2 days ago close price against the indicator (In this case the ichimoku cloud) but from also 2 days ago. Thanks in advance

Yes, you need to make the factor window safe like this:

class IchimokuKinkoHyo(IchimokuKinkoHyo):  
    window_safe = True  

Then you can create a simple custom factor that returns the values from 2 days ago (or what window_length you set there)

class Factor2DaysAgo(CustomFactor):  
    window_length = 2  
    def compute(self, today, assets, out, factor):  
        out[:] = factor[0]  

For more details see the attached notebook

Loading notebook preview...