Lesson 306 said to count the number of settings tried and write it at the top of the results table. Trials that were thrown away are counted too, because the more trials there are, the larger the part of luck in the best result. In this lab you measure that statement directly in numbers.
The method is simple. We run 1,000 hypothetical teaching rules on synthetic prices built from the start so that no rule can have an edge. Then we see how good the best setting in the sample looks, and what happens when that setting is run on a period that was not looked at. Picking the best of many test results is called multiple testing.
This lesson only runs the experiment. Lesson 589 covers the formulas that raise the threshold to reflect the number of trials. The meanings of in-sample and out-of-sample were covered in Lesson 476 and Lesson 660.
1. Experimental design: synthetic prices with no edge and 1,000 settings
The prices are synthetic data made with a fixed seed. Each period's return is an independent draw from a normal distribution with a mean of 0 and a standard deviation of 0.01. Read as daily data, the annual volatility is about 15.9%. The mean is 0 and past returns carry no information about the next return, so every rule's true Sharpe ratio is 0. The seeds were fixed before writing the lesson, 10 seeds starting from 20261108; the same experiment was repeated 10 times, and every number in the text is written as a median and range.
There are 2,720 periods. The first 200 periods are used only to build the long moving averages, the next 1,260 periods are the in-sample period and the last 1,260 periods are the out-of-sample period. Read as daily data, each is about five years.
The rule is a hypothetical teaching rule. It holds for the next period when the close is above the n-period moving average and, if the trend filter is on, also above the m-period moving average. A state, once changed, is kept for at least h periods. n takes 25 values from 5 to 125 in steps of 5; m takes 5 values, no filter and 50, 100, 150 and 200; and h takes 8 values, 1, 2, 3, 5, 8, 10, 15 and 20. That makes 25 × 5 × 8 = 1,000 settings, and each one is one trial.
The decision is made on the close of period t, and the return is received from period t + 1. Costs and the cash rate are set to 0 (Lesson 585, Lesson 587). The Sharpe ratio is annualized on the basis of 252 daily returns. The 1,000 settings were run in one order shuffled with a fixed seed, and "N trials" means the first N in that order.
2. As trials increase, the in-sample best rises
In medians over the 10 seeds, the best in-sample Sharpe ratio among the first 10 trials was 0.19. With 100 trials it becomes 0.46, and with 1,000 trials 0.66. The rules have no edge at all, yet the best value rose just by adding trials.
| Number of trials | Best in-sample Sharpe ratio | Out-of-sample Sharpe ratio of that setting |
|---|---|---|
| 10 | median 0.19 (−0.47 to 0.83) | median 0.10 (−0.45 to 0.35) |
| 100 | median 0.46 (0.06 to 1.15) | median 0.15 (−0.47 to 0.54) |
| 1,000 | median 0.66 (0.17 to 1.27) | median 0.08 (−0.46 to 0.80) |

Look at the ranges too. With 1,000 trials, the in-sample best ranged from 0.17 to 1.27 depending on the seed. This means that even on data with no edge, a setting with an annualized five-year Sharpe ratio above 1 can be picked.
The in-sample average over all 1,000 settings had a median of −0.15, but it moved from −0.65 to 0.30 depending on the seed. The number of settings with an in-sample Sharpe ratio above 0 also ranged from 4 to 925 depending on the seed. All 1,000 settings hold or leave the same synthetic asset, so the in-sample path of each seed shifts the whole distribution together. The best value at the top is just a value sitting at the end of that distribution.
3. Running the same setting out of sample
The out-of-sample Sharpe ratios of the settings picked in sample had medians of 0.10, 0.15 and 0.08. The in-sample best rose with the number of trials, but the out-of-sample values did not follow that order. The out-of-sample average over all 1,000 settings had a median of 0.09.
Subtracting the out-of-sample average of all settings from the out-of-sample value of the picked setting for each seed, the medians are 0.03, 0.04 and 0.06 for 10, 100 and 1,000 trials. The range for 1,000 trials is −0.62 to 0.42. Grouping the top 10 in sample gives the same picture. Their in-sample average of 0.52 became 0.12 out of sample (medians over the 10 seeds). The correlation coefficient between the in-sample and out-of-sample Sharpe ratios of the 1,000 settings also had a median of 0.04, close to 0. What was picked in sample was mostly that period's luck, and luck does not carry over to the next period.
Looking at one seed alone can lead to a different reading. In seed 20261108, chosen as the first seed before writing the lesson, the in-sample best of the 1,000 was the 106th trial (5-period moving average, 50-period filter, minimum hold of 8 periods, in-sample 0.70). This setting's out-of-sample Sharpe ratio of 0.25 was 0.42 higher than that seed's out-of-sample average of all settings, −0.17. This gap was the largest of the 10 seeds and about seven times the median of 0.06. Had the lesson been written from the first seed alone, it would have left the wrong impression that "the picked setting is still better out of sample."

