Skip to main content

Quantitative Analysis for Dummies - A Quick Analysis of Opening Gaps on the S&P 500

This blog entry is going to roughly test the viability of trading a simple strategy known as the "opening gap" in the S&P 500 over a period of 10 years.  I stopped at 10 years because this is what I could find freely and simply available in my cursory search of the Internet.

First some background:

Ever since I moved to Washington D.C., I had an interest in finance and economics.  The catalyst for my interest was the lack of affordability of housing, another story.

I've since considered investing and opportunistic trading, hobbies.  Well before the 2008 financial crisis I played around and realized I was not disciplined enough for day trading.  After that short-lived bout with losses, I tried my hand at buy and hold,  buying what I perceived to be good companies at what I perceived to be a discount.  I studied fundamental analysis and technical analysis.  I looked for the "Holy Grail", but I tended to be flummoxed by the gap between different schools of thought.   On one hand, you had folks who believed that the market was efficient and the best possible return you could ever hope to receive is through passive investment with the "indexes".  On the other hand there were folks who believed strongly that the market was not efficient and that it tended to be shaped by "behavioral economics".  In other words,  they believed that you could achieve an advantage over the market over a longer period by being informed and opportunistic.

The first camp of the "efficient market" hypothesis crowd will say things like:  "Monkeys throwing darts at the wall can pick stocks just as well as traders on average" or "there is no way to prove that the market is not efficient".  The "behavioral economics" camp will quickly point out folks like Warren Buffett and others who have amassed huge fortunes with a better strategy.

While it is not the subject of this blog, I have convinced myself that the Market is NOT efficient and instead a smart individual can beat the market on a perpetual basis.  There are some proofs that I could offer:

  1. Many people buy blindly and then sell in a panic.  In other words, people don't make rational and/or informed decisions.  Could it be that this is just noise in the market and the smarter/larger money will find the correct price instantly?  
  2. News often is not digested instantly and prices do not become stable once news is known.  News is just a catalyst for people to start moving the market by jumping in or jumping out.  While some have models that can perhaps perfectly update the change in expectation,  others  tend to just jump in. My supposition is that these activities create an imperfect price which can be exploited.
  3. A large amount of money is tied up in 401k's through mutual funds which can only be bought and/or sold at the end of the trading day.  In other words, if everybody hit sell on their Mutual Funds all at once,  an entire trading day could elapse in between this selling.  That is not "efficient" in that it cannot and does not move the market instantly.

Anyhow, I purchased "Mastering the Trade" by John Carter about 10 years ago.  I actually tried some of the techniques in his book, and became disenfranchised when I didn't have the time, patience, or discipline to implement successfully.   I revisited the book this week after the market dropped precipitously.  I mainly have a curiosity as to whether it is possible to programmatically beat the market with his or other strategies. Using data analytic skills that I've gained over a few years,  it is much easier for me to analyze and backtest today. There are many more tools available to accomplish as well.

One of the first chapters on actual trading strategies goes a little something like this (obviously summarized):

  1. U.S. Markets tend to have gaps between one day's trading day and the next (4:00 p.m. EST - 9:30 a.m.)
  2. One can buy/sell the gap at the market open and have a strong likelihood (80%) of the gap being closed before the end of the day.  
  3. Their are a couple of suggestions for why they have a high likelihood of closing the gap like: traders don't like messy charts,  the folks that bought/sold pre-market are actually weak hands, etc.  
  4. With a reasonably setup and objective (unemotional) trading strategy, a trader can regularly profit on this trade. 
Note:  I am ignoring some of the nitty gritty of the strategy as the rules seem highly nuanced (human) and are difficult to quickly model.

I've watched the stock market for about 10 years with this chapter in mind.  Without really ever putting the strategy to work,  I noticed the gap being closed in many cases.  I never really had the time to put it to good use as I was doing other things (working).  It is interesting to note though that if a strategy can't be reduced down to something simple, I tend to discount it.  I believe that humans are subject to confirmation bias, so if you can't test the result in a repeatable way,  it is not actionable.

One thing that is important to note,  Carter, and many other traders will tell you how important it is to have a "system", and to set "Stops" as well as to having a defined exit strategy for your profit.   The reason for this is simple and again,  it is because you need to break down the strategy to its simple, almost mechanical steps, otherwise it is not repeatable.  Exiting on emotion, whether at a profit or loss, is not repeatable.

Let's take a look at some examples (Using the S&P 500 ETF - SPY):



This first example was on August 25, 2015.  The hashed line on the left was the previous day's close (Close Price: 189.48).  On the morning of the 25th , the market gapped higher and opened at 195.43.  The difference between the close and open was 5.95.  If you had used a 1:1 risk/reward stop ratio, the stop price would have been 201.38.   While the gap did not close right away, it did close the gap before reaching your stop for a profitable trade.


This second example was on the very next day, August 26, 2015.  The market closed on the 25th at 187.24 and opened on the 26th at 192.08.  If you had gotten the open price, you could have set a stop at 196.92.  In this particular example,  you didn't close the gap, but also weren't stopped out.  Instead you would have booked a loss at the Market Close of 2.48.

With some examples behind us,  we know how it works.  Let's see if we can test it.  In order to quickly attempt a backtest we just use the historical Open, High, Low, Close prices for any stock and/or exchange traded fund.

