Contact us
Back to knowledgebase

Backtesting

In a backtest, an analyst returns to a series of past dates to estimate how a forecasting method would have performed. At each date he reconstructs the data then on file, issues the forecast on the usual schedule, and compares it with the outcome recorded later.

The historical cutoff applies both to the data used by a model and to the analyst’s choice of model. A forecast that bears the correct issue date can still owe its place in the report to hindsight.

Four forecasts for the same week

A retailer issues forecasts at 9 a.m. every Monday for each of the next four sales weeks, starting the following Monday. On June 1 a new model predicts nine units of one item at one store for the week of June 29. By June 22 it predicts seventeen for that week. The store sells eighteen.

The June 29 column holds four successive forecasts of 9, 11, 14 and 17 units against 18 sold. The outlined diagonal follows forecasts issued four weeks ahead for different sales weeks.

The incumbent forecast twelve units throughout, missing by six each time. The new model missed by nine, seven, four and one. Across the four revisions its mean absolute error was 5.25 units, 12.5% lower than the incumbent’s. Yet the planner had to book the display on June 1. On the only forecast he could use, the new model missed by nine against six, 50% more.

To test forecasts for display bookings, follow the outlined diagonal in the figure. Each Monday supplies a four-week-ahead forecast for a different sales week. The archive needs both dates on every row, alongside the item, location and method. If a planner amends a forecast, retain the original, the amendment and its time. Comparing the two on the amended lines measures what his changes achieved. Comparing amended items with untouched ones mostly reveals which exceptions reached his desk.

Another planner might need the total over the next four weeks. A sale that slips from the first week to the second leaves that total unchanged. Its 90th percentile depends on whether busy weeks tend to follow one another. Given simulated demand paths, add the four quantities on each path and take the 90th percentile of the sums. Adding four weekly 90th percentiles generally gives a different answer.1

Reconstructing the information at issue time

On May 25 the retailer booked a promotion for June 8. On May 29 a competitor cut its price. The survey reporting the cut arrived on June 4. A query for prices and promotions in effect on June 1 would admit the price cut and exclude the promotion. The forecaster issuing the June 1 forecast knew about the promotion alone.

For the June 1 forecast, the retailer could use a promotion booked on May 25 for June 8. A competitor’s price cut took effect on May 29 but reached the forecast feed on June 4.

Now suppose a cancellation came through on May 30. To rebuild the June 1 calendar, take the last revision received for each promotion ID by the cutoff, cancellations included. Then select the active promotions for the target week. Reversing the two operations resurrects the May 25 booking. Where the ERP overwrites the calendar and no copies survive, the analyst can drop the field from both models or start the test at the first reliable snapshot. Giving both models today’s calendar favors whichever can make better use of the advance notice.

The retailer may still have the forecast file it sent its stores that Monday. Compare it line by line with a replay of the incumbent forecast. To trace a suspected leak, remove records received after the cutoff from a test copy and rerun with the same code and random seed. A forecast that changes depended on later data. This test alone will miss a delivery promise overwritten under the original purchase order date.

A return posted on June 12 may revise net sales for the week of June 1. The corrected figure belongs in the eventual score for a forecast of net sales. The June 8 run still has to use the sales figure on file that morning.

Rolling origins and model fitting

In a rolling-origin backtest, the analyst advances the forecast date and reruns the procedure. A retailer might issue forecasts every Monday and refit the model only at month end, using two years of history. A faithful replay carries the fitted parameters through the intervening Mondays. Fitting once before the first test date is legitimate for a model the retailer intends to freeze. Fitting once on the entire archive gives even the earliest forecast the benefit of the final month’s sales.1

A model fitted across stores needs one cutoff for the whole chain. Hold out June in one store and leave June sales in the others, and the model gets to see how the chain-wide promotion went. Even a category average computed before splitting the data can carry that information. Training examples also need time to mature. On June 1, the outcome of a May 18 forecast for June 1–7 is still a week away. In lead-time forecasting, a recent order still in transit has a known age and an unknown receipt date. Discard the open orders and a slow supplier begins to look fast.

