Suppose an investment strategy produced high returns over the past few years. But what if dozens of rules were tested and only the best one was picked? It may be a rule that fit the past well by chance. The important question is whether the rule can hold up in a period it has never seen.
Rules that fit the past too well
Imagine a student who saw the exam questions and answers in advance and memorized the answers. They would score highly on those same questions, but you cannot tell whether they would also do well on new ones. Investment rules are similar. If you keep changing the conditions to match past price movements, even the chance features of that period can end up in the rules.
This problem, where rules are fitted so closely to past data that they do not work well in new situations, is called overfitting. You cannot conclude that a strategy is overfitted just because its past results are good. But you should ask how many rules were changed and tried while those results were being produced.
For example, if someone changes the buying criterion over and over, to 5 days, 10 days, 20 days and so on, and reports only the number with the highest return, you also need to see how the other numbers failed. The more conditions are tried, the more you need to consider the chance that a result that only looks good by luck was picked.
Separate the period that builds the rules from the period that checks them
Let us split the data in time order. The dates and results below are a hypothetical case for illustration. They are not a strategy that was actually tested, and they are not a stock recommendation.
| Stage | Hypothetical period | What you do |
|---|---|---|
| Training period | 2015–2019 | Compare several candidates and build the rules |
| Validation period | 2020–2021 | Compare the candidates and choose the detailed settings |
| Final test period | 2022–2023 | Check the rules set earlier without changing them |
The training period is the data used to build the rules. The validation period is the data used to check which of the candidates to choose. If, during this process, you change the conditions after looking at the validation results, that period no longer counts as fresh, unused data for the final assessment.
The final test period, kept aside until the end, is data you did not look at when you chose the rules. It is often called out-of-sample data. Here, the sample means the range of data used in the analysis. Strictly speaking, the validation period is also out of sample as far as training goes, because it was not used for training. But if you chose the rules after looking at its results, you should keep it distinct from an independent final test period.
A hypothetical case where the return changes
Assume a hypothetical rule was chosen in the training period and then applied unchanged in the final test period. Each period is a separate calculation, and the periods differ in length. Each one starts with $1,000, and we assume there are no deposits or withdrawals, commissions or taxes.
If $1,000 grew to $1,400 in the training period, the return for the whole period is as follows.
(1,400 - 1,000) ÷ 1,000 × 100 = 40%.
If $1,000 became $950 in the final test period, the return is as follows.
(950 - 1,000) ÷ 1,000 × 100 = -5%.
These figures are returns for each whole period, not average annual returns. Because the periods differ in length, you cannot compare 40% and -5% directly to judge which was better each year, or by how much. Still, this is an example of good results from the rule-building stage not showing up in the same way afterward.
You cannot conclude from this result alone that overfitting caused the failure. Market conditions may have changed, or the test period may have been short. Check not only the return but also how large the losses were, how the benchmark did and which costs were left out. Backtest results are not money earned in actual trading.
Moving forward in time and checking several times
With just one split, you may simply have picked a favorable period by chance. That is why some tests move forward in time one step at a time and evaluate at each step. This is called walk-forward testing.
For example, you set the rules using 2015–2019 and apply them in 2020. Next, you use 2016–2020 data to set the rules again, in a way decided in advance, and apply them in 2021. At each evaluation point, use only information that had been made public by then, and do not look ahead at results from later periods when you set the rules.
This process helps you see how a strategy behaves in different periods, but it does not guarantee future returns. If you keep looking at the results and adjusting the length of the training period and the criteria, the periods used for evaluation are in effect also being used for selection. Record which rules you changed and when, along with the candidates you tried, and at the end check the result on data you have not looked at before.
When you look at a strategy in practice
If someone shows you strong performance, first check the start and end dates of the results. Ask whether the strategy was built and changed during that same period, and whether there is a separate period that was not used for selection. When you compare strategies, match the market, the period, the amount invested, deposits and withdrawals, and how dividends and costs were handled.
For example, suppose a loss appeared in the final test period, and the buying criteria were changed after seeing that result and then tested again on the same period. What is wrong with that? The second result has been adjusted with reference to that period. To use it as a new report card, lock in the revised rules first, then check them on a separate period that has not been used for selection before.
Good testing shows how the rules were built and the risks across several periods, rather than a single high return. In the next lesson, we will look at how results change when the calculation includes trading costs and real execution conditions.
Connect selection to final evaluation with a brief record
The table below shows hypothetical inputs for practicing the selection workflow, not real backtest results. Assume candidates A and B were defined upfront, each starting with $1,000 in the same validation period with no deposits, withdrawals, or taxes. Costs are subtracted once from the ending gross amount, never subtracted a second time from an after-cost figure.
| Candidate in validation period | Ending amount before costs | Total costs | Ending amount after costs | Return after costs |
|---|---|---|---|---|
| A | $1,100 | $40 | $1,060 | 6% |
| B | $1,080 | $10 | $1,070 | 7% |
- Before comparing candidates, record the shared period, initial capital, transaction cost method, and selection rule—here, assume the rule chosen upfront is the higher return after costs.
- Pick B in the validation period and lock in the rules, period, stock universe, and cost assumptions. In real research, fix limits such as maximum drawdown and trade count before selecting as well.
- Apply only B to the unseen final test period. If that separate period also starts at $1,000 and ends at $970 before $20 of costs, the net ending amount is $950 and the return is −5%.
- If you revise the rules after seeing −5%, log the change as a new version; rerunning the same final test period does not count as fresh out-of-sample testing.
The hypothetical selection workflow CSV lists each stage, candidate, cost, and result. When auditing your own research, attach the exact rule document, raw data path, and file version so results can be reproduced.
Try it yourself
Problem 1
These are hypothetical inputs, not results run on real prices. Candidates X, Y, and Z were defined at the start and each began the same validation period with $2,000, with no deposits, withdrawals, or taxes. Before-cost ending amounts are $2,300 for X, $2,240 for Y, and $2,260 for Z, while total costs are $120 for X, $20 for Y, and $70 for Z. If you decided in advance to pick the candidate with the highest return after costs, which one do you pick? Applying only that chosen candidate with $2,000 to an unseen final test period gives $2,090 before costs and $30 in costs; what is the final test period return? If you see that result, adjust the rules, rerun the same final test period, and get 8%, can you call that 8% an out-of-sample test result?
Answer 1
Return after costs equals (ending amount before costs − total costs − starting amount) ÷ starting amount × 100. Net ending amounts are 2,300 − 120 = $2,180 (9%) for X, 2,240 − 20 = $2,220 (11%) for Y, and 2,260 − 70 = $2,190 (9.5%) for Z. Although X led before costs at 15%, the upfront criterion is return after costs, so you select Y. In the final test period, Y ends at 2,090 − 30 = $2,060, giving a return of (2,060 − 2,000) ÷ 2,000 × 100 = 3%. The 11% return came from the period used to choose the candidate, while 3% came from the unused period; both are total period returns rather than annualized rates. You cannot call 8% an out-of-sample result: because you changed the rules after seeing 3%, that period has now been used in selection. Log the revised rules as a new version and test them on a separate period not yet used for selection.

