Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Am I doing this right? (CustomFactor)

So I'm trying to find the highest value and the lowest value from the last 52 trading days. And then I'm taking these two numbers and adding them together and then dividing them by 2. I just want the output value of this formula, but I'm unsure if I'm doing this correctly or not. Here's the code that I'm using in my backtest.

I'd appreciate any help, thanks.

2 responses

Pretty close. Try this.

class VarA(CustomFactor):  
    inputs = [USEquityPricing.high, USEquityPricing.low]  
    window_length = 52

    def compute(self, today, assets, out, highs, lows):  
        highest_high52 = np.nanmax(highs, axis=0)  
        lowest_low52 = np.nanmin(lows, axis=0)  
        out[:] = (highest_high52 + lowest_low52) / 2.0

See attached notebook for the custom factor in action. Good luck.

Oh wow, that seems much easier. Thanks so much, I really appreciate it!