I run a grid search over fast and slow settings and print the best in-sample return, acknowledging this winner probably overfit the random patterns in the past.
def backtest(fast, slow, return_on_test):
return return_on_test
best = None
for fast in range(10, 13):
for slow in range(12, 15):
ret = backtest(fast, slow, return_on_test=5.0)
if best is None or ret > best[0]:
best = (ret, fast, slow)
print("Optimization and its dangers")
print("Best in-sample: %.1f%% (fast=%d, slow=%d)" % (best[0], best[1], best[2]))
Before you run it, say out loud what it will print. Then open the answer.
What it prints
Optimization and its dangers
Best in-sample: 5.0% (fast=10, slow=12)
The best settings in historical data are usually the noise wearing a costume. Search is easy; judging the search is the hard part.