[Intermediate] — How much stock to order and when: the economic order quantity and why it’s so forgiving, reorder points and safety stock when demand is random, and the newsvendor model for things that can’t be sold later. Small formulas with a lot of business behind them.
Source: [reference] — see the domain note. The code below was run and its output checked.
Before you start
You need to be able to differentiate a simple function and set the derivative to zero → derivative rules, and know the normal distribution and what a percentile is → distributions.
After this lesson you will be able to:
- Derive and use the economic order quantity, and explain why getting it slightly wrong barely matters.
- Set a reorder point with safety stock for a target service level.
- Solve a newsvendor problem with the critical ratio, and explain the answer in terms of the costs of too much and too little.
Study route: sections 1–3 (EOQ) with a pencil; stop and derive the formula yourself. Then sections 4–5.
The kid version
You keep snacks in your cupboard. Every trip to the shop is a hassle, so you’d like to buy a lot at once. But a huge pile of snacks takes up space and some go stale. Buy too little and you’re always at the shop; buy too much and the cupboard is full of stale crisps. Inventory models find the amount to buy each time that balances the hassle of shopping against the cost of keeping stuff. And because you never know exactly how many snacks you’ll eat this week, they also tell you how many spare to keep so you don’t run out.
Where the analogy stops working. For you, running out of crisps is a small annoyance. For a hospital running out of blood, or a factory running out of a part that stops a production line, the cost of running out can be huge — and the models make you put a number on it, which is often the hardest and most important step.
1. Why this exists
A shop sells 1,200 units of a product a year. Each order costs ₦50 to place (admin, delivery), whatever its size. Holding one unit in stock for a year costs ₦2 (storage, insurance, the money tied up).
- Order every week (about 23 units each time): 52 orders cost ₦2,600 a year; average stock is low.
- Order once a year (1,200 units): one order costs ₦50; but average stock is 600 units, costing ₦1,200 a year to hold.
Somewhere between is a minimum. Inventory is one of the largest assets on most companies’ balance sheets, so these trade-offs move real money — and the same logic covers cash balances, cache sizes and batch sizes in software.
Terms used in inventory models
- Demand rate: This is how many units are used or sold per unit time, written (here, per year).
- Ordering cost: This is also known as setup cost. Written , it’s the fixed cost of placing one order, regardless of its size.
- Holding cost: Written , it’s the cost of keeping one unit in stock for one unit of time. It’s often 15–30% of the item’s value per year, mostly the cost of the money tied up.
- Order quantity: Written , it’s how many units are ordered each time.
- Lead time: Written , it’s the delay between placing an order and receiving it.
- Reorder point: This is the stock level at which you place the next order, so it arrives before you run out.
- Safety stock: This is extra stock held to cover demand during the lead time being higher than average.
- Service level: This is also known as cycle service level. This is the probability of not running out during a replenishment cycle — 95% means you run out in about one cycle in twenty.
- Stockout: This is running out of stock when there’s demand for it.
- Critical ratio: This is the number that decides the newsvendor order: the cost of having too little divided by the total cost of being wrong in either direction.
2. The economic order quantity
Assume demand is steady and known, and orders arrive instantly. Stock then follows a sawtooth: it jumps to when an order arrives, falls steadily to 0, and jumps again.
stock
Q ┤╲ ╲ ╲
│ ╲ ╲ ╲
Q/2 ┤ ─ ─╲─ ─ ─ ─ ╲─ ─ ─ ─ ╲─ ─ average stock = Q/2
│ ╲ ╲ ╲
0 ┼───────●────────●────────●──── time
order order order
The annual cost has two parts:
- Ordering: you place orders a year, each costing : . This falls as rises.
- Holding: average stock is , each costing a year: . This rises with .
Find the minimum. Differentiate and set to zero: . So:
The economic order quantity is the square root of twice the demand times the ordering cost, divided by the holding cost.
At , the two cost parts are exactly equal — a useful check.
The shop’s numbers: units. That’s about 4.9 orders a year, every 10–11 weeks. Total cost: ₦490 a year. (Check: ordering cost ; holding cost . Equal. ✓)
Pause and predict: if you ordered 300 instead of 245 — 22% more — how much would total cost rise?
3. Why EOQ is so forgiving
| Order quantity | 150 | 200 | 245 | 300 | 400 |
|---|---|---|---|---|---|
| Annual cost (₦) | 550 | 500 | 490 | 500 | 550 |
| Above optimum | +12% | +2% | — | +2% | +12% |
Ordering 22% too much raises cost by only 2%. The cost curve is very flat near the bottom, because of the square root.
That has big practical consequences:
- You can round to a convenient pack size, pallet or truckload at almost no cost.
- Rough estimates of and are good enough. If you estimate the ordering cost as double its true value, rises by a factor of , and the cost penalty is only about 6%.
- The square root halves the relative error: a 20% error in gives about a 10% error in .
So EOQ is used not because its assumptions are true (they rarely are) but because its answer is robust to their being wrong.
4. Random demand: reorder points and safety stock
Now suppose orders take days to arrive, and daily demand is random with mean 20 and standard deviation 5.
Without uncertainty, reorder when stock falls to the demand during the lead time: units.
With uncertainty, demand during those 4 days might be more than 80. If daily demands are independent, the lead-time demand has:
- Mean .
- Standard deviation . (Variances add over independent days, so the standard deviation grows with the square root of the number of days.)
To run out in at most 5% of cycles (a 95% service level), set the reorder point at the 95th percentile of lead-time demand. For a normal distribution that’s the mean plus standard deviations:
The reorder point is the average lead-time demand plus a safety stock of standard deviations of lead-time demand.
Reorder when stock falls to about 97 units. The extra 17 is the safety stock.
What the safety stock costs. Higher service levels get expensive fast:
| Service level | 90% | 95% | 99% | 99.9% |
|---|---|---|---|---|
| 1.28 | 1.645 | 2.33 | 3.09 | |
| Safety stock (units) | 13 | 17 | 23 | 31 |
Going from 95% to 99.9% almost doubles the safety stock. Whether it’s worth it depends on what a stockout costs — which is the business question the formula forces you to answer.
Two levers reduce safety stock: reduce demand variability (better forecasts) or reduce lead time (faster suppliers). Halving the lead time cuts by a factor of , not 2.
5. The newsvendor: one chance to order
Some products can’t be sold later: newspapers, fresh bread, fashion items, event tickets, flu vaccines. You order once, before demand is known. Order too many and you’re stuck with leftovers; too few and you lose sales.
A bakery’s numbers. A cake sells for ₦10, costs ₦4 to bake, and unsold cakes are sold off at the end of the day for ₦1. Daily demand is uniformly random between 50 and 150.
The two costs of being wrong:
- Underage cost : the profit lost on each cake you could have sold but didn’t bake. .
- Overage cost : the loss on each cake baked but not sold. .
The argument, in words. Consider baking one more cake than you planned. It sells if demand exceeds your quantity , with probability , gaining . It goes unsold otherwise, losing . Keep adding cakes while the expected gain exceeds the expected loss. You stop exactly where they balance:
The newsvendor rule states that the best order quantity is the one where the probability of demand being at or below it equals the critical ratio.
Bakery: critical ratio . For demand uniform on [50, 150], the 66.7th percentile is . Bake 117 cakes — well above the average demand of 100.
Why above average? Running short costs ₦6 a cake; over-baking costs ₦3. Shortage is twice as expensive, so you lean towards having too many. If unsold cakes had to be thrown away and cost something to dispose of, would rise and the order would fall.
If demand is normal with mean and standard deviation : , where is the critical ratio’s percentile of the standard normal. For a ratio of 0.667, .
This one idea — balance the cost of too little against the cost of too much, weighted by probability — also sets airline overbooking, hotel room allocation, cloud capacity reservations and how many servers to pre-provision.
Worked example — EOQ and the newsvendor in Python
Runnable, standard library only.
# inventory.py — note 13: EOQ and the newsvendor
import math
D, S, H = 1200, 50, 2 # units/year, cost per order, holding cost per unit-year
Q = math.sqrt(2 * D * S / H)
cost = lambda q: D * S / q + H * q / 2
print(f"EOQ = {Q:.1f} units, annual cost {cost(Q):.1f}")
for q in (150, 200, 300, 400):
print(f" order {q}: cost {cost(q):.1f} ({100 * (cost(q) / cost(Q) - 1):+.1f}%)")
price, unit_cost, salvage = 10, 4, 1
cu, co = price - unit_cost, unit_cost - salvage
ratio = cu / (cu + co)
lo, hi = 50, 150 # demand uniform between 50 and 150
print(f"critical ratio {ratio:.3f} -> order {lo + ratio * (hi - lo):.1f}")python3 inventory.pyExpected output:
EOQ = 244.9 units, annual cost 489.9
order 150: cost 550.0 (+12.3%)
order 200: cost 500.0 (+2.1%)
order 300: cost 500.0 (+2.1%)
order 400: cost 550.0 (+12.3%)
critical ratio 0.667 -> order 116.7
Common pitfalls and traps
- Units mismatch. per year with per month gives a that’s off by . Put everything on the same time base.
- Leaving out the cost of money. Holding cost isn’t just warehouse rent; the capital tied up in stock is usually the biggest part.
- Adding standard deviations across days. Variances add, standard deviations don’t. Four days of gives , not 20.
- Confusing service level definitions. “95% cycle service level” (run out in 5% of cycles) is not “95% fill rate” (meet 95% of demand from stock). The fill rate is usually much higher for the same safety stock.
- Ordering the mean in a newsvendor problem. The mean is only right when . Otherwise the costs push you up or down.
- Ignoring the bullwhip effect. Small swings in customer demand become larger swings in orders up a supply chain, as each stage adds safety stock and batches orders. Sharing demand data across the chain is the standard cure.
Check your understanding
- If demand doubles, by what factor does the EOQ change? The total cost?
- Why is the EOQ cost curve so flat near the minimum?
- A supplier cuts lead time from 9 days to 4. Daily demand has . By how much does the safety stock for a 95% service level fall?
- In the bakery, unsold cakes now have to be thrown away (salvage 0). What’s the new order quantity?
After your attempt — answers
- Both by . Demand doubled, but EOQ and its cost each rise by only 41%: economies of scale in ordering.
- Near the minimum, an increase in one cost part is almost exactly offset by a decrease in the other: their slopes are equal and opposite at . Mathematically, the first derivative is zero there, so the cost changes only with the square of the deviation.
- falls from to . Safety stock falls from to — about 10 units, a third.
- becomes . Critical ratio . Order .
Practice — independent task
- Derive: with the note closed, derive the EOQ formula from the total cost, and show the two cost parts are equal at the optimum.
- Apply: a pharmacy sells 5,000 boxes of a medicine a year. Each order costs ₦2,000; each box costs ₦800, and holding cost is 25% of value per year. Lead time is 10 days; daily demand has standard deviation 4 boxes. Find the EOQ, the reorder point for a 98% service level (assume 365 days a year), and the annual ordering and holding costs.
- Simulate: write a short script that simulates the bakery for 10,000 days with uniform random demand, for every bake quantity from 80 to 150, and plots (or prints) average profit. Confirm the peak is near 117.
Done when: your derivation is on paper, your pharmacy numbers are internally consistent (ordering cost ≈ cycle-stock holding cost), and the simulation’s best quantity is within a couple of cakes of the formula.
Before moving on
You’re ready when you can derive EOQ, explain its flatness, compute a reorder point with safety stock, and explain the newsvendor answer in one sentence about the two costs of being wrong.
Recap:
- EOQ balances ordering and holding costs, and is robust to errors in its inputs.
- Safety stock , with . High service levels get expensive fast.
- The newsvendor orders where — above the mean when shortages cost more than leftovers.
Next: Simulation — when the system is too messy for any formula, build it in code and run it many times.
Related
- Dynamic Programming — multi-period stocking under uncertainty
- Queueing Theory — the other classic stochastic model
- Distributions — the normal and uniform used here
- Operations research map
Software engineering
Infrastructure & security
Computer science
Hardware & engineering