Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Price/Earnings Ratio Mean Reversion Strategy

The P/E ratio is defined as the price of the stock divided by the earnings per share of the stock, and is particularly interesting because it's dimensionless (has no units) and has historically always remained around the same value.

This algorithm computes the P/E ratio every day using the current S&P price and most recent S&P earnings per share. If the current P/E ratio is higher than its historical average, then we would expect the stock price to go down, so we short. If the current P/E ratio is lower than its historical average, then we would expect the stock price to go up, so we go long.

The earnings look pretty crazy because at least in these backtests, this is a good predictor of days the S&P crashes. It often goes long periods of time without trading, so it may be best to pair this with another signal or strategy.

Clone the algo and play around with it, and let me know if you have any questions!

EDIT: Simon has pointed out below that this would not be realistic for live trading, since I didn't account for earning announcement delay. I still believe this idea has merit, however, due to the nature of the ratio.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

23 responses

Here's a version with a few things that are different. This version is meant for minute-mode, but can also be run in daily mode. Instead of computing the average, it takes an expected PE ratio and trades based off of that.

very interesting.. I like mean reversion studies--thanks for the share!

really interesting 2008 crash ..caught it well

Hello, Gus Gordon,
Thank you for sharing this very interesting algorithm. May I ask you a question? It seems to me the S&P 500 quarterly earnings are released much later than a quarter's ending, e.g., 1st quarter of 2014 ends on 3/31, but the earning for this quarter is not released until 7/15. This algorithm is using this earning data right after 3/31. Wouldn't this be a look-ahead bias?

I'm curious if there is a way to automate the S&P 500 earnings data source.
Quantopian has made me quite lazy. Even updating a csv manually every 3 months feels like too much work now. =)

Where is a data source for this P/E information? Ideally good, accurate and timely. Yahoo Finance has this data, but it would have to be scraped....I just don't know how timely or accurate it is.

Quandl data is integrated with TradingView now just in case that might help: http://blog.tradingview.com/?p=452

Thanks everyone.

WJ, S&P doesn't release the total S&P 500 earnings themselves until later. However, the companies that constitute the S&P release their earnings throughout the quarter, and these earnings could be calculated accordingly, albeit more difficultly. In fact, the data I imported could be much more accurate with some effort. Some companies may release their earnings two or three months earlier than the report date in the CSV. It would be possible to have a total S&P 500 earnings that is updated every day, where the newest earnings for a company override the older earnings, then the total S&P earnings is recalculated. It would be more practical to only live trade with this, because current data is relatively available online. Backtesting would be much more difficult because it would be a pain to gather past data and compile everything together. But I think if I were to live trade, the best way would be to have some way to compute the most recent possible S&P earnings like I said. It's just difficult with the changing stocks in the index. There may be an existing solution, but I haven't looked around much. Also, some sources for the PE ratio seem to calculate it differently. I believe many places online use operational EPS whereas I'm using reported EPS, which seems to work better from my tests.

Chandra, look here: http://us.spindices.com/indices/equity/sp-500
Click the additional info tab on the left. That's where I got it from for backtesting purposes. For live purposes, I'm guessing there is a good source somewhere, but it may be best to calculate it yourself. See my reply to WJ just above.

Gary that is so cool! I didn't see that.

So WJ's reply prompted me to try a quick backtest with dates in the csv timeshifted by 3.5 months.
The results are about as bad as you'd probably imagine... completely missed timings on most crashes.

Looks like some kind of custom real-time earnings data gathering will be necessary to get close to the results in the earlier backtests.
Possible feature request maybe? It'd be nice to have access to earnings information and other fundamentals straight from the API.

Gus, thank you very much for your answer. It makes a lot of sense.

Interesting Lewis. Some of those earnings can be as much as 6th months old which is no good! The way I have it in the backtest, the data is already late. The issue is just that S&P doesn't release the aggregate earnings themselves until later — they can be calculated much earlier, daily. See my reply to WJ above if you haven't already. Yes, fundamental data would be a very important feature, I absolutely agree.

WJ, glad I could help, let me know of any other questions/ideas.

Is it possible to live trade this? The system asks me to do a minute data backtest and the results were horrible.

Hi Luesak,
See the 2nd post in this thread, and my reply to WJ. Let me know if you have any other questions.

Gus

Where are you getting these P/E ratios from? When I looked up P/E ratios for the S&P500 they are around 17. P/E of 8.5 seems really low for stocks these days...

Michael, I believe that is a ratio based on the operational earnings, whereas I am using reported earnings.

I think you cannot use the published earnings without delaying, you are definitely, definitely introducing look-ahead bias that way - the date on that spreadsheet is the end of quarter, for the quarter in which the earnings were earned. Individual companies take up to 45 days after the end of the quarter to report their first three quarterly earnings, but they will still wind up dated to the end of the quarter, and the same occurs in aggregate here. These backtest results are simply not indicative of what would happen with live trading, no matter how sophisticated one's live earnings gathering was.

Both the operational and reported earnings are over 17. I still don't know where you are getting such low numbers from.

I think he's calculating (SPY ETF Price) / (S&P Earnings)

I'm not so sure about that. the S&P500 is at 1990 while SPY is around 199 so a 10x difference where as the difference between the P/E Gus is using is roughly 1/2 of what I'm seeing online from multiple sources.

Hi, Michael Huang,
Gus's algorithm is using (SPY price) / (S&P500 quarterly earning). Usual definition is (S&P500 index value) / (S&P500 yearly earning). Since SPY is roughly 0.1 of the index value, quarterly earning is roughly 0.25 of yearly earning, so the resulted P/E ratio is roughly 1/2 off.

Thanks guys.

Simon, you are definitely right, sorry for the confusion. Here is a backtest that has a 45 day delay — as should be expected, the results are about average. There is still some room for improvement however, as this backtest represents what is essentially the worst-case scenario of all S&P companies releasing earnings 45 days after the quarter ends, when in fact most are released 20-30 days earlier. I'll edit my first post.

Gus

I was just wondering about this type of strategy. I am interested in using fundamental data to have a 'normal price' and short/long depending on how the stock is trading relative to some sort of 'normal price'. Not necessarily an MA ( i gave up on that whole idea a long time ago) rather, more like your example of P/E correlation. However, I am wondering, if the earnings don't change but every quarter, is this strategy hoping that price won't either? If some how minute by minute we are shorting/longing depending on the P/E calculated quarterly, are we saying that somehow the 'correct price' shouldn't change till we know the next earnings? I don't know at all, I have no financial training and can barely code, but I love reading and trying out this stuff. Thank you quantopian for everything!

I am just getting started with quantopian, so this question might be pretty naive. If you are using the fundamental data provided by morning star for back testing , is there a chance that you might have a look ahead bias ? In other words, is this data updated only after the day it was originally announced by the company or is it updated at the beginning of every quarter?