# The 200-day moving average rule on SPY, daily bars - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-10-21 (approved by the owner the same day, draft 1 unchanged)**. No moving average, signal, trade or equity curve of this test has been computed. What was looked at before writing it: the row counts, date range, gaps and price checks of the data files (below), and the total-return check of Yahoo's Adj Close against our own close-plus-dividends index (end ratios 31.98 and 31.99). Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed.

## Why this test, and where the rule comes from
- **Chosen by the owner** on 2026-10-21 from three stock proposals ("hai varianta 1"): the site's first test on a stock-market ETF.
- The rule is one of the most quoted in investing: hold the S&P 500 while it is above its 200-day moving average, step aside into cash while it is below. Its best-known written form is Mebane Faber, "A Quantitative Approach to Tactical Asset Allocation" (2007), with a **monthly** check of the price against its **10-month** average and T-bills while out; the popular **daily** form compares each close with the 200-day average. It is promoted as giving most of the market's return with much smaller crashes. We test both forms with their usual settings; no other length will be tried after the result.
- **Looked at before on the site:** the golden cross (50/200 crosses) on ES futures daily bars, 2020-2026 (buried). So the S&P 500's path from 2020 is not new to us; the holdout below is stated as partly seen.

## Instrument and data
- **SPY** (SPDR S&P 500 ETF Trust), daily bars, **1993-01-29 to 2026-10-20** (8,489 trading days), from the Yahoo Finance history page saved by the owner on 2026-10-21 (`data_spy/spy_yahoo.html`, extracted by `spy_parse.js` to `spy_daily.csv` and `spy_dividends.csv`, 136 dividends). Close = the traded price (SPY has never split); dividends as listed. Checks: no impossible bar (high below open/close, low above them); the only gaps longer than 4 days are the market closures of September 2001, 2 January 2007 and October 2012 (hurricane Sandy).
- **Total return:** our own index, close plus each dividend reinvested at the ex-date close (Yahoo's Adj Close agrees to 0.05% over 33 years). Signals use the **price** (Close), as on any chart; returns use the total-return index, so dividends are earned while invested.
- **Cash:** the 3-month Treasury bill rate (FRED series DTB3, downloaded 2026-10-21, 363 blank days filled with the previous value), earned each calendar day while out of the market at rate / 360.
- File hashes (SHA-256, first 16 characters): spy_yahoo.html 18cc4bee4d719c13, spy_daily.csv 8de2b35662134fe5, spy_dividends.csv f6a7857257bbd23c, dtb3_fred_raw.csv 0ba63bf126e01aa6.

## Rules
- **SMA-D200 (daily):** SMA = the simple average of the last 200 closes, including today's. If today's close is above the SMA and we are out: buy **at the next day's open**. If today's close is below the SMA and we are in: sell at the next day's open. A close equal to the SMA changes nothing. First signal on the 200th close.
- **SMA-M10 (Faber, monthly):** on the last trading day of each month, SMA = the average of the last 10 month-end closes, including this one. Above: be invested; below: be in cash; the change is made **at the next trading day's open**. First signal at the 10th month-end.
- Long only, all-in or all-out; no stop, no target. A position open at the end of the data is closed at the last close (marked).
- **Two variants: SMA-D200, SMA-M10.**

## Costs
- **0.04% of the price per round trip** (0.02% a side: SPY's one-cent spread is about 0.002% today but was wider in the 1990s, plus slippage at the open), charged on every trade; no commission. Stated as an assumption; a 0.10% scenario is shown, the verdict is that of 0.04%.

## Results, periods, gates, control
- **Unit:** net % per trade (total-return index, entry open to exit open, minus the cost). Also reported, not gated: the whole strategy with cash interest against buy-and-hold SPY (total return): yearly growth (CAGR), worst drawdown (end of day), the share of time invested, the worst year, and how each crash went (2000-02, 2008-09, 2020, 2022).
- **Periods (by entry date):** development 1993 .. 2005; validation 2006 .. 2015; holdout 2016 .. 2026-10-20 (**partly seen**: the S&P 500 from 2020 through the ES golden-cross test).
- **Six gates per variant** (standard): validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.0** (two variants of a strategy not tested before on the site); above the 95th percentile of 500 runs of the matched control; positive without the 10 best trades; holdout net positive. Fewer than 30 trades: Inconclusive. The monthly rule is expected to trade too rarely for gate 2; that is reported as it falls, not changed.
- **Matched control (shifted holding periods):** every real trade moved, all together, by one random circular offset of at least 5% of the trading days, keeping its length in trading days; same costs. 500 runs, seeds 1000 + run. Statistic: average net % per trade. It asks whether the average picks better times to be invested than the same number of holdings of the same lengths at random times (the market's rise is in both).

## Engine and self-test (before the run)
New engine `sma200_lib.js`, independent re-implementation `sma200_ref.js`, `sma200_selftest.js` that must pass before any result is printed: hand-worked SMA and signals (including a close equal to the SMA and the month-end rule), next-open fills, dividends inside a trade, cash interest, costs, the end-of-data close; the reference matched trade by trade on the real data; the control at offset 0 reproduces the real trades.

## Before the article
Results go to the owner first: both variants, every gate, by year, every crash, against buy-and-hold. One article, published only with the owner's agreement.

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge per trade was not demonstrated; neither is proof that none exists. A rule can also fail our gates and still have had smaller crashes than buy-and-hold; the article will show both. One ETF, one data source, the usual settings only.
