Back to knowledge
Data & research8 min read

Machine learning

Feature engineering without leakage

Create useful features from trading data while keeping the future out of the input and the live pipeline reproducible.

Define the feature timestamp

Every feature needs a clear timestamp: the latest information available when a decision is made. Rolling values should exclude the unfinished or future observation according to the execution convention. Lagging a feature is often safer than assuming a bar close was available at its open.

Write the timestamp rule into the feature specification and test it with a tiny hand-checked example.

Fit transformations inside the split

Normalisation, imputation, feature selection, dimensionality reduction, and target encoding can leak distribution information if they are fitted on the full dataset. Fit each transformation on the training segment and apply the frozen object to validation and test segments.

  • Use lagged and rolling features with explicit windows.
  • Keep raw and transformed columns traceable.
  • Test features around session and missing-data boundaries.
  • Record feature version and source columns in the experiment.

Prefer features with an explanation

A feature does not need a perfect economic theory, but you should be able to explain what it measures, when it is available, and why it might relate to the decision. Features that appear only after a large search deserve extra holdout testing.

When a feature disappears in live data, the pipeline should fail safely instead of silently substituting a different value.

Discuss this article

Ask a setup question, share a backtest, or compare notes with other algorithmic traders. Use a display name; your email remains private.

Create an account or sign in above to join the conversation.

Loading discussion…