Skip to content

Hyperparameter tuning

Choosing model settings on validation evidence: separate fitting, search, refitting and final testing, with chronological assessment for financial forecasts.

Hyperparameter tuning is the process of choosing settings that govern a learning algorithm by comparing candidate configurations on validation evidence. In quantitative finance, those choices can determine whether a forecasting model captures a repeatable relationship or merely wins a search through historical noise.
A decision tree, for example, learns split locations and leaf predictions from training data. Its permitted maximum depth is a hyperparameter: it controls the fitting procedure rather than being a split location learned inside that fit. Other examples include a penalty strength, a learning rate and a minimum leaf size. An automated search still makes a selection; automation does not turn the selected settings into independent evidence of predictive skill.

Fit, compare, choose, refit

For a candidate configuration hh, fit a model f^h\widehat f_h using the training window. Then measure its mean squared error on a later validation set:
MSE⁡V(h)=1nV∑i∈V(yi−f^h(xi))2.\operatorname{MSE}_{V}(h)=\frac{1}{n_V}\sum_{i\in V}\left(y_i-\widehat f_h(x_i)\right)^2.
Here xix_i is the feature vector known at the forecast time, yiy_i is the later target variable, and nVn_V is the number of validation observations. Under a predeclared minimum-MSE rule, choose
h∗∈arg⁡min⁡h∈HMSE⁡V(h),h^*\in\arg\min_{h\in\mathcal H}\operatorname{MSE}_{V}(h),

where H\mathcal H is the allowed candidate set. Specify a tie rule too, such as choosing the shallower tree when scores are equal. The loss, the candidate set and the tie rule are research decisions that should precede the comparison.

Consider a hypothetical model forecasting a future price change measured in basis points. Training uses earlier period blocks 1–6; validation uses blocks 7–8; blocks 9–10 form the final test set. Each block contains many observations. Assume features are available at their forecast times and training labels have completed before each fit.
Candidate settingStipulated validation MSE, squared basis pointsDecision under minimum MSE
Maximum depth 24Not selected
Maximum depth 53Selected
These scores are assumptions for the example, not results from training a model or testing a market strategy. Depth 5 wins because 3 is below 4 under the stated rule. This does not establish that deeper trees generally forecast better, that the difference is statistically reliable, or that the predictions can support profitable trades after costs.
After selection, a predeclared procedure may refit the chosen depth-5 pipeline on all eligible development data in blocks 1–8, then assess it on untouched blocks 9–10. Refit means estimating fresh split locations, leaf predictions and any learned preprocessing using the enlarged permitted dataset. It does not mean searching again on test scores. The earlier validation MSE describes the candidate fitted on the earlier training data, not a measured test error of this refitted model. No final-test score is supplied here.
Synthetic chronological tuning: training blocks 1–6 fit candidates; validation blocks 7–8 choose depth 5 at MSE 3 rather than depth 2 at MSE 4 squared basis points. Refit on eligible blocks 1–8 before assessing untouched test blocks 9–10. No test score is given.
Synthetic chronological tuning: training blocks 1–6 fit candidates; validation blocks 7–8 choose depth 5 at MSE 3 rather than depth 2 at MSE 4 squared basis points. Refit on eligible blocks 1–8 before assessing untouched test blocks 9–10. No test score is given.
Original hypothetical selection diagram. MSE values are stipulated, not fitted market results; period blocks contain many observations. Refitting uses only labels available before the test cutoff.

The search has a budget and a history

A grid search tries every combination in a specified finite grid. A random search samples configurations from specified distributions under a chosen budget. Both require a declared validation design and score; neither automatically protects the final test. These distinctions follow the official scikit-learn search documentation.
For a separate budget illustration, a grid containing 3 depth choices and 2 minimum-leaf-size choices has 6 configurations. Evaluating every configuration on 3 chronological folds requires 18 candidate fits. One final refit makes 19 fits in total, assuming one model fit per configuration per fold, no retries and no additional selection stages. Learned preprocessing belongs inside each fold's fitted pipeline. If a search uses randomness, record its seed as well as its sampling distributions and budget.

Keep rejected configurations and failed runs in the research log. Also record changes to features, label horizons, universes, preprocessing, costs and metrics. Expanding a grid after seeing validation results adds to the search history even if the notebook calls it a new experiment.

The loss-curve and hyperparameter-search lesson develops the training-diagnostics side of this workflow: full access requires membership, with a public preview available.

Assess the tuning procedure in chronological order

Repeated searches can overfit validation evidence. Each score contains sampling noise; choosing settings because their scores look unusually good can select favourable noise along with useful structure. Cawley and Talbot show why the model-selection criterion itself can be overfit. Chronology prevents one kind of information misuse; it does not erase selection bias.
Nested assessment separates the inner search from an outer assessment. Inside each outer training history, use earlier training windows and later inner validation windows to choose settings. Refit the chosen pipeline on that outer history, then predict the subsequent outer assessment block. Repeat according to a rule fixed before reviewing the outer results. Different outer histories may select different settings: the object being assessed is the entire tuning-and-refitting procedure.
The official nested cross-validation example explains this inner/outer separation using nonfinancial data. For historical financial forecasting, preserve time order at both levels rather than copying its shuffled folds. Rolling-origin assessment trains forecasts using preceding observations. Financial labels additionally require availability checks: a row dated before a cutoff can have an outcome that is still unknown at that cutoff. Preprocessing learned from future rows can create look-ahead bias even if the final estimator is fitted on earlier rows.

If outer results are used to redesign the search, those results have become development evidence too. Preserve a separate final interval or genuinely arriving observations for confirmation, and disclose what influenced each version. Nested assessment improves the separation of selection and evaluation; it does not guarantee future performance through changing market regimes.

For the full learning schedule, Time-Ordered Train, Validation and Test Design works through label eligibility, preprocessing and declared refitting rules. The full lesson requires membership; its public preview shows the scope and prerequisites.

Sources

Last updated
  • model selection
  • machine learning
  • validation
  • financial data
← Back to the glossaryBack to top ↑