Skip to content
The Casebook · An idea an AI invented

Buy ahead of inferred earnings spike, above 50-day average

Find the bar in the last 80 bars with the largest volume*abs(gap) spike (earnings proxy). If latest bar is 58-62 trading days after that spike, close above 50-SMA, enter long at close. Stop = entry - 1.5*ATR(14). Target = entry + 2.0*ATR(14).
Why the AI thought it might work

Stocks exhibit abnormal positive returns in the days before earnings announcements as investors position for the attention-driven event premium; earnings cycles are periodic (~63 trading days) and detectable from the recurring volume/range spike pattern in a single stock's bars. Buying roughly 5 days ahead of the inferred next spike captures the pre-announcement attention premium without needing the calendar.

VerdictTested Nov 22, 2026

Killed by costs

There is something there before trading costs; after them, too little is left to count (under 0.04R a trade).

  • +0.062R a trade before costs, −0.063R after the spread and the selection haircut.
Trades on the laggards
388

42 large US stocks, 15 years

Per trade, after costs
−0.063R

Before costs +0.062R

Bar to clear
t > 2.95

By trade and by day, sized to 362 rules

What the numbers say

Across 388 laggard trades the rule made 0.062R a trade before costs and −0.063R after them. Bull markets gave −0.028R and flat markets −0.275R; bear markets gave 0.675R on only 10 trades. The pre-cost edge is thin and costs erase it, so the verdict is killed by costs.

How it was tested

The rule as written, coded once, run on every stock the same way.

Side
Long
Time limit
Exit at the close after 30 trading days, unless the stop, the target or its own exit comes first
Bar to clear
t > 2.95, by trade and by day, sized to the 362 rules in the search it came from
Prices
15 years of daily bars through 2026-11-20; judged 2026-11-22

The evidence

The laggards decide: 22 large stocks that lagged or fell, where hindsight can't flatter a rule. Today's winners sit beside them to show what survivorship would add.

MarketTradesPer tradet, by tradet, by dayRandom datesWinners, per trade
Bull294−0.028R−0.31−0.63 · 266d−0.121R · beats 85%+0.085R
Flat84−0.275R−1.75−1.22 · 70d−0.060R · beats 15%+0.384R
Bear10+0.675R1.571.57 · 10d+0.030R · beats 90%+0.984R
All388−0.063R−0.104R+0.169R

R is the result per trade in units of the risk taken (entry to stop). Costs are each stock's own trading spread (median 7.8 bps) plus 0.045R for the fills a real order wouldn't get. “By day” groups trades opened the same day, so a rule that fires on the same dates for every stock counts as a few events. “Random dates” places the same plan on random days of the same stocks in the same kind of market, 20 times; the idea must beat 95% of those draws.

The scanner we wroteShow the code
from decimal import Decimal

from core.domain import Bar
from strategies.indicators import atr, sma
from scanners.base import Candidate


