Overfitting
Overfitting is choosing rules or settings because they did best on past prices. The past then looks excellent and the future does not match it.
- Level 11 Your Trading Plan
- 第 15 课,共 25 课
- 阅读约 5 分钟
- 2 道题
Overfitting means tuning a system to the prices it was tested on: trying many settings, rules or filters and keeping whatever scored best. Part of any best score is luck that belonged to those prices alone. Level 3 and Level 5 both warned against tuning to the past. This lesson shows it happening, with numbers.
Eight settings of one rule
The example system looks back 20 candles for its breakout. Suppose eight lookbacks are tried and judged on the first three years of the example candles, after costs.
| Lookback | Years 1 to 3, R a trade | Years 4 to 6, R a trade |
|---|---|---|
| 10 | −0.015 | −0.050 |
| 15 | −0.009 | −0.065 |
| 20 | +0.050 | −0.087 |
| 25 | +0.078 | −0.105 |
| 30 | +0.140 | −0.091 |
| 40 | +0.099 | −0.147 |
| 50 | +0.137 | −0.036 |
| 60 | −0.005 | −0.074 |
A lookback of 30 looks best: +0.140R a trade, +26.2R over 187 trades. In the next three years it made −0.091R a trade and lost 15.0R. Every setting lost in those years.
The prices were made with no pattern in them, so every plus sign in the middle column is luck. That is known here by construction. With real prices nobody knows, which is the reason for the next two ideas.
In-sample and out-of-sample
The prices used to choose a setting are in-sample. Prices kept back and used once, after the choice is final, are out-of-sample. Only the second set says anything about the choice. Looking at the out-of-sample result and then adjusting turns it into in-sample data.
Walk-forward
A walk-forward test repeats the split along the data. Choose the best setting on years 1 and 2, trade it in year 3, then choose again on years 2 and 3 and trade year 4, and so on. The traded years, joined together, show what the habit of choosing the best setting would have earned. Here the four traded years lost 11.2R over 185 trades.
A wide plateau is not proof
Level 5 gave a guard: distrust a setting whose neighbours fail. Here the neighbours passed. Lookbacks of 25, 40 and 50 all made money in years 1 to 3, and all lost afterwards. Neighbouring settings share most of their trades, so they rise and fall together. The guard can reject a system and cannot confirm one.
Signs of a fitted system
- Many rules, each with its own setting.
- A filter with no reason behind it beyond the results.
- An equity curve far smoother than the method’s logic would suggest.
- No out-of-sample result, or one that was looked at more than once.
Key points
- Overfitting is choosing settings because they scored best on the tested prices.
- In the example the best of eight lookbacks made +0.140R a trade in years 1 to 3 and −0.091R in years 4 to 6.
- In-sample prices are used to choose. Out-of-sample prices are used once, after the choice.
- A walk-forward test repeats that split along the data and joins the out-of-sample years.
快速检查
这些问题不计入你的测验分数。
Common mistakes
- Trying settings until one works. With enough attempts something always works on the tested prices.
- Using the out-of-sample data twice. After the first look it has become part of the search.
- Adding a rule to remove each losing period. The curve improves and the system stops describing anything real.
- Trusting a wide plateau of good settings. Neighbouring settings share most of their trades, so they tend to succeed and fail together.
Another example
Suppose a rule with no edge is tested in 20 versions, and a version is called promising if it scores better than 19 out of 20 random results would. Each version has a 5% chance of looking promising by luck. The chance that at least one of the 20 does so is 1 − 0.95 multiplied by itself 20 times, which is 64.2%. Nearly two times in three, a search through 20 worthless versions turns up something that looks like a discovery.
Questions people ask
What is overfitting in trading?
Overfitting is shaping a system so closely to past prices that it captures their accidents as well as anything lasting. It happens when many settings, rules or filters are tried and the best-scoring one is kept. The result looks excellent on the tested data and does worse on new data.
What is out-of-sample testing?
It is checking a system on prices that were kept apart while the system was being designed and tuned. The design uses the in-sample prices only. The out-of-sample prices are then used once, and their result is the first fair estimate of how the choice performs.
What is walk-forward analysis?
It is a repeated out-of-sample test. Settings are chosen on one stretch of data and traded on the next, then both windows move forward and the process repeats. The traded stretches together show how the whole habit of choosing and trading would have performed.
Should I optimise my strategy’s settings?
Only with care, and with data kept back. Trying a handful of sensible values and checking the choice on untouched prices is reasonable. Searching thousands of combinations for the best curve is overfitting, and most platform optimisers make that easy to do.
无需账户即可免费阅读课程。登录后 PipCircle 会记住你停下的位置、保存测验分数并颁发徽章。 免费登录
Trading foreign exchange and CFDs carries a high risk of losing money. PipCircle Learn is education and is not investment advice.