Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Morningstar pe_ratio

How is pe_ratio calculated for a stock with negative earnings over the last four quarters? I've found that these ratios are never shown as negative. Short of compiling earnings for each of the four previous quarters, is there some simple way to flag stocks with negative earnings over the last year?

5 responses

The Morningstar definition of PE Ratio is (see https://www.quantopian.com/help/fundamentals#valuation-ratios)

Adjusted Close Price/ EPS. If the result is negative, zero, >10,000 or
<0.001, then null.

So, if it's negative then it's reported as NaN.

To check if a whole year is negative maybe write a custom filter with a window length of 252. Inputs = [mstar.valuation_ratios.pe_ratio]. Check if a whole column (ie all the data) are NaNs. Maybe something like this?

class EPS_NaN(CustomFilter):  
    # Define inputs  
    inputs = [mstar.valuation_ratios.pe_ratio]  
    window_length = 252  
    def compute(self, today, assets, out, pe):  
        # The input 'pe' is a Numpy array with data as axis 0 (total rows = window length)  
        # and axis 1 are all the assets (ie stocks and securities).  
        # Here we use the built in Numpy methods to check for all NaNs (ie all negative earnings).  
        is_nan = np.isnan(pe)  
        out[:] = np.all(is_nan, axis=0)

Attached is a notebook with this in action.

oops, forgot to attach the notebook...

Didn't know that PE ratio returned NaN if it was negative. Might be useful to divide closing price by EPS and calculate the PE ratio that way if you want to incorporate negative PE ratios in an algorithm. For the trailing PE ratio you could divide market cap by net income for the last four quarters using a custom factor to get net income for past quarters.

Thanks much, Dan and Eric, for your response to my post.

What triggered the post was finding anomalous PE ratios for a few stocks that had negative earnings—APA and SHLD. The attached notebook extracts prices, earnings per share, and price-earnings ratios for these two stocks and five others (SBUX, IBM, AAPL, TSLA, and TWTR).

SBUX, IBM, and AAPL all had positive earnings in the past quarter and fiscal year; pe_ratio for these stocks appear to have been calculated as price divided by annual earnings per share for the last 12 months. To verify this, I went to the Morningstar web site and looked up earnings per share. It would be useful if the documentation of Morningstar fundamental data made clear what data items are quarterly and what are annual. The documentation just says that pe_ratio is price divided by EPS, without specifying whether EPS is the last quarter, the last 12 months, or the last fiscal year.

Both TSLA and TWTR had negative earnings per share in the last quarter and last 12 months. For each of these, the pe_ratio is, appropriately, not a number (NaN).

The problem arises with SHLD and APA. Both these stocks had negative earnings in the last 12 months but pe_ratio is a positive number—69.4 for SHLD and 18.0 for APA.

In my last post, I should have made clear that the basic_eps values shown in my notebook are quarterly, not annual. That is, both SHLD and APA had negative earnings for the trailing 12-month (TTM) period but positive earnings for the last quarter. It seems that, for such stocks, a positive pe_ratio is shown (even though annual earnings per share are used in calculating pe_ratio for other stocks.