shadowfolio

Guides

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

  1. Pick what to trade. Name one ticker, or a list where each is held only while above its own average.
  2. Pick the fallback. Cash at 0%, or a fund you name for idle money, such as a Treasury-bill ETF.
  3. Pick how often to check. Daily reacts fastest; weekly or monthly trades less and pays fewer costs.
  4. Run it. Compare the return and max drawdown with the benchmark; trend rules often aim to cut drawdowns rather than raise returns.
  5. 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 ChatGPTSpreadsheetCode (Python and a data library)Asking ChatGPT alone
You describe the rulesIn plain English; it asks for anything you left openAs formulas, one column per ruleAs a programIn plain English
PricesEnd-of-day prices for US stocks and ETFs, refreshed dailyYou download and paste themYou fetch themNone: it can't run your rules on real prices without a tool
ResultsReturn, max drawdown, Sharpe, win rate, trades, curve against a benchmarkWhatever you buildWhatever you buildEstimates from memory, which can be wrong
Forward trackingYes: updated after every US close from the day you saveOnly if you update it by handOnly if you schedule itNo
LimitsDaily closes only; US stocks and ETFs; last 12 monthsSlow for many tickersTakes time to write and checkNo 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.

More guides