A recursive forecast feeds the prediction for week one into week two. Fetch the lagged values from a table of actual sales instead, and by week four the model knows what sold in week three. For a random walk with independent, zero-mean weekly shocks of variance σ², carrying the last observation forward gives a four-week error equal to the sum of four shocks. Its root mean squared error is 2σ. Reading week three’s sales leaves just one shock and cuts the reported figure to σ.

For a launch, the order of the join matters too. Start from the launch list on file at the issue date and attach the sales. Starting from the sales ledger loses every item that never sold. Check receipts to distinguish a stocked item with zero sales from a store that never received it. A seasonal benchmark needs its ordinary fallback for products with no sales history. Count any launches for which a method produced no forecast at all. Omitting them from the report rewards the method for skipping difficult items.

Choosing a model for each SKU

An analyst has two May forecasts on file for every SKU. If he waits for the June sales before choosing which May forecast to keep, every forecast in his report will bear a genuine May date. The choice between them was made in June.

An intermittent item sells either zero units or one unit each week, with equal odds and no dependence from week to week. The rule “always forecast zero” will miss half the time, as will “always forecast one.” Give an analyst four weeks of sales for each SKU and ask him to keep whichever rule made fewer mistakes.

Each cell gives the better rule’s misses in one of sixteen four-week sales histories. Two cells have zero misses, eight have one and six have two. The miss rate on those histories is 31.25%, against 50% expected the following week.

Across the sixteen equally likely histories, the chosen rule makes twenty mistakes in sixty-four forecasts. That is a 31.25% miss rate, or 37.5% fewer misses than either rule alone would average. Next week, either choice still has a 50% chance of being wrong. With a hundred thousand independent SKUs, the reported gain would settle close to 37.5% while the analyst gained nothing on a single item.2

To test the selection rule itself, give it only forecasts whose outcomes were known when the choice was due. A model picked in March for the spring season carries its April mistakes in the score, even if a rival has pulled ahead by then. A team that reselects every Monday can switch sooner, on the evidence available that Monday.

The same problem arises at the analyst’s desk. If a miss at Easter inspires him to add a holiday feature, rerunning that Easter tells him whether the repair worked on the case he designed it for. The following Easter gives the feature a fresh trial. To claim that it works across retailers, he can also reserve entire retailers for testing.

How much evidence is in a year of forecasts?

For each item, issue date and horizon, score both forecasts against the same observation and subtract the incumbent’s loss from the candidate’s. Negative differences favor the candidate. Use absolute error for median sales, pinball loss for a specified quantile, or the continuous ranked probability score for a full distribution. Decide how much each case counts before examining the results. A volume-weighted average can favor a model that improves a handful of large stores at the expense of most small ones.3

Even if weekly sales fluctuate independently around a constant mean with the same variance each week, successive four-week totals overlap. Adjacent totals share three weeks, giving them a correlation of ¾. Two Mondays apart the correlation is ½, and three Mondays apart it is ¼. Compare two distinct constant forecasts for those totals by squared error. Subtracting their squared errors cancels the term in actual sales squared. What remains is linear in the total, so the loss differences have exactly those correlations.

In a run of 52 Mondays there are 51 pairs one week apart, 50 pairs two weeks apart and 49 pairs three weeks apart. Accounting for their covariances gives the mean loss difference an effective sample size of 52² / [52 + 2(51 × ¾ + 50 × ½ + 49 × ¼)] ≈ 13.3. Treating all 52 observations as independent would roughly halve the reported standard error. For other models, inspect the differences in loss over time. A promotion can produce large errors for both models and scarcely move the difference between them.4

For a retailer forecasting the same network of stores each week, first average the differences across stores at each issue date using the agreed weights. Resampling blocks of consecutive issue dates then keeps stores exposed to the same promotion together, as well as neighboring forecasts that share sales. Choose blocks long enough to cover the overlap and any longer-lived effects. If the archive contains a single port closure, show how much the comparison changes when that episode is left out. Resampling the closure a hundred times supplies no more evidence about the next one.

Ma and Fildes tested five methods on Walmart’s M5 data over five 28-day periods. One model forecast each item in each store and summed the quantities. At the item–store level it came first in all five periods. On total sales it went from first in the public leaderboard period to last in the final one.5

Scoring a forecast produced by simulation

