Quant

Machine learning for finance

Build models that survive real markets: catch overfitting and leakage, validate in time, use trees and boosting well, judge rare-event models with the right metrics and watch for drift.

Read first: Statistics and machine learning

6 concepts7 min read25-question test, from a bank of 33Updated

Concept 1 of 61 min

Overfitting and how to fight it

The rule
A model far better in sample than out of sample has learned noise, so keep a test set never used for any decision.
Worked example

In sample against out of sample

Given
Sharpe in sample3
Out of sample0.3
  1. Kept = 0.3 ÷ 3 = 10%

Only 10% of the apparent quality survives on new data, the signature of overfitting.

The picture
Why it holds

The other defences are a stronger penalty such as ridge's λ, early stopping on a validation set, dropout in neural networks and a sensible learning rate. Testing many variants on the same data makes one look brilliant by chance.

A larger ridge penalty shrinks coefficients towards zero, more bias, less variance; exact zeros come from Lasso. Early stopping halts training when the validation error starts to rise.

Dropout switches off random units during training so they cannot rely on each other, and is switched off at prediction. A learning rate that is too large makes the loss jump around and grow.

Every choice made with validation data leaks a little information, so only untouched data gives an honest final score.

A great backtest that loses money live is the classic sign: the strategy was fitted to noise in the history, which the untouched test period would have exposed.

If training error falls from 0.5 at epoch 10 to 0.3 at epoch 20 and 0.1 at epoch 40, while validation error goes from 0.55 to 0.4 and then back up to 0.5, training should stop at epoch 20.

Watch out
  • Blaming costs or market efficiency for a collapse that overfitting explains.
  • Expecting ridge to set coefficients to zero.
  • Tuning on the final test set.
In the interview
  1. Your model has a great backtest but loses money live. What is the most likely explanation, and how would you have caught it?

  2. You have tried 200 versions of a trading signal and kept the best. How would you know whether it is real?

    A complete answer covers

    • Expect the best of 200 to look good by chance: adjust for multiple testing.
    • Test it on data never used in the search, walk-forward.
    • Check that it is stable across periods and parameters.
    • Prefer a simple signal with an economic reason.

Also in our technical interviews, on camera, with a score.

Concept 2 of 61 min

Leakage and validation in time

The rule
Leakage lets information from the test period or the outcome reach the model, so every feature must be known before the prediction time.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 3 of 61 min

Random forests and boosting

The rule
A random forest averages deep trees grown on bootstrap samples with random feature subsets, while gradient boosting adds shallow trees fitting the errors so far.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 4 of 61 min

Rare events and the right metrics

The rule
On imbalanced data accuracy misleads, so a rare-event model is judged on precision, recall and AUC (area under the ROC curve).

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 5 of 61 min

Distances, explanations and drift

The rule
Distance-based methods such as k-nearest neighbours and k-means need standardised features and suffer in high dimensions, where points become roughly equally far apart.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Concept 6 of 61 min

AdvancedWhy more trees stop helping: the correlation floor

The rule
The variance of an average of B trees with variance σ² and pairwise correlation ρ is ρσ² + (1 − ρ)σ² ÷ B.

The why, the charts, the worked example and the interview questions are in Essentials, with every quiz.

See the plansSign in

Recap

  • A big gap between in-sample and out-of-sample results means overfitting; regularise, stop early, and keep a final test set untouched.
  • Leakage hides everywhere: scaling on the whole dataset, labels that overlap the test period, features known only afterwards, today's index members.
  • Validate financial models walk-forward, with purging and an embargo around each test fold.
  • Random forests cut variance by averaging decorrelated trees; boosting fits the residuals one tree at a time and can overfit if it runs too long.
  • On rare events accuracy misleads: use precision, recall and AUC; small edges can still pay at scale.
Now test it

25 questions on Machine learning for finance

Timed, like the real one, drawn from a bank of 33. Every answer explained.

Test yourself →