Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. How to Backtest a Forecast Properly
AI & Machine Learning

How to Backtest a Forecast Properly

Why a forecast that scores well on historical data often fails live, and the walk-forward method that gives you an honest estimate before you commit.

Updated 3 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Backtesting means replaying history as though you were standing in the past, using only what was known then. Random train/test splits leak the future into the past and produce scores that cannot be reproduced live. Walk-forward validation across several origins is the honest method.

The number that does not survive launch

The most common disappointment in forecasting work is a model that scored well in development and visibly worse in production. Usually nothing broke. The development score was simply measured in a way that could never be achieved live.

Backtesting done properly is the cheapest risk reduction available on a forecasting project. It costs compute time and no capital, and it tells you before launch roughly what to expect after.

Why a random split is wrong for time series

Standard machine learning practice shuffles rows and holds some out at random. For time series that is invalid, because it lets the model learn from Thursday in order to predict Wednesday. A real forecast has to be made without knowing what came next.

The damage is not subtle. A model with access to future periods can pick up the shape of a spike it should have had to predict, and report an accuracy that is simply unattainable. Teams then spend months wondering why live performance is worse.

Walk-forward validation, step by step

Walk-forward validation replays history in order. You choose a cut-off, train on everything before it, forecast the horizon you care about, score it, then move the cut-off forward and repeat.

  1. Pick your real forecast horizon. If you order six weeks ahead, test six weeks ahead, not one.
  2. Choose several origins spread across the history, covering different seasons and trading conditions.
  3. At each origin, train using only data available up to that date - including anything used to build features.
  4. Forecast the full horizon, score it, and record each origin separately rather than pooling into one average.
  5. Look at the spread across origins, not just the mean. A model that is excellent in three quarters and hopeless in the fourth is a different proposition from one that is steadily mediocre.

The leaks that hide in feature engineering

Even with correct splitting, information leaks in through features. These are easy to introduce and hard to spot once a pipeline is large.

  • A rolling average computed over the whole dataset before splitting, so every training row has already seen the future.
  • Category averages - mean sales per product - calculated across all time rather than up to the origin.
  • Records updated in place: an order row whose status now reads 'returned' was not marked that way when the forecast would have been made.
  • A price or cost field overwritten with the current value rather than the value that applied at the time.

The last two we find most often in business systems, because operational databases are built to hold current state, not history. If your ERP overwrites rather than versions, the honest answer may be that some features cannot be reconstructed for the past at all. Our note on data leakage goes further into how to spot it.

What the result should be compared against

A backtest score is meaningless alone. It needs a baseline computed over exactly the same origins and horizon, so the comparison is like for like.

Use the method the business actually uses today - the planner's spreadsheet, last year plus a percentage, or a seasonal naive forecast. If the model beats that by a margin too small to change any decision, that is a legitimate finding and much cheaper to learn before the build than after.

A backtest is not there to make the model look good. It is there to tell you what you are buying.

What to promise stakeholders

Live performance is usually a little worse than a careful backtest, even a clean one, because the world keeps changing in ways history did not contain. Presenting the backtest as a floor rather than a promise avoids an awkward conversation three months in.

We would rather show a client a modest, honestly measured improvement that holds than a flattering number that collapses. The second costs far more in trust than the first gains in enthusiasm.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How much history do I need to backtest a forecast?

Enough to cover several repeats of whatever cycle matters - typically at least two full years where there is annual seasonality, so the model sees each season more than once.

How many origins should a walk-forward test use?

Enough to cover the range of trading conditions you expect, ideally including each season. A handful spread across the history tells you far more than one split.

Can I backtest if my system overwrites records?

Partially. Fields that are genuinely historical can be backtested; anything that exists only in current form cannot be reconstructed honestly. Better to exclude it than pretend.

Is a good backtest a guarantee of live performance?

No. Treat it as the best available estimate, expect live results to be slightly worse, and monitor after launch to confirm.

Keep reading

More on AI & Machine Learning

Start here

Want machine learning project details from us?

Tell us what you are trying to predict and roughly what data you hold. We will come back with an honest view on whether machine learning is the right tool, what the work would involve and a realistic cost range. If a spreadsheet would do the job, we will say so.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →