Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 38 · Simulation of Systems

Inventory Simulation and the Newsvendor Problem

Choose how much stock to order when demand is random. Simulate profits, find the best order quantity and verify it with the critical ratio rule.

A baker bakes loaves each morning before knowing how many customers will come. Bake too few and you turn away sales; bake too many and the leftovers are wasted. This tension appears in every business that stocks goods under uncertain demand: newspapers, fresh food, fashion, spare parts, event tickets. The textbook version is the newsvendor problem.

It is a perfect Monte Carlo case study because the decision (how much to order) interacts with randomness (demand) in a way a single "average demand" calculation gets wrong. It also has a neat exact answer, so you can check your simulation.

Setting up the model

  • You choose an order quantity Q before demand D is known.
  • Each unit costs c to buy and sells for p (with p > c).
  • Leftover units are worth a salvage value s (here 0).
  • Profit is p·min(Q, D) + s·max(Q − D, 0) − c·Q.

Suppose demand is normal with mean 100 and standard deviation 20 (rounded and truncated at zero in a more careful model; we ignore this since negative demand is extremely rare here), p = 10, c = 6.

The cost of ordering one unit too few (underage) is the lost margin p − c = 4. The cost of ordering one too many (overage) is c − s = 6. The optimal quantity balances them: it is the demand quantile

Text
F(Q*) = (p − c) / (p − s) = 4 / 10 = 0.4

called the critical ratio. With normal demand, Q* = μ + σ·z, where z is the standard normal quantile at 0.4 (about −0.253). The best quantity is below average demand, because overstocking is the more expensive mistake here.

Simulating profits

We simulate 200,000 demand scenarios and evaluate every candidate Q on the same scenarios. Using the same random numbers for every option is called common random numbers; it makes the comparison between options much less noisy.

Python Find the best order quantity by simulation

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The simulated best Q should be within a unit or two of the formula. The profit curve is very flat near the optimum, so neighboring quantities are almost as good; do not be surprised if the argmax jumps by one with a different seed.

Risk, not just the mean

The mean profit ignores how bad a bad day can be. A manager who orders more stock chases higher upside but takes bigger losses when demand disappoints. Simulation gives the whole distribution of profit, so you can look at percentiles.

Python Profit distribution for three order quantities

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the trade-off. A large Q = 120 has the biggest upside, but when demand is weak it loses money. The mean-maximizing Q ≈ 95 is a good compromise; a risk-averse owner might choose a smaller Q.

Extending the model

The same simulation framework handles variations that have no closed form:

  • Multiple periods with carry-over of unsold stock (an (s, S) reorder policy: when inventory falls to s, order up to S).
  • Lead times: orders arrive several days after being placed.
  • Lost sales vs backorders: unmet demand is lost, or served later.
  • Correlated or seasonal demand: sample demand from a model fitted to history.

Each extension adds a few lines to the simulation loop, but would make the algebra intractable. That is the practical power of Monte Carlo: when the model becomes realistic, you do not need a new theory, only a more detailed program.

Common random numbers are valuable whenever you compare alternatives. Differences are measured on the same scenarios, so the noise that affects all options equally cancels.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. In the newsvendor problem, the optimal order quantity satisfies:

    The critical ratio compares underage cost (p - c) to the total of underage and overage costs (p - s).
  2. 2. Price 10, cost 6, salvage 0: the critical ratio is:

    (10 - 6) / (10 - 0) = 0.4.
  3. 3. Why use the same random demand scenarios for every candidate Q?

    Differences between options are measured on identical scenarios, so shared noise cancels.
  4. 4. Why look at the profit distribution and not only its mean?

    Two quantities can have similar means but very different chances of a loss.

Summary

  • The newsvendor chooses Q before demand is known; profit is p·min(Q, D) + s·max(Q − D, 0) − c·Q.
  • The optimal Q* solves F(Q*) = (p − c)/(p − s); with normal demand Q* = μ + σz.
  • Simulate profits on shared scenarios, find the best Q, and check against the formula.
  • Look at percentiles and loss probabilities, not just the mean; extensions without formulas need only more code.

Next chapter: Option Pricing by Monte Carlo