Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Custom factor - with yearly based calculation

Hi, I would like to create a custom factor which computes a yearly standard deviation of the the ROA (Net Income / Average Total Assets).
I've found a way to calculate this on a daily basis:

class StdDev(CustomFactor):  
    def compute(self, today, asset_ids, out, values):  
        out[:] = numpy.nanstd(values, axis=0)

def make_pipeline():  
    std_dev = StdDev(  
        inputs=[Fundamentals.roa.latest],  
        window_length=5  
    )

    return Pipeline(  
        columns={  
            'std_dev': std_dev  
        }  
    )  

any ideas how to change the window_length units to be yearly?

Thanks!

1 response

As far as I know, you can't change the units. Instead, increase the window length to 253 business days (might want to go a bit higher to guard against variation in business days per year) and do a percent change calculation (see attached notebook). When you put it in an algorithm you can set the rebalance frequency to monthly, but not quarterly. It should be possible to map calendar days to business days but I haven't tried it yet.