Custom Losses, Search Spaces, and Samplers for Trading Strategy Hyperopt
Summary
This guide explains advanced ways to configure strategy hyperoptimization in Freqtrade. It shows how to define a custom loss function, which receives trade results and backtest context and returns a score where lower values are preferred. The example combines trade count, total profit, and average trade duration, illustrating how an objective can encode several preferences. The guide also lists the data and configuration available to the loss function and advises keeping it efficient because it runs once per optimization epoch.
Additional sections describe overriding parameter spaces for return-on-investment schedules, stop losses, trailing stops, and maximum open trades; creating parameters dynamically; and selecting an Optuna sampler. It compares categorical, integer, and continuous search dimensions, recommending bounded decimal precision when full precision is unnecessary. These are implementation techniques, not evidence that optimization finds robust live strategies. Objective design, parameter ranges, sampler choices, and backtest quality remain the user’s responsibility, and the page does not discuss safeguards against overfitting in depth.
Key ideas
- A custom hyperoptimization loss can combine trade count, profit, and trade duration into a single score.
- The loss function receives trade-level results alongside backtest configuration and statistics.
- Strategy authors can override parameter spaces for risk and return settings.
- Optuna samplers can be selected through a strategy’s hyperoptimization configuration.
- Limited-precision decimal dimensions can reduce search complexity when finer precision is unnecessary.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.