Skip to content
The Casebook · An idea an AI invented

Buy quarter-end losers below the 20-day average

Latest bar is within the last 3 trading days of March, June, September or December. Require stock's 60-day return in the bottom decile of its own 300-bar history (60-day return < 10th percentile of its own rolling 60-day returns) and close < 20-SMA. Enter long at close. Stop = entry - 2*ATR(14). Target = entry + 2.5*ATR(14).
Why the AI thought it might work

Fund managers sell YTD/quarter losers before quarter-end disclosure to avoid showing them (window dressing), pushing already-weak names below fair value in the last sessions. The selling is non-informational and compelled by reporting optics; it unwinds in the first days of the new quarter when the pressure disappears.

VerdictTested Nov 22, 2026

Too rare to judge

Too few trades in 15 years to tell anything either way.

  • 0 trades on the laggard stocks in 15 years; 30 are needed to judge.
  • The rule as written never fired on any of the 42 stocks: it may be stricter than you meant.
Trades on the laggards
0

42 large US stocks, 15 years

Per trade, after costs
—

Before costs —

Bar to clear
t > 2.95

By trade and by day, sized to 362 rules

What the numbers say

The rule produced 0 trades on the laggard stocks in 15 years, against the 30 needed to judge. It also never fired on any of the 42 stocks, so there is no R per trade, no market-by-market result and no random-date comparison. The verdict follows from there being nothing to measure; the rule may be stricter than intended.

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
Bull0—————
Flat0—————
Bear0—————
All0———

R is the result per trade in units of the risk taken (entry to stop). Costs are each stock's own trading spread (median 10.0 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, 0 times; the idea must beat 95% of those draws.

The scanner we wroteShow the code
from decimal import Decimal
from datetime import datetime, timedelta
import math

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


class QuarterEndLoserDumpingReversal:
    name = "quarter_end_loser_dumping_reversal"
    description = "Long bottom-decile 60d losers below 20-SMA in the last 3 trading days of a quarter, betting window-dressing supply unwinds next quarter."

    def __init__(
        self,
        ret_window: int = 60,
        history: int = 300,
        pct_threshold: float = 0.10,
        last_n_days: int = 3,
        stop_atr_mult: float = 2.0,
        target_atr_mult: float = 3.2,
        require_quarter_end: bool = True,
    ) -> None:
        self._ret_window = ret_window
        self._history = history
        self._pct = pct_threshold
        self._last_n = last_n_days
        self._stop_mult = stop_atr_mult
        self._target_mult = target_atr_mult
        self._require_qe = require_quarter_end

    def _in_quarter_end_window(self, bar: Bar) -> bool:
        ts = bar.timestamp
        d = ts.date() if isinstance(ts, datetime) else ts
        if d.month not in (3, 6, 9, 12):
            return False
        # Count remaining weekdays in the month after today (calendar-only, no future bars)
        remaining = 0
        cur = d + timedelta(days=1)
        while cur.month == d.month:
            if cur.weekday() < 5:
                remaining += 1
            cur = cur + timedelta(days=1)
        return remaining <= self._last_n - 1

    def scan(self, ticker: str, bars: list[Bar]) -> Candidate | None:
        need = self._history + self._ret_window + 5
        if len(bars) < need:
            return None
        current = bars[-1]
        if self._require_qe and not self._in_quarter_end_window(current):
            return None

        closes = [float(b.close) for b in bars]
        n = len(closes)
        w = self._ret_window
        if closes[-1 - w] <= 0:
            return None
        cur_ret = closes[-1] / closes[-1 - w] - 1.0

        # Distribution of prior rolling 60d returns over the last `history` bars (excluding today)
        hist = []
        for i in range(n - self._history, n - 1):
            base = closes[i - w]
            if base > 0:
                hist.append(closes[i] / base - 1.0)
        if len(hist) < 100:
            return None
        hist.sort()
        idx = max(0, min(len(hist) - 1, int(math.floor(self._pct * len(hist)))))
        p10 = hist[idx]
        if cur_ret >= p10:
            return None

        sma20 = sma(closes, 20)
        if sma20 is None or closes[-1] >= sma20:
            return None

        atr_val = atr(bars, 14)
        if atr_val is None or atr_val <= 0:
            return None
        atr_dec = Decimal(str(atr_val))
        entry = current.close
        stop = entry - Decimal(str(self._stop_mult)) * atr_dec
        if stop <= 0:
            return None
        risk = entry - stop
        if risk <= 0:
            return None
        sma20_dec = Decimal(str(sma20))
        # Target: at least target_mult*ATR, or the 20-SMA reversion level if farther
        reward = max(Decimal(str(self._target_mult)) * atr_dec, sma20_dec - entry)
        target = entry + reward
        rr = (target - entry) / risk
        if rr < Decimal("1.5"):
            return None

        # --- signal strength ---
        # 1. Depth of loss relative to own distribution (0-35)
        spread = max(1e-6, hist[len(hist) // 2] - hist[0])
        depth = (p10 - cur_ret) / spread
        depth_score = min(35, max(0, int(depth * 70)))
        # 2. Stretch below 20-SMA in ATRs (0-30)
        stretch = (sma20 - closes[-1]) / float(atr_val)
        stretch_score = min(30, max(0, int(stretch * 12)))
        # 3. Dumping evidence: last 3 sessions volume vs prior 50-day avg (0-20)
        prior_vol = [float(b.volume) for b in bars[-53:-3]]
        avg_vol = sum(prior_vol) / max(len(prior_vol), 1)
        recent_vol = sum(float(b.volume) for b in bars[-3:]) / 3.0
        vol_ratio = recent_vol / max(avg_vol, 1.0)
        vol_score = min(20, max(0, int((vol_ratio - 0.8) * 25)))
        # 4. Close position in the day's range: absorption of selling (0-15)
        rng = float(current.high - current.low)
        close_pos = (float(current.close - current.low) / rng) if rng > 0 else 0.5
        close_score = min(15, max(0, int(close_pos * 15)))
        strength = max(0, min(100, depth_score + stretch_score + vol_score + close_score))

        thesis = (
            f"Quarter-end window-dressing reversal: 60d return {cur_ret*100:.1f}% is below its own "
            f"10th percentile ({p10*100:.1f}%) and close is {stretch:.1f} ATR under the 20-SMA in the final "
            f"sessions of the quarter. The non-informational loser dumping should unwind early next quarter. "
            f"The wide 2-ATR stop absorbs residual dumping."
        )
        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 quarter-end losers below the 20-day average: Too rare to judge · EdgeProven