In this experiment every true Sharpe ratio is 0, so both 0.42 and −0.62 are luck. Note also that the same first seed was sixth from the bottom of the 10 for the in-sample best (0.70), around the middle. One seed can be a typical value for one number and an extreme value for another.
4. When trials resemble each other, the real number of trials shrinks
The 1,000 settings are rules that hold or leave the same asset, so they resemble each other closely. The average correlation coefficient of in-sample returns over 300 randomly chosen pairs of settings had a median over the 10 seeds of 0.75 (0.69 to 0.80). A 5-period and a 10-period moving average hold in mostly the same periods.
So 1,000 settings are not the same as 1,000 independent trials. The number of truly independent trials is much smaller, and the best value also rises less than it would with 1,000 independent trials. Put the other way, counting trials is not enough; you also record how much the trials resemble each other. Lesson 589 shows how to put the correlation between trials into the formula.
5. What to write in the trial record
One seed's numbers are one experiment. So in a synthetic-data experiment, fix several seeds in advance, do not pick a seed you like after seeing the results, and write medians and ranges. Even if a seed fixed in advance happens to be at an extreme, as the first seed in section 3 was, write that fact as it is.
If thrown-away trials are not counted, readers misread which row of the table in section 2 they are standing on. If you ran 1,000 settings and write "best of 100 settings," the reader compares the result with the row that expects about 0.46. The result numbers are values computed under the settings of this experiment and are not a property of any rule.
The record for this lesson is the summary line of the trial record. On one line, write the number of trials (including thrown-away trials), the rough correlation between trials, the best in-sample result and that setting's out-of-sample result, and the out-of-sample average of all trials. For synthetic data, also write the number of seeds and the medians and ranges.
Try it yourself
- From the results table, read the medians of the best in-sample Sharpe ratio and of that setting's out-of-sample Sharpe ratio for 10, 100 and 1,000 trials.
- Compare the out-of-sample medians from question 1 with the out-of-sample average of all trials, and also read the range of the differences computed for each seed. Can you say that what was picked in sample was also better out of sample?
- Read the range over the 10 seeds of the in-sample best with 1,000 trials, and write in one sentence how the first seed's 0.70 should be reported.
- A report wrote "best of 100 settings, in-sample Sharpe ratio 0.9," but 1,000 settings were actually run. What must be corrected in the record?
Answers
First, 0.19 and 0.10 for 10 trials, 0.46 and 0.15 for 100 trials, and 0.66 and 0.08 for 1,000 trials. The in-sample best rose with the number of trials, but the out-of-sample values did not follow that order.
Second, the out-of-sample average of all trials has a median of 0.09. The differences computed for each seed have medians of 0.03, 0.04 and 0.06, close to 0, and for 1,000 trials they range over −0.62 to 0.42, on both sides. There is no basis for saying that what was picked was also better out of sample.
Third, the range is 0.17 to 1.27. Write the number of trials together with the median and range, for example: "best of 1,000 settings on synthetic data with no edge, 0.70; repeating the same experiment with 10 seeds gives a median of 0.66, range 0.17 to 1.27."
Fourth, correct the number of trials to 1,000 and put the 900 thrown-away settings in the trial record too. Then read 0.9 again as the best of 1,000 trials, and write separately the result for a period not used in the picking. If there is no such period, that line is "not checked" under the Lesson 306 verdicts.
Data: synthetic data made with fixed seeds 20261108-20261117 (10 seeds, fixed before writing the lesson), 2,720 periods of returns from a normal distribution with a mean of 0 and a standard deviation of 0.01. The numbers in the text are medians and ranges from repeating the same experiment with the 10 seeds. The order of trials and the pairs of settings used to measure correlation were also fixed with fixed seeds.