class PreEarningsRunupProxyLong:
    name = "pre_earnings_runup_proxy_long"
    description = "Long 2-6 bars before the next earnings date inferred from the measured spacing of this stock's prior volume*gap spikes, above a rising 50-SMA."

    def __init__(self, spike_window: int = 80, min_interval: int = 55, max_interval: int = 75,
                 lead_min: int = 2, lead_max: int = 6, swing_lookback: int = 10,
                 atr_buffer: float = 0.25, rr_target: float = 1.6,
                 min_spike_ratio: float = 4.0, max_runup_atr: float = 2.5) -> None:
        self._win = spike_window
        self._imin = min_interval
        self._imax = max_interval
        self._lead_min = lead_min
        self._lead_max = lead_max
        self._swing = swing_lookback
        self._buf = atr_buffer
        self._rr = rr_target
        self._ratio = min_spike_ratio
        self._max_runup = max_runup_atr

    def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
        n = len(bars)
        if n < 220:
            return None
        i = n - 1
        closes = [float(b.close) for b in bars]
        opens = [float(b.open) for b in bars]
        lows = [float(b.low) for b in bars]
        vols = [float(b.volume) for b in bars]

        # Earnings-proxy score: relative volume * absolute overnight gap
        scores = [0.0] * n
        for k in range(21, n):
            prev = closes[k - 1]
            if prev <= 0:
                continue
            avgv = sum(vols[k - 20:k]) / 20.0
            if avgv <= 0:
                continue
            scores[k] = (vols[k] / avgv) * abs(opens[k] - prev) / prev

        def argmax(lo: int, hi: int):
            lo = max(lo, 21)
            hi = min(hi, i)
            if lo > hi:
                return None
            best = lo
            for k in range(lo, hi + 1):
                if scores[k] > scores[best]:
                    best = k
            return best

        base_vals = sorted(s for s in scores[max(21, n - 250):] if s > 0)
        if len(base_vals) < 50:
            return None
        median = base_vals[len(base_vals) // 2]
        if median <= 0:
            return None

        # Most recent spike
        s1 = argmax(i - self._win + 1, i)
        if s1 is None or scores[s1] <= 0:
            return None
        if i - s1 < 40:
            return None
        r1 = scores[s1] / median
        if r1 < self._ratio:
            return None

        # Prior spike -> measured interval
        s0 = argmax(s1 - self._imax - 5, s1 - self._imin + 5)
        if s0 is None or scores[s0] <= 0:
            return None
        r0 = scores[s0] / median
        if r0 < self._ratio * 0.75:
            return None
        interval = s1 - s0
        if interval < self._imin or interval > self._imax:
            return None

        expected = s1 + interval
        lead = expected - i
        if lead < self._lead_min or lead > self._lead_max:
            return None

        # Event must not have already happened (no comparable spike since s1+40)
        for k in range(s1 + 40, i + 1):
            if scores[k] >= 0.5 * scores[s1]:
                return None

        # Optional third cycle for consistency
        consistency = None
        if s0 - self._imax - 5 >= 21:
            sm1 = argmax(s0 - self._imax - 5, s0 - self._imin + 5)
            if sm1 is not None and scores[sm1] / median >= self._ratio * 0.75:
                interval2 = s0 - sm1
                if self._imin <= interval2 <= self._imax:
                    consistency = abs(interval - interval2)

        # Trend filter
        sma50 = sma(closes, 50)
        sma50_prev = sma(closes[:-10], 50)
        sma200 = sma(closes, 200)
        if sma50 is None or sma50_prev is None or sma200 is None:
            return None
        sma50 = float(sma50)
        sma50_prev = float(sma50_prev)
        sma200 = float(sma200)
        close = closes[-1]
        if close <= sma50:
            return None

        atr_val = atr(bars, 14)
        if atr_val is None:
            return None
        a = float(atr_val)
        if a <= 0:
            return None

        # Don't chase: drift must not already be exhausted
        runup = close - closes[-11]
        if runup > self._max_runup * a:
            return None

        # Structural stop: recent swing low minus small ATR buffer
        swing_low = min(lows[-self._swing:])
        stop_f = swing_low - self._buf * a
        if close - stop_f < 0.6 * a:
            stop_f = close - 0.6 * a
        if close - stop_f > 1.5 * a:
            return None
        if stop_f <= 0:
            return None

        entry = bars[-1].close
        stop = Decimal(str(round(stop_f, 4)))
        risk = entry - stop
        if risk <= 0:
            return None
        target = entry + Decimal(str(self._rr)) * risk
        rr = (target - entry) / risk
        if rr < Decimal("1.5"):
            return None

        # Scoring
        if consistency is None:
            cyc_score = 10
        else:
            cyc_score = max(0, 35 - int(consistency * 4))
        spike_score = min(25, max(0, int((min(r1, r0) - self._ratio * 0.75) * 2.5)))
        trend_score = 0
        if sma50 > sma50_prev:
            trend_score += 10
        if close > sma200:
            trend_score += 5
        if sma50 > sma200:
            trend_score += 5
        prox_score = max(0, 20 - 6 * abs(lead - 4))
        strength = max(0, min(100, cyc_score + spike_score + trend_score + prox_score))

        thesis = (
            f"Earnings-proxy spikes {interval} bars apart (last {i - s1} bars ago); next event projected in ~{lead} bars. "
            f"Long into the pre-announcement attention premium above the 50-SMA; stop under {self._swing}-bar swing low. "
            f"Exit before the projected event day if not already at target."
        )
        return Candidate(
            ticker=ticker,
            side="buy",
            entry=entry,
            stop=stop,
            target=target,
            risk_reward_ratio=rr.quantize(Decimal("0.01")),
            signal_strength=int(strength),
            thesis=thesis,
        )

Hypothetical results from our own backtest of the rule as restated, on 42 large US stocks over 15 years. Past performance, real or simulated, does not predict future results. Research and education only; not investment advice.

Have an idea of your own?

Describe it in plain words and get the same honest test in about a minute.

Run the Gauntlet
Buy ahead of inferred earnings spike, above 50-day average: Killed by costs · EdgeProven