Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Growth Rate with Factor

I'm trying to determine the growth rate for two EPS values: the current quarter vs the same quarter a year ago. The challenge that I'm finding is that depending if the earnings are positive or negative, the sign on the growth rate is not correct. I would normally just use a conditional statement and apply a negative sign correctly, but this is all captured in factors and I haven't been able to figure out how to conditionally change the sign. I tried "np.where" but got errors.

The standard percentage growth formula is obviously:

growth = (Current - Previous) / Previous  

However if EPS go from -$1 a share to $5 a share then it would be:

growth = -6 = (5 -- 1)/-1.  

So in this case, the growth is -6, but it had positive growth. I'm trying to make my algorithm distinguish between negative growth and positive growth. (This seems like a fairly newbie question)

I've attached a notebook to hopefully make it easier for someone to help.

Thanks!
--Brian

3 responses

You may want to consider a separate custom factor to calculate eps growth. Divide by the absolute value of 'previous'. Something like this....

class EPS_Growth(CustomFactor):  
    inputs = [morningstar.income_statement.net_income_from_continuing_and_discontinued_operation, morningstar.valuation.shares_outstanding]  
    window_length = cTRADING_DAYS_YEAR  


    def compute(self, today, assets, out, income, shares):  
        current_eps = income[-1] / shares[-1]  
        year_ago_eps = income[0] / shares[0]  
        out[:] = (current_eps - year_ago_eps) / np.absolute(year_ago_eps)

See attached notebook with this in action. Specifically note ABX about 10 rows down in the resulting dataframe. The earnings go from negative to positive. The custom factor therefore shows a positive growth (which is what you were looking for).

I noticed FLWS, for example, ballooned in some weeks/quarters. But the period shifted around. Timeshift might be worth checking out.

Dan, thank you so much for this! I was stuck on this for hours and hours.