# Trend following on crude oil (WTI spot, daily, 1986-2026) - specification (RIP Backtest protocol v1.0 plus the 8 Oct 2026 rules)

Specification written and **frozen 2026-11-07 (approved by the owner the same day: "Da, îngheață și rulează"; draft 1 unchanged)**, before any moving average, momentum value, signal or trade was computed on crude oil. Once frozen, any change of a rule is documented and treated as a separate test; bugs may be fixed.

## Why this test, and what was looked at before
- **Chosen by the owner** on 2026-11-07 ("Trend following"), after noting that the site had no crude oil test, from three proposals (trend following on daily data, the EIA inventory report, the opening-range breakout).
- **The idea:** crude oil is the market best known for long trends (1990, 2008, 2014, 2020), and trend following is what commodity funds do. We test two of the most common rules: the **200-day moving average** (the same rule as our SPY test) and **12-month time-series momentum** (Moskowitz, Ooi and Pedersen, "Time series momentum", Journal of Financial Economics, 2012, who found it in crude oil among 58 futures markets).
- **Why it might not (written before the run):** oil also has violent reversals (1991, 2008, 2020) that hurt slow rules; our price is the spot price, which ignores the roll yield of futures; and trend rules have done poorly on most markets we tested.
- **Looked at before (disclosed):** no crude oil data has been used on the site; the 200-day average on SPY (buried), many trend rules on other markets (buried); the broad history of oil prices is common knowledge. The data was checked before this draft (rows, missing days, the negative price of 2020-04-20, the largest moves), without computing any indicator or return.

## Instrument and data
- **WTI crude oil spot price, Cushing, Oklahoma**, daily, from the US Energy Information Administration via FRED (series DCOILWTICO), downloaded by the owner on 2026-11-07 (`data_oil/dcoilwtico_fred_raw.csv`, SHA-256 90c95c17a2cdb9a3...; 10,654 weekdays from 1986-01-02, 9,537 with a price). **Used from 1986-01-02 to 2026-10-30** (the last October price); later days stay unseen.
- **Days without a price are skipped, never filled** (1,117 weekdays, in gaps of at most 9 weekdays, most in 1999 and 2003; every month has prices). A "day" below is a day with a price.
- **One close a day, no open, high or low.** Signals use the close; trades fill at the **close of the next day with a price**.
- **Not a tradable price.** Futures and oil ETFs earn or pay the roll between contracts, which the spot price does not include; this is stated in the article. Results are the trend of the price, not of a product.
- **The negative price (2020-04-20, -36.98):** kept. Results per trade are computed from the entry and exit prices only; a trade entered at a price of $5 or less would be reported in dollars only (none is expected).

## Rules (four variants, fixed now)
- **MA200-L:** long when the close is above its 200-day average (the plain mean of the last 200 closes with a price), flat when below.
- **MA200-LS:** long above, short below.
- **TSM-LS (12-month time-series momentum):** at the last day with a price of each month, compare that close with the last close of the same month a year earlier; positive: long for the next month, otherwise short. The position changes only at month ends.
- **TSM-L:** long when the 12-month change is positive, flat otherwise.
- A change decided at the close of day t fills at the close of the next day with a price; a reversal closes and opens at that fill. No stop, no target. A position open at the end closes at the last close used.

## Costs
- **0.05% of the price per round trip** (about one tick of slippage on each side and a commission on a crude oil future at $60); 0.15% as a scenario. No roll cost (see above). The verdict is that of 0.05%.

## Results, periods, gates, control
- **Unit:** % per trade of the entry price (long: exit / entry - 1; short: 1 - exit / entry), net of costs; dollars per barrel shown alongside.
- **Periods (by entry date):** development 1986 .. 1999; validation 2000 .. 2012; holdout 2013 .. 2026-10-30. **The holdout has not been used by any test on the site** (fresh), though the shape of oil prices since 2013 is widely known.
- **Six gates per variant:** validation profit factor >= 1.2; at least 50 trades in each period; development **t >= 2.5** (trend rules are the most tested family 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.
- **Matched control (shifted holdings):** each variant's real position series (long, short or flat on every day) shifted as a whole by one random circular offset of at least 5% of the days (whole months for the TSM variants), then traded on the real prices with the same fills and costs; 500 runs, seeds 1000 + run. It keeps the number of trades, their lengths and the long/short mix and breaks only the timing. Statistic: average net % per trade.

## Also reported (descriptive, after the gates)
Long and short separately; by year and by period; win rate with its Wilson interval; holding days; time in the market; the largest trades and the worst open loss at a close; the 2008 and 2014 and 2020 collapses; without the 10 and 20 best trades; the 0.15% cost; a fill at the signal day's close instead of the next day; results in dollars per barrel; the spot price itself over the same years, for reference.

## Engine and self-test (before the run)
New engine `wti_lib.js`, an independent re-implementation `wti_ref.js`, and `wti_selftest.js`, which must pass before any result is printed: hand-worked days (the average, a crossing, the next-day fill, a reversal, the long-only exit, a skipped missing day), the month-end momentum on a hand-made series (including a month with missing days), the negative-price day inside a trade, the costs; the engine equal to the reference trade by trade for all four variants on the real data; the control at offset 0 reproducing the real trades; and a mutation check (average length, momentum look-back, fill day) that must make the test fail. `wti_run.js` refuses to run unless the self-test passed on the current code and this file is frozen.

## Before the article
Results go to the owner first (in Romanian), with every gate. One article, only with the owner's agreement; the FRED price file is public, but we link to it rather than republish it.

## Reading the result
"Buried" or "Inconclusive" mean a statistically convincing edge was not demonstrated; neither is proof that none exists. One market, the spot price (not a traded product), two rules in their usual form.

## Log
- 2026-11-07: draft 1 written after the data check. Nothing computed.
- 2026-11-07: frozen (draft 1 unchanged), approved by the owner ("Da, îngheață și rulează"). SHA-256 of the frozen text (before this log grew): 3ad39a56c48eb4a77c48200e699d8ec66bd155bd7ecd8f9217ddd15ba7a1ec50.
- 2026-11-07, before any result: wti_selftest.js passed (the hand-worked expectations of three checks were corrected by hand in the test itself before its first run; hand-worked days, month-end momentum with missing days, the negative price inside a trade; engine = independent reference trade by trade for the four variants; control at offset 0; three mutations detected). Counts only: MA200-L 159 trades, MA200-LS 317, TSM-L 34, TSM-LS 68.
- 2026-11-07, the run (`node wti_run.js`, once, outputs in `wti_out/`): **all four Buried.** MA200-L 2/6 (159 trades, +1.40% a trade, 31% winners, control 40th percentile, negative without the 10 best, too few trades in two periods); MA200-LS 1/6 (+0.22% a trade, shorts -152% summed, holdout -77%, control 53rd); TSM-L 2/6 (34 trades, +4.28% a trade, control 36th); TSM-LS 1/6 (68 trades, +0.46%, control 50th). The same holdings shifted in time did as well or better: the rules did not time oil better than chance; a few long trends (1999-2000, 2007-08, 2020-21) made the totals. Nothing was rerun or changed.
- 2026-11-07: the owner asked for the article ("Yes, write it"). Published from the outputs of the single run, unchanged, with a new Energy market page.