A planner asks for the probability of going four weeks without a delivery. The model gives this event a 10% chance, but its interface returns simulated paths. With ten independent paths, the analyst will often see a delivery on every path and report a probability of zero. This happens in about 35% of forecast runs (0.9¹⁰).

The receiving log gives the event a value of one if no delivery arrived and zero otherwise. The Brier score is the squared difference between the published probability and that value. If the model knows the true probability p, publishing it gives an expected score of p(1 − p). Estimating it from M independent paths adds the sampling variance p(1 − p) / M. For the same 10% risk, ten paths score 0.099 on average and a thousand score 0.09009. The second run bought more precision from the same model.

For a planner who actually receives the ten-path estimate, score the number he received. For an analyst comparing the underlying models, use their event probabilities directly if available. There is also a correction for simulation. Let q be the fraction of paths with no delivery. With M > 1 independent paths, subtracting q(1 − q) / (M − 1) from the squared error removes the sampling penalty in expectation.6

What the sales history can verify

A store has ten units, sells all ten and takes no backorders or further deliveries. The sales forecast can be scored against ten. Demand is right-censored. Let D be the quantity customers would request at the going price, assuming their requests do not depend on the quantity on display. Recorded sales are the smaller of D and ten. For this week the likelihood contribution is the probability the model assigned to D ≥ 10. The sales ledger would record ten units in every one of those cases.7

Two models give eight requests a 60% chance. One puts the remaining 40% on ten requests, the other on fifteen. As long as the store stocks ten, the two predict exactly the same distribution of sales. Another year of weekly totals cannot settle the difference. The time of the stockout or a record of unfilled requests might. Imputing lost sales with the candidate’s own forecast would let the candidate supply its own answer.

Discard the sellouts and only weeks with eight sales remain. A forecast of eight can now achieve zero error. Better-stocked stores might reveal more of the demand, though it matters how they got the extra stock. If a manager reserved fifteen units for stores near a festival, those stores had unusual prospects from the outset.

From a backtest to the planning run

Once the team has chosen a candidate, it can issue a shadow forecast alongside the incumbent every Monday. Save what each method produced by 9 a.m. and record any late arrival or missing forecast. When those sales weeks close, the analyst has paired forecasts made from live feeds, under the ordinary deadline, for weeks he could never have inspected during development.

The shadow run still inherits the retailer’s stock policy. Put fifteen units on the shelf in the stockout example and the models finally disagree on something observable. One gives a 40% chance of selling all fifteen, the other gives zero. The retailer could try the larger allocation in comparable stores. To replay such a trial on paper, the analyst would have to supply the missing demand himself and carry the resulting inventory into the following week.8

References


  1. Leonard J. Tashman, “Out-of-sample tests of forecasting accuracy: an analysis and review,” International Journal of Forecasting, 2000. On modeling dependence across periods, see Introduction to Supply Chain, §7.4.7, “High-dimensional forecasts.” ↩︎ ↩︎

  2. Gavin C. Cawley and Nicola L. C. Talbot, “On Over-fitting in Model Selection and Subsequent Selection Bias in Performance Evaluation,” Journal of Machine Learning Research, 2010. ↩︎

  3. Forecast Accuracy discusses the statistical and economic consequences of the scoring rule. ↩︎

  4. Francis X. Diebold and Roberto S. Mariano, “Comparing Predictive Accuracy,” Journal of Business & Economic Statistics, 1995. ↩︎

  5. Shaohui Ma and Robert Fildes, “The performance of the global bottom-up approach in the M5 accuracy competition: A robustness check,” International Journal of Forecasting, 2022, table 1. The comparison above is for the recursive bottom-up model. ↩︎

  6. Christopher A. T. Ferro, “Fair scores for ensemble forecasts,” Quarterly Journal of the Royal Meteorological Society, 2014. The correction above assumes equally weighted draws that are independent conditional on the forecast distribution. ↩︎

  7. Woonghee Tim Huh and Paat Rusmevichientong, “A Nonparametric Asymptotic Analysis of Inventory Planning with Censored Demand,” Mathematics of Operations Research, 2009. ↩︎

  8. The Limited Applicability of Backtesting and Introduction to Supply Chain, §7.4.8, “Functional forecasts.” ↩︎