← Back to the lab

Simulation

Medicine supply digital twin (2/14): safety stock

How forecast uncertainty becomes units on the shelf. Where the square root of time comes from, what it costs to go from 95 to 99 %, and why an unpunctual supplier weighs more than variable demand.

By ·

The previous post ended with a forecast and a deviation σ\sigma. Today’s question is practical: a health unit receives medicine every seven days and an order takes another seven to arrive. How much should it order today?

If it orders exactly the forecast, half the time it runs out before the next delivery, because real demand ends up above the average half the time. Safety stock is the buffer that brings that probability down to an acceptable level.

The horizon to cover

What it orders today has to last from now until the delivery after the one it is ordering. That horizon is

H=L+RH = L + R

where LL is the time until this order arrives and RR the time between deliveries. With L=R=7L = R = 7 days, H=14H = 14.

Where the square root comes from

Demand over HH days is a sum of HH daily demands. If each day is independent with mean μ\mu and variance σ2\sigma^2, means and variances add up:

E[∑d=1HDd]=Hμ,Var⁡[∑d=1HDd]=Hσ2⟹σH=σH\mathbb{E}\Big[\sum_{d=1}^{H} D_d\Big] = H\mu, \qquad \operatorname{Var}\Big[\sum_{d=1}^{H} D_d\Big] = H\sigma^2 \quad\Longrightarrow\quad \sigma_H = \sigma\sqrt{H}

Standard deviations don’t add: their squares do. That is why the buffer grows with the square root of the horizon, not in proportion. Covering four times as many days doesn’t take four times the buffer, only twice.

If that sum is roughly normal (it is when HH isn’t too small, by the central limit theorem), for it to be enough with probability 1−α1 - \alpha you need

Hμ+z1−α σHH\mu + z_{1-\alpha}\,\sigma\sqrt{H}

What goes beyond the mean is the safety stock, SS=z σHSS = z\,\sigma\sqrt{H}. And the order is what’s missing to get there:

Q=max⁡(0,  Hμ+z σH−I−P)Q = \max\big(0,\; H\mu + z\,\sigma\sqrt{H} - I - P\big)

The price of the last point

zz grows faster and faster as the service level approaches 100 %:

Service levelValue of zzExample buffer
90 %1.28296 units
95 %1.645123 units
99 %2.326174 units
99.9 %3.090231 units

Going from 90 to 95 % costs 27 units; from 99 to 99.9 %, 57. So it makes no sense to ask the same level for everything: a vital item deserves it, an antacid doesn’t. The twin uses 95 % as its baseline.

The warehouse (CEDIS) in 3D: racks, cold room, docks and trucks. Turn on the Inventory layer (“Inventario”) to see each item’s level against its safety stock. (Interface in Spanish.) · Open full screen

When the supplier is what varies

So far I assumed the order arrives in exactly LL days. If lead time also varies, with mean Lˉ\bar L and deviation σL\sigma_L, the variance of demand during the wait has two sources:

σtotal2=Hˉ σ2⏟varying demand+μ2 σL2⏟varying wait\sigma_{\text{total}}^2 = \underbrace{\bar H\,\sigma^2}_{\text{varying demand}} + \underbrace{\mu^2\,\sigma_L^2}_{\text{varying wait}}

The second term comes from the fact that if the wait stretches by Δ\Delta days, μΔ\mu\Delta extra units are used.

What the twin does

With the Holt-Winters forecast instead of a fixed mean, the calculation is the same: add up the forecast for the HH days, add 1.65 σH1.65\,\sigma\sqrt{H} and subtract what is on hand and in transit. The result is rounded up to the item’s pack size.

What comes next

This calculation works for a unit that orders every week. The central warehouse does the same for the whole network, with suppliers that are sometimes late or deliver short. In the next post I compare the warehouse’s two ways of ordering: fixed min-max against forecast-based ordering.