Parameter Optimization
Choosing strategy parameters by optimisation risks overfitting. Learn grid and random search, robustness surfaces, walk forward optimisation and sensible defaults.
Almost every trading strategy has parameters: lookback periods, thresholds, stop distances, position size rules. Choosing them by testing many values and picking the best is called parameter optimisation. It is a natural step, but it is also where most overfitting happens. The goal is not to find the single best historical setting, but to find settings that are likely to work reasonably well in the future. This lesson applies the general ideas from Optimization specifically to trading strategy design.
The problem with "best" parameters#
When you test many parameter combinations on the same data, the best one is partly selected for luck. Its backtest performance is biased upward, and the more combinations you test, the larger the bias. See P-Hacking and Multiple Testing.
Search methods#
| Method | Description | Notes |
|---|---|---|
| Grid search | Test every combination on a grid | Simple; expensive with many parameters |
| Random search | Test random combinations | Often as good as grid search with fewer tests |
| Bayesian optimisation | Uses past results to choose promising next tests | Efficient for expensive backtests |
| Genetic algorithms | Evolve parameter sets through selection and mutation | Powerful, high overfitting risk |
Look at the whole surface#
Instead of picking the top result, plot performance across parameter values.
Principles for robust parameters#
- Fewer parameters: each one adds a dimension for overfitting.
- Coarse grids: test values that differ meaningfully (20, 50, 100 days), not every integer.
- Prefer plateaus over peaks.
- Use sensible defaults grounded in reasoning, such as one month or one year lookbacks.
- Check neighbours: a good setting should have good neighbours.
- Combine several settings: averaging signals across parameter values reduces dependence on any one. See Combining Signals.
- Validate out of sample and with walk forward tests. See Walk-Forward Analysis.
Walk forward optimisation#
Optimise on a rolling past window, trade the chosen parameters on the next period, then re optimise. The stitched out of sample results show how the optimisation process itself performs. If chosen parameters jump around wildly between windows, the optimisation is likely fitting noise.
Objective functions#
What you optimise matters:
| Objective | Risk |
|---|---|
| Total return | Encourages excessive risk and leverage |
| Sharpe ratio | Can favour negatively skewed strategies. See Skewness and Kurtosis |
| Return to drawdown | Sensitive to one worst period |
| Multiple criteria | More balanced; harder to compare |
Optimise for robustness and risk adjusted returns, not just profit.
Parameter count vs data#
A rough guide: the more trades and the longer the history relative to the number of parameters, the safer the optimisation. A strategy with 10 parameters and 80 trades is very likely overfit; one with 2 parameters and 2,000 trades much less so.
Frequently asked questions#
What is parameter optimisation in trading?#
Testing different values for a strategy's settings, such as lookback periods or thresholds, to choose those expected to perform well.
How do I avoid overfitting when optimising parameters?#
Use few parameters, coarse grids and broad plateaus of good performance, check neighbouring values, and validate with walk forward and out of sample tests.
Should I always use the best performing parameters?#
No. The best historical values are often lucky; settings in the middle of a stable region of good results are usually more reliable.
Next, learn to test how fragile a strategy is in Robustness and Stress Testing.
3 quick questions on this lesson. Get them all right to finish it.
Turn on JavaScript to take the quiz.
Mentioned in
- Monte Carlo SimulationResearch and Backtesting
- Event-Driven vs Vectorized BacktestingResearch and Backtesting
- Trend FollowingStrategies and Styles
- Bayesian StatisticsMath and Statistics
- Docker and KubernetesTrading Infrastructure
- Model Evaluation and Cross-ValidationMachine Learning