What is overfitting?

By Oalgo · Last reviewed

Overfitting means tuning rules so closely to one stretch of past prices that they describe that stretch and little else. They look good in a backtest and often behave differently on new prices.

Chart: example prices, and a line drawn from rules tuned on past prices. The line follows the past prices closely, then drifts away from the new prices after today.PriceRule lineFitsthe pastTodayMissesnew prices
Example prices, made up for this page, not a test result.

Why does overfitting fool people?

#
  • A backtest can be run as often as you like. Each small change to a rule or a setting is another try on the same prices.
  • With enough tries, some settings will fit that period by chance.
  • The version you keep is the one that fit best, so the backtest report looks better than the rules deserve.

What are the signs of overfitting?

#
  • Many rules, filters and exact numbers, each added to fix one past trade.
  • A small change in a setting, such as 14 to 15, changes the report a lot.
  • Very few trades behind the numbers.

How can you check for it?

#
  • Test more than one date range, including ranges you did not tune on.
  • Keep the rules simple, with few settings.
  • Change a setting a little. Rules that work at only one exact value are a warning.
  • Forward test the rules. New prices cannot have been tuned on.

None of these proves the rules will hold up. They make a chance fit easier to spot.

Read next