Probabilistic Demand Forecasting and Stochastic Optimisation for Inventory Control
A forecast is only useful if it changes an order. This post follows one product from a quantile forecast to a weekly replenishment decision, simulates a year of trading under three forecasters, and shows why two models with the same point accuracy can leave very different amounts of money on the shelf.
The Gap Between the Forecast and the Order
In most companies the forecast and the order are made by different people. An analyst fits a model and sends over one number per week. A planner takes that number, adds a safety margin, and orders. Both are doing their job well by the measures they are given. The analyst is judged on accuracy. The planner is judged on stock-outs and inventory value. Nobody is judged on whether the forecast was the right input for the order.
I think this is the most expensive handover in supply chain analytics. A model can have the best mean error in the building and still cause stock-outs every time a promotion runs, because it says nothing about how wide the demand distribution is in a promotion week. The planner’s safety margin cannot fix this. It is one number for every week, and the weeks are not alike.
This post follows one product from a demand forecast to a replenishment rule and then through a simulated year of trading. The forecast is a distribution, not a point, scored with proper scoring rules . The decision is the newsvendor’s critical fractile, which reads the quantile it needs from that distribution . The test is a Monte Carlo simulation of inventory cost. Along the way I compare three forecasters that share the same point forecast quality and find that their inventory costs are not the same. The idea that a model should be judged by the decision it feeds, rather than by its error alone, has a growing literature under the names decision-focused learning and prescriptive analytics . This post is a small, concrete instance of it.
Why a Point Forecast Is the Wrong Input
Inventory costs are asymmetric. Running out of a product that sells for a good margin costs far more per unit than holding one unit for an extra week. A symmetric error measure such as root mean squared error (RMSE) treats a shortfall of ten units and a surplus of ten units as equal mistakes. The warehouse does not.
A replenishment rule needs a quantile. If a lost sale costs nine times what a week of holding costs, the rule should carry enough stock to cover demand nine times out of ten. That is a statement about the 90th percentile of demand, not about its mean. A point forecast plus one standard deviation can produce a 90th percentile only if demand is roughly normal with the same spread every week. For most retail products neither holds. Demand is skewed to the right, it is more variable when its level is high, and it is far more variable in promotion weeks .
The fix is to forecast the whole conditional distribution and let the policy read whichever quantile it needs. Writing $D_{t+h}$ for demand $h$ weeks after the forecast origin $t$ and $\mathcal{X}_t$ for everything known at $t$, the object we want is
The one property this distribution must have is calibration: of all the weeks in which the forecast said demand would stay below its 90th percentile, about 90 percent should actually do so . A distribution can be sharp and still badly calibrated. In inventory control that is the worst combination, because it gives confident safety stocks that are wrong.
One Product, Three Years
To keep everything checkable I simulate the product rather than borrow a dataset. Weekly demand follows a seasonal pattern around 120 units, with a 60 percent uplift in promotion weeks, which happen about one week in six. The noise is negative binomial, so demand is skewed and its variance rises with its level. This is the standard choice for retail count data . The first 104 weeks are used for fitting and the last 52 for testing. Promotion dates are known in advance, as they are in practice.
Three forecasters share one seasonal regression and differ only in how they describe uncertainty.
- Forecaster A uses the promotion-aware regression for the mean and a normal distribution with one residual standard deviation for every week.
- Forecaster B uses the same mean, but describes uncertainty with the empirical distribution of the ratio of actual to fitted demand over the training years. Its spread therefore scales with the level, and its shape is whatever the data say it is.
- Forecaster C is the same as A but without the promotion feature, which is what a model fed only sales history would see.
A and B produce identical point forecasts. Their RMSE on the test year is the same to the last digit. Anything that separates them is coming from the tails.
shows the test year through forecaster B’s eyes. Two things are worth noticing. The intervals are wide, because weekly demand for a single product is noisy and the forecaster is honest about it. And they are not equally wide. In promotion weeks the 90th percentile sits far above the median, which is exactly where forecaster A, with its single standard deviation, will be too low.
Scoring the Distribution Before Using It
A quantile forecast is scored with the pinball loss. For a quantile level $\tau$, a forecast $\hat{q}_\tau$ and an outcome $y$,
The loss is small when the forecast quantile is at the right place and it charges more for being too low than too high when $\tau$ is above one half. Averaged over all quantile levels it becomes the continuous ranked probability score (CRPS), which scores the whole distribution at once . Both are proper: a forecaster minimises them in expectation by reporting its true belief, so there is no incentive to hedge. The M5 uncertainty competition used exactly this family of scores to rank distributional forecasts of retail demand .
| Forecaster | RMSE | MAE | CRPS | Pinball at 0.90 | Pinball at 0.95 | Coverage at 0.90 | Coverage at 0.95 |
|---|---|---|---|---|---|---|---|
| A: normal, promotion-aware | 48.7 | 36.9 | 27.2 | 10.7 | 7.0 | 0.85 | 0.90 |
| B: empirical quantiles, promotion-aware | 48.7 | 36.9 | 26.4 | 9.6 | 6.1 | 0.88 | 0.90 |
| C: normal, promotion-blind | 58.0 | 40.5 | 30.6 | 13.4 | 9.7 | 0.88 | 0.90 |
says what RMSE cannot. A and B tie on every point measure and separate on the pinball loss at the 90th and 95th percentiles, where B is about ten percent better. Those two levels are the only part of the distribution the ordering rule will ever look at. Forecaster C is worse on everything, which is the honest price of not knowing when promotions happen.
is the diagnostic I would ask for before any forecast is allowed near an order. With 52 test weeks the curves are jagged, and all three forecasters are a little overconfident in the upper tail. The differences are small on this plot. They will not be small in the warehouse.
The Newsvendor: Where the Forecast Becomes an Order
The simplest model that turns a distribution into an order is the newsvendor. Stock $q$ units before demand $D$ is known. Each unit left over costs $c_o$ and each unit of unmet demand costs $c_u$. The order that minimises expected cost solves
and the answer is a quantile of the demand distribution :
The ratio $c_u / (c_u + c_o)$ is the critical fractile. With a lost sale costing nine times a week of holding, it is 0.9 and the order is the 90th percentile of demand. If a forecaster reports the full distribution, the planner reads that quantile straight off it. There is no safety-stock formula, no assumption of normality, and no separate error model. This is also why the median is almost never the right order. The median is optimal only when $c_u = c_o$.
lets you move the fractile and watch the order slide up the distribution. At 0.5 the order sits at the median and the red shortfall region is large. As the ratio climbs, the order moves into the right tail, the cost curve becomes steep on the left and shallow on the right, and the penalty for ordering too little grows faster than the penalty for ordering too much. The green order from forecaster B tracks the purple true optimum closely across the range, which is what calibration buys.
From One Period to a Year
Real replenishment is repeated. Orders placed this week arrive next week, stock carried over affects next week’s order, and a lost sale is lost for good. The objective over a horizon of $T$ weeks is
with holding cost $h$ per unit per week, shortage cost $b$ per unit, and lead time $L$. Solving this exactly means dynamic programming over a continuous state, which is not practical for thousands of products. The usual approach is a base-stock policy: at each review, order up to a level $S_t$ chosen so that stock covers demand over the lead time plus the review period with the probability given by the critical fractile . When the demand distribution is not standard, the level comes from sampled demand paths and a scenario programme, in the manner of stochastic programming .
Here the lead time is one week, so the policy protects two weeks of demand. Each forecaster supplies its own order-up-to level: the two-week median plus its own estimate of the two-week spread at the target fractile. The rule is identical across forecasters. Only the distribution it reads from differs.
replays the test year. Watch the promotion weeks. Forecaster B raises its order-up-to level before each one, because its spread scales with the level. Forecaster A raises it by less and is more often caught short. Over the realised year B finishes with a cost of 7,671 against 8,188 for A, a saving of six percent, while also losing fewer sales. One year is one draw, though. The next section asks whether that holds on average.
Monte Carlo: What the Policy Costs on Average
I simulate 400 fresh test years from the true demand process and run every policy through each of them. The policies are the three forecasters at nine target fractiles from 0.5 to 0.99, plus a distribution-free policy that uses only the mean and standard deviation. That last one is Scarf’s rule , as restated by Gallego and Moon :
It is the order that minimises the worst expected cost over every distribution with that mean and variance, and it needs no assumption about the shape. Natarajan, Sim and Uichanco extend this family to sets that also fix the asymmetry of demand , and Das, Dhara and Natarajan show how heavy the implied worst-case tails are . I include Scarf’s rule because it is a useful yardstick: it is what you can do when you trust the first two moments and nothing else.
| Policy | Mean annual cost | 95th percentile of cost | Fill rate | Units short per year | Weeks with lost sales | Best fractile | Cost at best fractile |
|---|---|---|---|---|---|---|---|
| A: normal, promotion-aware | 8,118 | 10,705 | 93.8% | 442 | 7.7 | 0.90 | 8,118 |
| B: empirical quantiles, promotion-aware | 7,961 | 10,054 | 94.8% | 367 | 7.0 | 0.90 | 7,961 |
| C: normal, promotion-blind | 9,079 | 11,960 | 92.6% | 523 | 8.3 | 0.95 | 9,052 |
| Scarf, mean and variance only | 8,108 | 10,655 | 94.0% | 426 | 7.3 |
is the result the whole post is built around. Forecasters A and B have identical point accuracy. Over 400 simulated years B costs two percent less, loses 17 percent fewer sales, and has a 95th percentile of annual cost six percent lower. The whole difference comes from the upper tail of the forecast in promotion weeks. Forecaster C costs twelve percent more than B, which is roughly what it costs to not know the promotion calendar. Scarf’s rule, which knows nothing about shape, lands on top of forecaster A. That is no accident. A normal distribution with a fixed standard deviation carries exactly the information Scarf’s rule uses, and no more.
shows the same thing across all targets. Each forecaster traces a curve as the target fractile rises: cost falls, reaches a minimum near the critical fractile, and climbs again as holding cost takes over. Two things stand out. B’s curve sits below A’s throughout the region any retailer would operate in. And the minimum of each curve lands where the theory says it should, at 0.9, except for C, whose best target is 0.95. A forecaster that does not know about promotions has to carry extra stock all year to survive them.
shows the spread, which matters as much as the mean. A policy that is cheap on average and ruinous one year in twenty is not a good policy. B’s cost distribution is the tightest of the four. Its upper tail is where the gain is, because the bad years are the ones with several large promotion weeks in a row, and those are the weeks in which B carries more stock.
Why Two Models With the Same RMSE Cost Different Amounts
The mechanism is simple once the numbers are on the table. Forecaster A uses one standard deviation, about 44 units, for every week. In an ordinary week the true standard deviation is close to that. In a promotion week, with mean demand near 200, it is closer to 75. A’s 90th percentile in those weeks is therefore too low by around 40 units, and at nine units of penalty per lost sale that is where the extra cost comes from. Forecaster B learned the spread as a proportion of the level, so its 90th percentile moves with the mean.
Nothing in RMSE can see this. RMSE averages squared errors of the mean forecast, and the two mean forecasts are the same. The pinball loss at the 90th percentile sees it immediately, because that is the quantity being scored. This is the practical content of decision-focused evaluation: score the forecast on the part of the distribution the decision consumes . Ban and Rudin make the point from the other direction, learning the order quantity directly from features and showing that it can beat forecasting and then optimising when the forecast is misspecified .
What to Report, and in What Order
A credible study of this pipeline reports two sets of numbers and keeps them in that order.
- Forecast scores at the levels the policy uses. Pinball loss at the critical fractile and at one level above it, CRPS as a summary, and coverage at those same levels. A calibration plot like .
- Inventory outcomes from a rolling simulation. Total cost split into holding and shortage, fill rate, weeks with lost sales, average stock on hand, and the spread of cost across simulated years. A frontier like , so that the trade-off is visible rather than summarised.
The simulation should use rolling origins, a fixed horizon, and a realistic retraining schedule, and it should be run on perturbed demand as well as on the fitted distribution, because the forecaster will be wrong in ways the training years did not show. A moment-based rule such as is a sensible companion for that stress test.
Pitfalls I Keep Meeting
- Censored demand. Sales are zero when the shelf is empty, but demand is not. A model trained on sales learns to under-forecast exactly the weeks it most needs to get right, and the stock-outs then feed the next training set. Flag stock-out weeks and treat them as censored.
- Intermittent products. Most items in a long tail sell nothing in most weeks. Croston’s method and its corrections remain the baseline , and count distributions such as the negative binomial handle the zeros where a normal model cannot .
- Leakage. A promotion uplift that was only known after the event is not a feature. It is a leak that inflates every score and vanishes at deployment.
- Scoring the whole distribution when the decision uses one quantile. CRPS is a fine summary, but two forecasters with the same CRPS can differ badly at the 95th percentile. Look at the levels you use.
- Picking the target fractile by hand. The critical fractile is a cost ratio, not a service-level preference. If the business insists on a 98 percent fill rate, it is implicitly stating that a lost sale costs fifty times a week of holding. Say so, and check whether anyone believes it.
Closing
A forecast is a claim about the future. An order is a bet on it. The only test of a demand forecast that matters to a supply chain is whether the bets it supports pay off. In this study two forecasters made identical claims about the mean and different claims about the tail, and the one with the better tail saved two percent of annual cost and a sixth of lost sales without holding more stock on average. The point accuracy measures could not tell them apart. The pinball loss at the 90th percentile could, and so could the simulated warehouse.
Score the distribution, read the quantile the cost structure asks for, and simulate the policy. Model selection by RMSE alone is choosing a forecaster for a job it was never asked to do.