This is an archived documentation site for release 2.2. For the latest documentation or to access any other site features, please return to www.quantrocket.com

Global Trading Blog

What happens when strong stocks gap down at the open? A well-known trading strategy is to buy the gap, expecting mean reversion. This post uses Zipline to explore down gaps and finds a profitable strategy based on selling, not buying, the gap.

Buy the gap?

Buying stocks that gap down is a common trading strategy. The reasoning behind the strategy is that bad news causes traders to enter sell orders overnight which execute in tandem at the open, causing a temporary liquidity shock which drives down the opening price. The selling pressure immediately exhausts itself, however, leading the stock to recover through the remainder of the session. The strategy typically targets stocks in an uptrend, expecting that traders will buy the dip.

I use Zipline with QuantRocket's 1-minute US stock data to backtest a buy-on-gap strategy. I first screen the daily universe of 8,000 listed stocks using the following criteria:

  1. common stocks only (no ETFs, ADRs, or preferred shares)
  2. liquid stocks only (top 10% by dollar volume)
  3. closed above their 20-day moving average
mavg = SimpleMovingAverage(
    window_length=20, inputs=[EquityPricing.close])

are_common_stocks = SecuritiesMaster.usstock_SecurityType2.latest.eq(
    "Common Stock")
are_liquid = AverageDollarVolume(window_length=30).percentile_between(90, 100)
are_above_mavg = EquityPricing.close.latest > mavg

pipeline = Pipeline(
    screen=(
        are_common_stocks
        & are_liquid
        & are_above_mavg
    )
)

For the stocks that pass the screen, I use intraday data to identify which stocks gapped down at least 1 standard deviation below the prior day's low:

today_opens = data.current(context.candidates.index, 'open')
prior_lows = context.candidates["prior_low"]
stds = context.candidates["std"]

# find stocks that opened sufficiently below the prior day's low
gapped_down = today_opens < (prior_lows - stds)

assets_to_buy = context.candidates[gapped_down]

I buy the stocks 1 minute after the open and hold until the close, resulting in the following equity curve:

Sell the gap

The performance of the buy-on-gap strategy is so bad, it suggests a good strategy. Why not simply reverse the sign of the trade and go short instead of long?

I reverse the rules and indeed find a profitable strategy. From 2014-2020, the Sharpe ratio is 1.30 and the annual return is 10%:

Experimenting with parameters, I make two observations:

  • The strategy works better on large-cap stocks than on small-cap stocks. Perhaps this is because small-cap stocks are more subject to liquidity shocks, which tend to mean-revert.
  • Entering positions 5-10 minutes after the open works better than entering immediately after the open. This suggests that some mean reversion occurs immediately after the open before the stock continues falling.

Big gaps vs small gaps

If a sell-on-gap strategy works better than a buy-on-gap strategy, why is the buy-on-gap strategy so well-known?

Most buy-on-gap strategies utilize a rule to limit the size of the down gap, but it turns out that I inadvertently omitted such a rule in my original backtest. As a result, my original strategy targeted large down gaps.

I revise the buy-on-gap strategy to target smaller down gaps by requiring that stocks not only closed above their 20-day moving average the prior day, but also open above the moving average on the day of the down gap. This produces a positive equity curve:

The difference in price action following small gaps vs large gaps makes intuitive sense. A small down gap leaves the uptrend intact; thus the gap is a buying opportunity. In contrast, a large down gap violates the uptrend and often signals more serious trouble; moreover, because of the prior uptrend, the stock that is now in trouble has room to keep falling.

Conclusion

Stocks tend to recover after small down gaps and keep dropping after large down gaps. This knowledge can be used to develop trading strategies on both the long and short side.

This post also demonstrates the serendipity of quantitative research. Sometimes you discover useful trading ideas by accident while exploring a different idea. Even implementation errors occasionally provide helpful insights into how markets behave.

Explore this research on your own

This research was created with QuantRocket. Clone the sell-gap repository to get the code and perform your own analysis.

quantrocket codeload clone 'sell-gap'

QuantRocket LLC is not a financial advisor and nothing on this website or in any materials created by QuantRocket LLC should be construed as investment advice. All results are hypothetical unless otherwise noted. Past performance is not indicative of future results.

The material on this website and any other materials created by QuantRocket LLC 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 QuantRocket LLC.

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. Neither QuantRocket LLC 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 QuantRocket LLC 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. QuantRocket LLC 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. Past performance is not indicative of future results.