How to backtest the 200-day moving average strategy
The 200-day moving average rule owns an asset only while its price is above the average of its last 200 daily closes, and moves to cash (or a bond fund) when it falls below. In ChatGPT with Shadowfolio, say "backtest holding SPY when it's above its 200-day average, otherwise BIL, checked daily" and you get 12 months of results against simply holding SPY.
Updated · The Open Apps, Inc.
Step by step
- Pick what to trade. Name one ticker, or a list where each is held only while above its own average.
- Pick the fallback. Cash at 0%, or a fund you name for idle money, such as a Treasury-bill ETF.
- Pick how often to check. Daily reacts fastest; weekly or monthly trades less and pays fewer costs.
- Run it. Compare the return and max drawdown with the benchmark; trend rules often aim to cut drawdowns rather than raise returns.
- Try variations honestly. A 150- or 250-day average, or a weekly check, are fair questions; trying dozens and keeping the best is curve fitting. Save the version you'd really follow and let the forward test judge it.
Versions you can describe
Single asset: "SPY above its 200-day average, else cash". Market filter: "hold my 10 stocks only while SPY is above its 200-day average". Golden cross: "buy when the 50-day average is above the 200-day, sell when it isn't". Each is one sentence to Shadowfolio.
Ways to do it
| Shadowfolio in ChatGPT | Spreadsheet | Code (Python and a data library) | Asking ChatGPT alone | |
|---|---|---|---|---|
| You describe the rules | In plain English; it asks for anything you left open | As formulas, one column per rule | As a program | In plain English |
| Prices | End-of-day prices for US stocks and ETFs, refreshed daily | You download and paste them | You fetch them | None: it can't run your rules on real prices without a tool |
| Results | Return, max drawdown, Sharpe, win rate, trades, curve against a benchmark | Whatever you build | Whatever you build | Estimates from memory, which can be wrong |
| Forward tracking | Yes: updated after every US close from the day you save | Only if you update it by hand | Only if you schedule it | No |
| Limits | Daily closes only; US stocks and ETFs; last 12 months | Slow for many tickers | Takes time to write and check | No real data |
Moving-average rules use only closing prices, which is exactly the data Shadowfolio has, so they test cleanly.
Use it in ChatGPT
Add Shadowfolio in ChatGPT (coming soon to the plugin directory), then say:
- Backtest holding SPY when it's above its 200-day average, otherwise BIL, checked daily.
Shadowfolio runs only the rules you describe. It never suggests investments, never gives advice and never places trades.
Questions
- Why 200 days?
- It's roughly ten months of trading and a widely watched convention, not a magic number. Shadowfolio accepts any length up to 252 days.
- Does the backtest need data from before the 12 months?
- Yes. The first day needs 200 days of history, so Shadowfolio keeps about 30 months of prices and tests the most recent 12.
- What about whipsaws?
- When the price hovers around the average, a daily check can buy and sell often. The trade count and costs in the result show how much that hurt; a weekly check is a common fix.