In this particular backtest,  I was able to download 10 years of historical data on SPY, the ETF that tries to closely track the performance of the S&P 500 index.

Here is an example of the data:  (You can find the data for free here: NASDAQ)


date close volume open high low
8/28/15 199.28 160338700 198.5 199.835 197.92
8/27/15 199.27 273700600 197.02 199.42 195.21
8/26/15 194.46 338718200 192.08 194.79 188.37
8/25/15 187.27 367623500 195.43 195.45 186.92
8/24/15 189.5 506257800 187.49 197.4772 182.4

On any given day,  you can calculate the difference between the previous close and the open,  and then test to see if the high and low price "brackets" the previous close price.  In other words,  we want to test to see if we traded back to the previous close price during the day.  If so, great!  We made a profit.  If not, darn, we booked a loss of the stop price.  (Note:  I did not see if the loss we took would have been less because our stop wasn't hit and instead we closed out at the market close like our example above.  Homework I guess.)   

Now to our results.  (They are somewhat surprising)



So the Y-axis is in cumulative dollars.  The results are as if you had only traded 1 share.  You can multiply the Y-axis by the number of shares you could theoretically purchase in each trading day.  

The X-axis is obviously the date, testing back 10 years.  This is where it is interesting.  Between August 2005 and the middle of the 2008-2009 financial crisis,  the opening gap trade was tremendously profitable!  

Essentially you could have had a tremendous return of ~130% from 2005 to 2009-2010.   This is where the magic stops unfortunately and thing start to get ugly.  I have no idea at present why things shifted, but perhaps it is due to an increased number of algorithmic traders?  

Interestingly it looks like the better trend to follow since 2009-2010 is actually to take the opposite trade.  

If anyone is interested in chatting more about these things,  send me a message.   I'm interested to see if there is any analysis that shows something different or if I was somehow wrong in my conclusions/approach.  A note of warning,  I am not a financial advisor and did this analysis in a few hours on a Saturday.

*** Edit:  One thing of note,  with only the Open, High, Low, and Close I have no way of testing whether or not the stop was hit before the gap was filled which presumably happens some percentage of the time.

*** Second Edit:  I wanted to see what the opposite trade looked like since it trended in the other direction.  It seems to be a rather profitable trade since 7/29/2009.  See chart with Y-Axis based on trading 1000 shares:  (Interestingly though,  it was more profitable to just buy the S&P 500 and hold it during this same time period.  I wonder how it will do in the next bear market.)



Comments

Popular posts from this blog

The Price You Pay Does Not Matter - How Microsoft reflects poorly about the return prospects of investing in the stock market

Microsoft is the most valuable company in America. You probably didn't know that.  Few people know that Microsoft commands the largest valuation in the S&P 500.  It is an economic powerhouse, returning to shareholders substantially well over 100,000% return since IPO. Microsoft isn't a hot stock anymore, business schools probably have moved on from teaching about Amazon to Lyft or Uber at this point, not Microsoft.  Maybe they've even moved on from them to talk about fake meat companies like BYND.  Goodness forbid they teach about anything related to WeWork or...   Ok I'll stop while I'm ahead. Microsoft commands a truly impressive market capitalization of over 1.1 Trillion dollars.  This pales in comparison to our national debt, but is an impressive figure.  They have 38 billion dollars in INCOME, each year.  They have 130 billion dollars in sales (revenue) each year.  The Price to Sales ratio is 8.3x, a truly ridiculous figure. ...

2084: Why Total Government Control From Cradle to Grave Is the Future We Deserve

It’s time we admit it: freedom is overrated. The burden of personal choice, responsibility, and individuality has plagued humanity for too long. From the chaos of deciding which cereal to buy in the morning to the terrifying uncertainty of retirement planning, life is simply too complicated. Fortunately, there is a solution. It’s a radical one, but it’s the only way to free ourselves from the burden of freedom: total state control over every aspect of our lives, from cradle to grave. Think about it—what have our “freedoms” really gotten us? A chaotic world where we’re bombarded with endless choices, distractions, and responsibilities. Every day, we wake up and are forced to make decisions: where to work, what to wear, whom to marry, what opinions to hold. What if, instead of being weighed down by such trivial concerns, a benevolent government made all these choices for us? Imagine the relief of never having to think for yourself again! Let’s start with the basics: birth. Why should par...

From Tea to Tokens: How the Spirit of the Boston Tea Party Lives On in Bitcoin

In 1773, a group of colonists in Boston dressed as Mohawk Indians boarded ships in the harbor and dumped 342 chests of British tea into the water. They weren’t just protesting a tax on tea—they were rejecting the idea of taxation without representation and centralized control by a distant empire. That act of defiance would become one of the sparks that ignited the American Revolution. Fast forward to today: a different kind of rebellion is underway. But this time, it’s not against a monarchy—it’s against a monetary system controlled by central banks, governments, and entrenched financial institutions. And the protest doesn’t take the form of crates tossed into harbors. It’s digital. It’s global. And it’s called Bitcoin. The Boston Tea Party: A Revolt Against Monetary Tyranny At its core, the Boston Tea Party was about sovereignty. The American colonists were being taxed by a government in which they had no representation. Worse, the British East India Company was granted mono...