Skip to content
All library documents

Backtesting a Long-Only Moving Average Crossover on AAPL

Article QuantStart

Summary

This tutorial implements a long-only moving average crossover strategy in a pandas-based research backtester. It compares a short simple moving average with a longer one, enters when the short average is above the long average, and exits when it falls below. The example uses AAPL closing prices, 100-day and 400-day windows, and a portfolio that buys a fixed 100 shares. Trades are valued on a close-to-close basis, and the tutorial plots prices, signals, and the resulting equity curve.

The historical illustration covers the period from 1990 to 2002 and reports five completed round trips and an overall loss. The author attributes the outcome partly to AAPL's early weakness and the slow response of the long lookback during the later rise. This is a single-stock demonstration, not evidence of general strategy performance. The implementation depends on an earlier backtesting framework and legacy Python and pandas interfaces; transaction costs, slippage, and parameter robustness are not evaluated here.

Key ideas

  • The strategy holds a long position when the short moving average exceeds the long moving average.
  • A crossover in the opposite direction closes the position.
  • The example applies 100-day and 400-day averages to AAPL and buys 100 shares per signal.
  • The 1990–2002 illustration loses money across five round-trip trades.
  • Long lookbacks can delay signals, and a single historical example cannot establish robustness.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.