Building and training a model
The Model stage combines several signals into one prediction. It is optional. You pick a set of features from your saved signals, choose a target to predict, pick one of four model types, set walk-forward validation, and train. A regression predicts a value; a classifier predicts a class probability. Validation is walk-forward, so the model is always scored on data it never saw. The result is one predicted value or one class probability per point in time, and a backtest can read it to gate or size trades.
What the Model stage does
A model fits a statistical relationship from several signal-derived features to a target outcome. It is a rung between a signal and a backtest, and you reach for it when one signal is not enough and you want to combine several into a single number.
The output is one prediction per point in time: a predicted value for a regression, or a class probability for a classifier. You build the model in a Model tab: pick the features, pick the target, pick the type, set validation, train.
You do not need a model to run a backtest. A single signal, read against its EDA, is often enough. Add the Model stage when combining several features earns its keep.
Choosing features
Open the feature picker to add predictors. It opens the signal-selection modal, the same modal that appears everywhere a signal is chosen. It carries three sources:
- Your own signal library.
- The official Backtest.ai signal library.
- An option to browse community signals and clone one into your library.
Each signal you add becomes one predictor. Add as many as the relationship needs.
A feature is a saved signal, written in the Signal language and referenced by its slug. Any signal you can build, you can use as a feature. For example, 20-day annualized realized volatility, saved under a slug, becomes one input:
// Annualized 20-day realized volatility. Save it, then add it as a feature
daily_close = bar.close(sampling=sampling(period="day", time="close"))
returns = log_change(daily_close, 1)
rolling_std(returns, 20) * sqrt(252)Add a second feature the same way, for instance the trailing 1-year IV rank of 30-DTE IV, and the model now has two predictors to weigh.
Choosing a target
The target is what the model learns to predict. Two decisions.
First, what the model predicts:
- A return dataset, where the model learns to predict trade returns. See return datasets for how a reusable trade structure is defined and its outcomes recorded.
- Another signal, where the model learns to predict a market quantity, for instance next-day realized volatility. A signal target needs an anchor plan so its comparison observations are defined.
Second, the kind of target:
- A value to predict, for instance the trade's return. This is a regression.
- A class to predict, for instance whether the trade was a winner. This is a classification, and the model returns a class probability.
The kind you choose selects the model family in the next section. A return dataset is the typical target for a value; a class label is derived from the outcome you are separating.
The four model types
Four types are available, two per family. Pick the one that matches your target and how much you want to read the model's weights.
alpha (regularization strength), l1_ratio (L1/L2 mix)C (inverse regularization strength), penalty, class_weight, l1_ration_estimators, max_features, max_depth, min_samples_leaf, min_samples_splitclass_weightThe tunables are the named controls each type exposes. Set them where they matter and leave the rest at their configured setting.
Regression versus classification
The target choice picks the family. A value target takes a regression type, linear or random forest regression. A class target takes a classifier, logistic or random forest classifier.
Within a family, the choice is interpretability against flexibility. Linear and logistic fits give you a weight per feature you can read directly, so you can see which signal is carrying the prediction and how much. The random forests capture nonlinear interactions between features that a linear fit misses, at the cost of stable, readable coefficients.
This choice also determines which outputs the validation report shows. See model outputs and validation for the family-specific outputs.
Configuring walk-forward validation
Set three things: how much history to train on, how much to test on, and the minimum sample requirement per window.
Validation is walk-forward. The model trains on one window and is scored on the next window, one it never saw, and the process repeats forward through history. This is the default discipline of the stage for all four model types, and it is the reason the report opens with a fold table, one row per window.
The minimum sample requirement guards against windows too thin to fit. A window that cannot meet it is skipped rather than fit on noise.
Why purely out-of-sample
Each fold's score comes only from data the model was not trained on. A model can fit any in-sample history if you let it, so an in-sample score tells you nothing about whether the relationship is real. The out-of-sample score is the only evidence that the model is learning a relationship and not memorizing noise. The model outputs and validation page reads the fold table window by window.
Features and the target must be look-ahead-safe
Every feature and the target are aligned on the union spine with backward as-of fill, and every rolling window inside a feature is observation-count. A feature that reads a value not yet visible at a timestamp silently inflates the fit.
This is the honesty that decides whether a model is worth anything. A daily or bucketed feature is visible only at its session-close label, so its value is not readable earlier in that session. Alignment applies a backward as-of fill: each Signal's most recent visible value carries onto the shared spine, never a future one. See the execution model for how union-spine alignment and no-lookahead work.
A feature that leaks future information produces a walk-forward score that looks strong and a live result that does not follow. If a fold's out-of-sample score looks too clean, check that no feature reads ahead of its own timestamps before you trust it.
Training the model
Run training. The platform fits the model across every walk-forward window and produces a validation report with four outputs. Read that report before you carry the model anywhere.
The report is where you decide whether the model earned a place in a backtest. See model outputs and validation for the four outputs and how to read each one, and using a model in a backtest for reading the prediction into an entry filter or a sizing expression.