Random Search for Strategy Parameter Optimization
Random search is a parameter optimization method that samples combinations at random from the allowed ranges, running a fixed number of backtests — the budget — instead of testing every combination. For the same number of trials, random search usually finds a better result than grid search once a strategy has several parameters, because it spends its budget exploring the whole space rather than exhaustively mapping a small one.
Definition
Random search — a search that draws parameter combinations uniformly at random from their ranges, up to a fixed budget of backtests. backtester.run snaps each draw to your step grid and seeds the generator, so runs are reproducible and discrete parameters stay whole-numbered.
How does random search work?
Random search follows a straightforward five-step sequence from setup to ranked leaderboard:
- Define each parameter range. As with grid search: a minimum, maximum, and step per parameter. A step of 1 on an RSI period range of 5–30 gives 26 possible values; a step of 5 gives 6. Every draw will land on a valid step-grid point, so indicator periods and similar discrete parameters always stay at whole-number values.
- Set a budget. The number of backtests to run, capped by your plan's iteration limit — 20 on Free, 100 on Pro, 500 on Quant. Unlike grid search, random search will never exceed this cap regardless of how many parameters or how wide the ranges are.
- Sample at random. For each trial, draw a value for every parameter independently and uniformly from its range, snapping the result to the nearest step-grid point. The combination forms one complete parameter set. backtester.run fixes the random seed before sampling, so the same strategy configuration and budget always produce exactly the same sequence of sampled points.
- Backtest and repeat until the budget is spent, recording the full performance metrics for each sampled parameter set. Every trial is independent — there is no model being updated between samples, which keeps the method simple, fast per trial, and free of assumptions about the shape of the performance surface.
- Rank by objective. Sort the sampled results by your chosen performance metric — Sharpe ratio, Sortino, Calmar, profit factor, or others — to produce a leaderboard of the best parameter sets found within the budget.
Why does random search beat grid search in many dimensions?
The insight comes from a 2012 paper by Bergstra and Bengio that studied hyperparameter search for machine learning models, but the same reasoning applies directly to trading strategy optimization. In most strategies, only a small subset of parameters strongly drives performance. A moving-average period might matter enormously; a signal confirmation threshold might barely shift the result at all. When you run a grid search, you allocate equal trial density to every parameter axis. That means if two of your five parameters do most of the work, the grid wastes a large fraction of its budget testing fine variations of the three parameters that barely matter — hundreds of trials that each differ only in values that hardly move the needle. Random search, for the same total budget, draws independently on every axis with each trial. This means it effectively samples many more distinct values of the parameters that do matter, even though it is not targeting them deliberately. It is not smarter than grid search in any directed sense — it simply distributes its budget more broadly across the whole space, which turns out to be more useful when parameter importance is uneven.
This is why random search is the pragmatic default for medium-sized parameter spaces: three or more parameters, a bounded budget, and no prior knowledge about which parameters drive performance the most. The argument is not that random search is optimal — it is that grid search is systematically inefficient in this setting, and random search avoids that inefficiency at no additional cost. For situations where every trial is expensive and you want to learn from each result before choosing the next point, the next step up is Bayesian optimization, which models the performance surface and uses that model to target the most promising regions.
When should you use random search?
Random search is the right tool in the following circumstances:
- Three or more parameters. Below three, a small grid is affordable and gives you a complete map. Once you add a third parameter, the grid multiplies in size and random search usually covers the space more effectively for the same trial count.
- A fixed time or trial budget. Random search's budget is exactly the number of backtests you ask for — no more, no less. You decide the compute cost upfront and random search fills it with the broadest possible coverage.
- No assumptions about the performance surface. Random search needs no model and makes no smoothness assumptions. If the strategy's performance jumps discontinuously across parameter space — which happens with threshold-based signals — random search handles it just as well as any other region, whereas model-based approaches may get confused.
- Fast backtests. Each trial is independent, so there is no per-step modelling overhead. For strategies that run quickly, random search often finds results as good as Bayesian optimization in less wall-clock time, because the overhead of fitting and querying a surrogate model adds up when individual backtests are cheap.
For very expensive backtests — long intraday histories, multiple symbols, compute-heavy indicators — where every trial genuinely counts, consider Bayesian optimization instead. Bayesian search learns from each result and uses that knowledge to concentrate the remaining budget in the most promising regions of parameter space, which can make a meaningful difference when you only have a few dozen trials available.
Random search and overfitting
Random search tests fewer combinations than a full grid for the same parameter space, which slightly reduces the multiple-comparisons inflation — the phenomenon where the best result across many trials is biased upward simply because more draws were taken, even with no real edge present. A 20-trial random search is less exposed to this than a 500-combination grid, all else equal. But the reduction is modest, not a cure: the winner of any search is still the most favourable result across however many trials were run, and historical selection bias always inflates the apparent performance of the best parameter set. The discipline is the same regardless of search method — re-test the winning parameters on data the search never saw. The standard tool for this is walk-forward analysis, which optimises on rolling in-sample windows and reports performance on the out-of-sample windows that follow each one. If the out-of-sample results broadly match the in-sample results, the parameters generalise; if they collapse, the in-sample search was fitting historical noise. The companion concept is overfitting: understanding how curve-fitting to past data produces strategies that look excellent in backtests but fail in live trading is the most important piece of context for interpreting any optimization result, regardless of the search method used.
Run a random search on your strategy
backtester.run samples parameter combinations across real market data up to your chosen budget and returns a ranked leaderboard — describe the strategy in plain English to get started.
Start free →Frequently Asked Questions
- What is random search in parameter optimization?
- Random search samples parameter combinations at random from the allowed ranges, running a fixed number of backtests (the budget) rather than every combination. With the same number of trials it usually finds a better result than grid search once several parameters are involved.
- Why is random search more efficient than grid search?
- In most strategies only a few parameters strongly affect performance. Grid search wastes trials testing fine variations of parameters that barely matter. Random search spreads its budget across the whole space, so it samples more distinct values of the parameters that do matter for the same number of backtests.
- Is random search reproducible?
- Yes. backtester.run seeds the random generator, so the same strategy, ranges, and budget produce the same set of sampled points every run. Samples are also snapped to your step grid, keeping discrete parameters like indicator periods at whole-number values.
- How many trials should a random search run?
- Set the budget as high as your plan's iteration cap allows for a meaningful search — Free caps at 20, Pro at 100, Quant at 500. More trials give a better chance of finding a strong region; beyond a few hundred, returns diminish unless the space is large.
- When should I choose random over grid or Bayesian search?
- Choose random search when you have three or more parameters and a limited budget. It needs no model and no assumptions, so it is a robust default for medium-sized spaces. Move to Bayesian optimization when each backtest is expensive and you want to squeeze the most from very few trials.