14.8k stars · MIT · v5.0.0 (2026-09-07) · Track this in Scout
Hyperparameter search that samples the promising regions and prunes hopeless trials early — a week of sweeps back as an afternoon.
▶Repo detailsthe review · specs · pros & cons · install
What it is
A hyperparameter optimisation framework. You write a function that scores one configuration; Optuna chooses which configurations to try, using the results so far to sample the promising regions, and prunes runs that are clearly going nowhere before they finish. Every trial is stored in a database, so a study can be paused, resumed and inspected.
What it is good for. The real constraint in strategy research is how many hypotheses you can kill per day, and grid search is the slowest possible way to kill them: entry threshold × stop × target × session, and a full sweep runs thousands of backtests, most of them on parameter values that were obviously bad after the first six months of data. Optuna's sampler concentrates on the regions that are working, and its pruning stops a hopeless trial part-way — together that is usually an order of magnitude fewer full backtests for the same answer, on a CPU box that has other jobs to do. It also fits the tools already in the ledger rather than replacing them: it wraps skforecast's rolling-origin backtest as the objective function, so the thing being optimised is walk-forward performance rather than a curve fitted to the whole history. One warning, and it is the important part: a smarter search finds an overfitted result faster than a dumb one. Everything Edition 6 said about arch's reality check applies double here — the more configurations you try, the more certain it is that the best of them is luck. Optuna finds candidates; it never validates them.
- MIT, pure Python, pandas-friendly, and it wraps around code you have already written rather than asking you to restructure it
- Pruning is the feature that matters on modest hardware — abandoning a bad trial early is where the wall-clock saving comes from
- Studies persist to a database, so a long search survives a restart and every trial stays inspectable in SQL
- It makes overfitting faster. Pair every study with a held-out period and the multiple-comparison test from arch, or you will find a beautiful strategy that is pure search noise
- The dashboard is a separate package and mostly unnecessary — the tables are the useful part, best read in a marimo notebook
- Defining the search space well is a real skill; too wide and it wanders, too narrow and it just confirms what you already assumed
pip install optuna

