Optimize a Strategy Tutorial

Learn how to systematically improve strategy performance through parameter optimization, walk-forward testing, and avoiding overfitting.

Time required: 30-60 minutes
Prerequisites: Basic strategy with backtest results

Step-by-Step Optimization Process

  1. Identify the parameter to optimize

    Start with one parameter (e.g., RSI oversold threshold). Never optimize multiple at once.

  2. Define test range

    RSI oversold: Test from 20 to 40 in steps of 5. This gives you 5 backtests: 20, 25, 30, 35, 40

  3. Run backtests

    Test each value on same symbol and date range. Record Sharpe ratio for each.

  4. Compare results

    Which value gave best risk-adjusted returns? Not just highest return, but best Sharpe.

  5. Validate out-of-sample

    Test optimal value on different time period or symbols. Does it still work?

Walk-Forward Testing

The professional way to optimize without overfitting:

Walk-Forward Method:

  1. In-Sample Period (Training): 2020-2022 - Optimize parameters here
  2. Out-of-Sample Period (Testing): 2023 - Test with optimal parameters
  3. Validation: If performance holds in 2023, strategy is robust
  4. Roll Forward: Repeat with 2021-2023 training, 2024 testing

Why this works: Tests if strategy works on unseen data, not just data you optimized on. Prevents curve-fitting.

Avoiding Overfitting

❌ Overfitting Warning Signs

  • Perfect or near-perfect results on backtest
  • Strategy has 10+ parameters all finely tuned
  • Works great on one symbol, fails on all others
  • Great 2020-2021, terrible 2022-2024
  • You tested 100+ parameter combinations

✅ Robust Strategy Signs

  • Works across multiple symbols
  • Consistent across different time periods
  • Simple with few parameters (<5)
  • Logical, explainable edge
  • Out-of-sample performance similar to in-sample