Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
distance between custom factors - range or something else?

I'm trying to calculate the distance from custom factor x to custom factor y.

My problem is: sometimes it will be a positive number to a negative and other times a negative to a positive.

If custom factor x is -10 and custom factor y is +10, I would want the output to be +20

If custom factor x is +10 and custom factor y is -10, I would want the output to be -20.

I am dealing with decimals.

Here's what I've tried with no luck:

class DiffInEroc2(CustomFactor):  
        inputs = [it24up11619.eroc]  
        window_length = 12  
        def compute(self, today, asset_ids, out, eroc):  
            out[:] = eroc[-12]  
    class DiffInEroc1(CustomFactor):  
        inputs = [it24up11619.eroc]  
        window_length = 1  
        def compute(self, today, asset_ids, out, eroc):  
            out[:] = eroc[-1]   

    eroc1 = DiffInEroc1()  
    eroc2 = DiffInEroc2()  
    erocrange = range(eroc1, eroc2, .0001)  
1 response

So I think there's a way to do this with growth_score but not sure how to mix it with my upload that is also a custom factor. Perhaps I'm thinking about this the wrong way....thanks.

class ChangeInGrowthScore(CustomFactor):
inputs = [Fundamentals.growth_score]
window_length=252
def compute(self, today, asset_ids, out, growth):
out[:] = growth[-1] - growth[0]