Choice Under Uncertainty
When an objective function depends on a random variable, we choose the value of the choice variable that optimizes the expected value of the objective. We apply this method to a weekly magazine order, a reorder point with a service target and an order with an uncertain delivered quantity.
Optimizing the expected value of a function of a random variable
This session combines Sessions 1 and 2.
- Session 1: random variables describe uncertainty. A distribution gives probabilities, an expected value and quantiles.
- Session 2: we chose the value of a choice variable to minimize or maximize an objective function that is known in advance, such as the EOQ cost $TC(Q)=Kd/Q+hQ/2$. This objective is deterministic.
- Session 3: the objective also depends on a random variable. We choose $Q$ to optimize the expected value of a function of that random variable.
Here $\pi(Q,D)$ is the profit from ordering $Q$ units when demand is $D$.
Demand $D$ is a random variable. The order $Q$ is a choice variable
Demand $D$ is a random variable. Its value is unknown when the order is placed. We assume that $D$ follows a known distribution, for example a normal distribution $D\sim N(\mu,\sigma^2)$. Other distributions, such as the Poisson distribution or the empirical distribution of past weeks, can be used in the same way. Other random variables also appear in this session: demand during a delivery lead time (Section 4) and the fraction $Y$ of an order that is delivered (Section 5).
The order quantity $Q$ is a choice variable. We set its value before $D$ is observed, and $Q$ is not random.
Lowercase $d$ is a realized value of $D$, such as $d=120$ copies of a magazine. As in Session 1, capital letters denote random variables and lowercase letters their realized values. The timing is:
- Choose $Q$. The distribution of $D$ is known, but its value is not.
- Observe $D=d$. Demand is realized.
- Receive $\pi(Q,d)$. Profit depends on both the choice and the realized demand.
When $Q$ is chosen at step 1, $D$ is still unknown. Profit $\pi(Q,D)$ is therefore a random variable: each possible value of demand gives a different profit for the same $Q$.
We maximize the expected value of profit
In Session 2, $TC(Q)$ was a number for each $Q$. Now $\pi(Q,D)$ is a random variable for each $Q$, so we rank the choices by its expected value. As in Session 1, the expectation of a function of a random variable weights each outcome by its probability:
The optimization problem is
$$\max_{Q\in\mathcal X}\;E[\pi(Q,D)].$$$Q$ is held fixed inside the expectation: the same order is used for every demand outcome. $\mathcal X$ is the feasible set of orders, for example $Q\ge0$, or $0\le Q\le$ a capacity limit. The expected profit is a deterministic function of $Q$, so the tools of Session 2 (first-order condition, convexity or concavity, boundaries) apply to it.
A first example: one choice, two possible demands
Choose $Q\ge0$ before demand is known. Demand is either 40 or 80 units, each with probability $1/2$. To practise a smooth first-order condition, use a simple quadratic mismatch cost. Matching demand earns a margin of €8 per unit. A mismatch of $Q-d$ units costs $0.1(Q-d)^2$ euros:
$$\pi(Q,d)=\underbrace{8d}_{\text{margin if demand is matched}} -\underbrace{0.1(Q-d)^2}_{\text{cost of a mismatch}}.$$Over- and under-ordering have equal quadratic penalties here. The magazine model in Section 1 uses different costs per unit.
before observing $D$
Profit $\pi(Q,40)$
Profit $\pi(Q,80)$
The same $Q$ appears on both branches. For example, if $Q=60$, the two profits are $\pi(60,40)=320-0.1(20)^2=280$ euros and $\pi(60,80)=640-0.1(-20)^2=600$ euros.
First average the profits on the two branches
Hold $Q$ fixed and weight each branch by its probability:
$$\begin{aligned} E[\pi(Q,D)]&=\tfrac12\pi(Q,40)+\tfrac12\pi(Q,80)\\[4pt] &=\tfrac12[320-0.1(Q-40)^2]+\tfrac12[640-0.1(Q-80)^2]\\[4pt] &=480-0.05\big[(Q-40)^2+(Q-80)^2\big]. \end{aligned}$$| Order $Q$ | Profit if $d=40$ | Profit if $d=80$ | Expected profit |
|---|---|---|---|
| 40 | €320 | €480 | €400 |
| 60 | €280 | €600 | €440 |
| 80 | €160 | €640 | €400 |
How does one order perform on each branch?
Move the order slider. The vertical line marks the same $Q$ on every curve, and each dot shows the profit it earns. The green curve averages the profits on the two demand branches.
Expected profit peaks at $Q=60$. The profit at mean demand lies €40 above expected profit for every order: replacing the random demand by its mean removes the quadratic cost of demand variability. The marginal-profit readout is positive below $Q=60$, zero at $Q=60$ and negative above it.
$E[D]=60$, but $\pi(60,E[D])=480$ euros while $E[\pi(60,D)]=440$ euros. In general, $E[\pi(Q,D)]\ne\pi(Q,E[D])$: keep the mismatch costs on each demand branch.
Now choose $Q$: take the first-order condition
$$\max_{Q\ge0}E[\pi(Q,D)] =\max_{Q\ge0}\left\{480-0.05\big[(Q-40)^2+(Q-80)^2\big]\right\}.$$ $$\begin{aligned} \frac{d}{dQ}E[\pi(Q,D)]&=-0.1\big[(Q-40)+(Q-80)\big]\\[4pt] &=12-0.2Q,\\[4pt] 12-0.2Q^*&=0. \end{aligned}$$ $$\boxed{Q^*=60}.$$Check the second-order condition (Session 2): $\frac{d^2}{dQ^2}E[\pi(Q,D)]=-0.2 < 0$. Strict concavity gives a unique global maximum. The choice $Q^*=60$ is feasible and earns €440 in expected profit. The mean is optimal in this example because the penalty is symmetric and quadratic. This will generally change with asymmetric per-unit costs.
An optimal choice and its objective value
“Arg max” returns the quantity or quantities achieving the best value.
“Max” returns the highest expected profit, in euros.
In the two-outcome example, the optimal choice is $Q^*=60$ units and the optimal value is €440.
Perfect information changes what can be chosen
$$\underbrace{\max_{Q\in\mathcal X} E[\pi(Q,D)]}_{\text{one order chosen in advance}} \;\le\;\underbrace{E\Big[\max_{Q\in\mathcal X}\pi(Q,D)\Big]}_{\text{a separate best order for each outcome}}$$On the left, every outcome must use the same $Q$. On the right, demand is revealed before the order is chosen. This is a perfect-information benchmark. The same feasible set is used on both sides, and we assume that the maxima and expectations exist. In the two-outcome example, with perfect information choose 40 or 80 units to match demand and earn $\tfrac12\times320+\tfrac12\times640=480$ euros on average, compared with €440 from the best single order. Only the left-hand decision can be made with the information available when the order is placed.
Expected-profit maximization is risk neutral
Maximizing expected profit ranks decisions by their average profit across the possible outcomes. A high expected profit does not guarantee a good result every week. A risk-averse decision-maker could instead maximize expected utility or limit the probability of a large loss. This session uses expected profit and, in Section 4, an explicit service-level requirement.
1. One order, uncertain demand: leftovers and missed sales
A newsstand sells a weekly magazine. Before each week starts, it orders $Q$ copies from the distributor. There is no second delivery during the week. When the shelf is empty, further customers leave without buying. At the end of the week, the next issue replaces the old one. The distributor takes back the unsold copies and refunds part of their cost.
Each copy sells for the price $p=5$ euros and costs $c=2$ euros to buy. The refund for an unsold copy is its salvage value $s=1$ euro.
Every week repeats the same one-order problem. It is called the newsvendor model after exactly this setting. We assume $p>c>s$, so selling earns a margin and leftovers lose money. The setting matters here. A pair of sunglasses that is unsold this week can still be sold next week, so there is no reason to sell it off at a loss every week. A magazine issue is out of date after one week, so its leftovers really are worth only the refund.
The two errors have different costs
The newsstand paid €2 for the copy and gets €1 back. This is the overage cost per leftover copy.
A customer leaves without buying, and the €3 margin on that sale is lost. This is the underage cost per unit of unmet demand.
A missing copy costs three times as much as a leftover copy. A low order avoids leftovers but risks the more expensive error.
The positive part measures leftovers and unmet demand
The positive part of a number keeps the number when it is positive and replaces it by zero when it is negative:
$$x^+=\max\{x,0\}.$$For an order $Q$ and a realized demand $d$, $(Q-d)^+$ is the number of leftover copies and $(d-Q)^+$ is the unmet demand. For a single realization, at most one of the two mismatch quantities is positive.
| Order $Q$ | Demand $d$ | Leftovers $(Q-d)^+$ | Unmet demand $(d-Q)^+$ |
|---|---|---|---|
| 100 | 80 | 20 | 0 |
| 100 | 100 | 0 | 0 |
| 100 | 120 | 0 | 20 |
Realized profit: sales, refunds and purchasing
The newsstand sells $\min\{Q,d\}$ copies, receives the refund $s$ for each of the $(Q-d)^+$ unsold copies and pays $c$ for each of the $Q$ copies ordered. The realized profit is
$$\boxed{\pi(Q,d)=p\min\{Q,d\}+s(Q-d)^+-cQ}.$$For example, with an order of 120 copies,
$$\begin{aligned} \pi(120,100)&=5\times100+1\times20-2\times120\\ &=280\text{ euros},\\[6pt] \pi(120,140)&=5\times120+1\times0-2\times120\\ &=360\text{ euros}. \end{aligned}$$The order is the same. Sales and leftovers depend on the realized demand.
Profit equals the margin from meeting demand minus leftover and shortage costs
The same profit can be written as the margin from meeting demand exactly, minus the cost of each type of mismatch:
$$\pi(Q,d)=(p-c)d -c_o\underbrace{(Q-d)^+}_{\textcolor{#fc6255}{\substack{\textbf{chosen quantity above}\\\textbf{realized demand}}}} -c_u\underbrace{(d-Q)^+}_{\textcolor{#fc6255}{\substack{\textbf{chosen quantity below}\\\textbf{realized demand}}}}.$$- $(p-c)d$ is the margin if the realized demand could be matched exactly.
- Subtract the overage cost $c_o=1$ euro per copy for all leftover copies $(Q-d)^+$.
- Subtract the underage cost $c_u=3$ euros per copy for all missed sales $(d-Q)^+$.
At $Q=120$ and $d=140$, this form gives $3\times140-1\times0-3\times20=360$ euros, as before. It shows the two errors separately.
Weekly demand is a continuous random variable with a known distribution
In the opening example, demand took only two values. From now on, weekly demand $D$ is a continuous random variable, and we assume that we know its distribution exactly:
$$D\sim N(100,\ 20^2)\quad\text{copies per week}.$$$D$ can take any value in an interval. As in Session 1, probabilities are areas under the density $f$, and the CDF is $F(Q)=P(D\le Q)$. The mean is $\mu=100$ copies and the standard deviation is $\sigma=20$ copies. In practice, these would be estimated from past weeks of sales. Here they are illustrative values. The normal model allows negative demand, but here $P(D \lt 0)$ is less than one in a million. Copies are whole numbers. The continuous model is an approximation that lets us use derivatives.
The same simulated weeks, scored for one fixed order quantity
Each dot is one simulated week of demand drawn from the assumed $N(100,\ 20^2)$ model. Every week uses the same order $Q$, and the bars give the total leftover and shortage costs over all simulated weeks.
The leftover cost is €1 times the total number of leftover copies, and the shortage cost is €3 times the total unmet demand. For the first 20 weeks, $Q=70$ gives only shortage cost, €2,152 in total, and an average profit of €210 per week. With $Q=140$, the same weeks give €683 of leftover cost and €1 of shortage cost, and an average profit of €283 per week. The green bar is the lowest total cost over these weeks for one fixed order, a whole number of copies between 60 and 150. It is selected after seeing the sample, so it is a comparison, not a decision that could be made in advance. It is also different from perfect information, which would allow a different order in each week. For the first 20 weeks this hindsight order is $Q=116$ copies, with a total cost of €420. Both types of error remain. Another sample would select a different order.
2. The critical ratio: the optimal order
We now choose $Q$ to maximize the expected profit $E[\pi(Q,D)]$ under the assumed demand distribution. As in Session 2, we look for the order at which the derivative of the objective is zero, and then check the second-order condition.
What does a little more stock add to expected profit?
Start from an order $Q$ and increase it slightly. The effect depends on demand:
slightly
Profit falls by $c_o=1$ euro per copy
Profit rises by $c_u=3$ euros per copy
The extra copy is left over when demand is at most $Q$, which has probability $F(Q)=P(D\le Q)$. It is sold when demand exceeds $Q$, which has probability $1-F(Q)=P(D>Q)$. Weight each branch by its probability, as in the opening example. The result is the derivative of expected profit, the expected change in profit per extra copy:
$$\boxed{\frac{d}{dQ}E[\pi(Q,D)]=c_u\,[1-F(Q)]-c_o\,F(Q)}.$$Proof: the derivative of expected profit
Take expectations of the profit formula, holding $Q$ fixed. By linearity of expectation (Session 1),
$$E[\pi(Q,D)]=(p-c)\mu-c_oE[(Q-D)^+]-c_uE[(D-Q)^+].$$For a fixed demand value $d\ne Q$, differentiate each positive part with respect to $Q$:
$$\frac{d}{dQ}(Q-d)^+=\begin{cases}1&\text{if }d \lt Q,\\0&\text{if }d>Q,\end{cases}\qquad \frac{d}{dQ}(d-Q)^+=\begin{cases}0&\text{if }d \lt Q,\\-1&\text{if }d>Q.\end{cases}$$Averaging over $D$ replaces each case by its probability. With continuous demand, $P(D=Q)=0$, so $P(D \lt Q)=F(Q)$ and $P(D>Q)=1-F(Q)$:
$$\begin{aligned} \frac{d}{dQ}E[\pi(Q,D)]&=-c_o\,P(D \lt Q)-c_u\,\big(-P(D>Q)\big)\\[6pt] &=-c_oF(Q)+c_u[1-F(Q)]. \end{aligned}$$The derivative may be taken inside the expectation because each positive part changes by at most the change in $Q$. The difference quotients are therefore bounded by 1, and the dominated convergence theorem allows the limit and the expectation to be exchanged.
The branch probabilities are areas under the density
At $Q=\mu=100$, the normal density is symmetric about the order, so $F(100)=0.5$ and
$$\begin{aligned} \frac{d}{dQ}E[\pi(Q,D)]\Big|_{Q=100}&=3\times0.5-1\times0.5\\[4pt] &=1\text{ euro}>0. \end{aligned}$$One more copy still adds €1 on average, so the newsstand should order more than mean demand.
Where does one more copy stop adding expected profit?
Top: the assumed demand density $N(100,\ 20^2)$, split at the order $Q$. The yellow area is the probability $F(Q)$ that an extra copy is left over, and the red area is the probability $1-F(Q)$ that it is sold. Bottom: the marginal expected profit $c_u[1-F(Q)]-c_oF(Q)$ for every order. Both panels share the horizontal axis.
The shaded areas are probabilities. At $Q=100$, each area is 50% and the marginal expected profit is €1 per extra copy. Moving $Q$ to the right moves probability from the red area to the yellow area, so the marginal expected profit falls. With $c_u=3$ euros and $c_o=1$ euro, it reaches zero at $Q^*\approx113.49$, where $F(Q^*)=75\%$. Raising $c_u$ to 6 euros moves this point right, to about 121.35. Returning to $c_u=3$ euros and raising $c_o$ to 4 euros moves it left, to about 96.40, below mean demand.
The first-order condition gives the critical ratio
Set the derivative equal to zero at $Q^*$ and solve for $F(Q^*)$:
$$\begin{aligned} c_u[1-F(Q^*)]-c_oF(Q^*)&=0,\\[4pt] c_u-c_uF(Q^*)-c_oF(Q^*)&=0,\\[4pt] (c_u+c_o)F(Q^*)&=c_u. \end{aligned}$$ $$\boxed{F(Q^*)=\alpha^*=\frac{c_u}{c_u+c_o}}.$$The critical ratio $\alpha^*$ is the underage cost divided by the sum of both mismatch costs. It is the optimal probability of covering all demand. At $Q^*$, the expected gain from one more copy is zero. This holds for positive costs and continuous demand. The optimal order is the $\alpha^*$-quantile of the demand distribution.
The second-order condition confirms a maximum
The derivative of the CDF $F$ is the density $f$. Differentiating the first derivative once more,
$$\begin{aligned} \frac{d^2}{dQ^2}E[\pi(Q,D)]&=-c_uf(Q)-c_of(Q)\\[4pt] &=-(c_u+c_o)f(Q)\le0. \end{aligned}$$Expected profit is concave, so, as in Session 2, the stationary point is a global maximum. If $F(Q) \lt \alpha^*$, the first derivative is positive, and one more copy raises expected profit. If $F(Q)>\alpha^*$, the first derivative is negative, and one more copy lowers expected profit. For normal demand, $f(Q)>0$ everywhere, so the optimal order is unique.
The magazine's critical ratio is 75%
$$\begin{aligned} \alpha^*&=\frac{c_u}{c_u+c_o}\\[4pt] &=\frac{3}{3+1}=0.75. \end{aligned}$$The newsstand should order the quantity $Q^*$ with $P(D\le Q^*)=0.75$. It then meets all demand in 75% of weeks and runs out in 25% of weeks. $Q^*$ is the 75% quantile of weekly demand. Next, we turn this probability into a number of copies.
To find the quantile, standardize demand
Demand is continuous and its distribution is known: $D\sim N(100,\ 20^2)$. We need the order $Q^*$ with $F(Q^*)=0.75$. There is a different normal distribution for every $\mu$ and $\sigma$, so tables list only the standard normal random variable $Z\sim N(0,1)$, with CDF $\Phi(z)=P(Z\le z)$ and quantiles $z_\alpha=\Phi^{-1}(\alpha)$. As in Session 1, subtracting $\mu$ and dividing by $\sigma$ turns any normal random variable into $Z$, so one table of $\Phi$ is enough for every normal demand model. We apply this to both sides of the inequality:
$$\begin{aligned} F(Q)=P(D\le Q)&=P\!\left(\frac{D-\mu}{\sigma}\le\frac{Q-\mu}{\sigma}\right)\\[6pt] &=P\!\left(Z\le\frac{Q-\mu}{\sigma}\right)\\[6pt] &=\Phi\!\left(\frac{Q-\mu}{\sigma}\right). \end{aligned}$$Since $\sigma>0$, dividing by $\sigma$ keeps the direction of the inequality. Software can
also give the quantile of $D$ directly, for example NORM.INV(0.75,100,20) in a
spreadsheet, with the same result.
Standardizing keeps the area and changes the axis
Left: weekly demand $D\sim N(100,\ 20^2)$, shaded up to the order $Q$. Right: the standard normal $Z\sim N(0,1)$, shaded up to $z=(Q-100)/20$. Move the probability slider. The two shaded areas are always equal.
Subtracting $\mu=100$ moves the center to 0. Dividing by $\sigma=20$ measures distances in standard deviations. The area to the left of the threshold stays the same. At $\alpha=75\%$, a table gives $z^*=\Phi^{-1}(0.75)\approx0.6745$, and converting back gives $Q^*=100+20\times0.6745\approx113.49$ copies.
The newsstand's optimal order
$$\begin{aligned} \Phi\!\left(\frac{Q^*-\mu}{\sigma}\right)&=\alpha^*=0.75,\\[6pt] \frac{Q^*-\mu}{\sigma}&=z^*=\Phi^{-1}(0.75)\approx0.6745,\\[6pt] Q^*&=\mu+\sigma z^*\\[4pt] &=100+20\times0.6745. \end{aligned}$$ $$\boxed{Q^*\approx113.49\ \text{copies}}.$$The newsstand orders about 13.5 copies more than mean demand, because a missing copy costs
more than a leftover one. In a spreadsheet, $\Phi^{-1}(0.75)$ is
NORM.S.INV(0.75). In Python, it is scipy.stats.norm.ppf(0.75).
Reading the optimal order from the CDF
Start at the critical ratio on the vertical axis, move across to the CDF of demand, then read the order quantity below. The sliders change the price, the purchase cost and the salvage value. The demand distribution stays fixed.
The slider ranges keep $p > c > s$, so both mismatch costs are positive and $0 \lt \alpha^* \lt 1$. With $p=5$ euros, $c=2$ euros and $s=1$ euro, $\alpha^*=75\%$ and $Q^*\approx113.49$ copies. Raising the price to 7 euros gives $c_u=5$ euros, $\alpha^*=5/6\approx83.33\%$ and $Q^*\approx119.35$ copies. The change comes entirely from the cost of a missed sale. Returning to $p=5$ euros and setting $s=0$ gives $c_o=2$ euros, $\alpha^*=3/5=60\%$ and $Q^*\approx105.07$ copies. A leftover copy then loses its full purchase cost of €2.
How price, purchase cost and salvage value affect the order
Substituting $c_u=p-c$ and $c_o=c-s$ gives
$$\begin{aligned} \alpha^*&=\frac{p-c}{(p-c)+(c-s)}\\[4pt] &=\frac{p-c}{p-s}\qquad(p>c>s). \end{aligned}$$Keep the demand distribution fixed when making these comparisons. A higher critical ratio is a higher quantile, so a larger order:
| Change, others fixed | Underage cost $c_u$ | Overage cost $c_o$ | Optimal order $Q^*$ |
|---|---|---|---|
| Price $p$ increases | increases | unchanged | increases |
| Purchase cost $c$ increases | decreases | increases | decreases |
| Salvage value $s$ increases | unchanged | decreases | increases |
What 75% coverage means
At the optimum, $P(D\le Q^*)=75\%$, so all demand is met in about three weeks out of four. The model predicts a shortage in about 25% of weeks. This is a probability across weeks, not the fraction of customers served or of copies sold. Maximizing expected profit deliberately accepts both shortage risk and leftover risk. A profit-maximizing coverage probability need not be close to 100%. Section 3 measures how many copies are left over or missing on average.
3. The loss function: expected leftovers, shortages and profit
What we want to know about an order
For a chosen $Q$, we want the expected shortage, the expected leftovers and the expected profit. Take expectations of the profit formula, holding $Q$ fixed. By linearity of expectation (Session 1),
$$\begin{aligned} E[\pi(Q,D)]&=E\big[(p-c)D-c_o(Q-D)^+-c_u(D-Q)^+\big]\\[6pt] &=(p-c)\mu-c_o\underbrace{E[(Q-D)^+]}_{\text{expected leftovers}} -c_u\underbrace{E[(D-Q)^+]}_{\text{expected shortage}}. \end{aligned}$$Leftovers minus shortage always equals $Q-d$. Taking expectations of both sides, expected leftovers follow from expected shortage:
$$\begin{aligned} (Q-d)^+-(d-Q)^+&=Q-d\qquad\text{for every demand }d,\\[6pt] E[(Q-D)^+]-E[(D-Q)^+]&=Q-\mu,\\[6pt] E[(Q-D)^+]&=Q-\mu+E[(D-Q)^+]. \end{aligned}$$Expected leftovers are therefore not simply $Q-\mu$: the weeks with high demand add the expected shortage. Only one expectation is left to compute, the expected shortage $E[(D-Q)^+]$.
The standard normal loss function gives the expected shortage
Standardize as before. Write $D=\mu+\sigma Z$ with $Z\sim N(0,1)$, and write the order as $Q=\mu+\sigma z$, so $z=(Q-\mu)/\sigma$. Then $D-Q=\sigma(Z-z)$, and
$$\begin{aligned} (D-Q)^+&=\big(\sigma(Z-z)\big)^+=\sigma(Z-z)^+\qquad(\sigma>0),\\[6pt] E[(D-Q)^+]&=\sigma\,E[(Z-z)^+]=\sigma L(z). \end{aligned}$$ $$\boxed{L(z)=E[(Z-z)^+]=\phi(z)-z[1-\Phi(z)]}.$$$L$ is the standard normal loss function: the expected amount
by which $Z$ exceeds $z$, counting zero when it does not. $Z$ is random. The threshold $z$ is
a fixed number computed from the chosen order $Q$. Read $L(z)$ from a table, or compute it
from the standard normal density $\phi$ and CDF $\Phi$. In a spreadsheet, use
NORM.S.DIST(z,FALSE) - z*(1-NORM.S.DIST(z,TRUE)). Multiplying by $\sigma$
converts $L(z)$, which is measured in standard deviations, into copies. The function $L(z)$
is distinct from the lead time $L$ in Section 4.
Proof: the standard normal loss function
For any fixed real threshold $z$ and $Z\sim N(0,1)$,
$$\begin{aligned} L(z)=E[(Z-z)^+]&=\int_z^\infty(x-z)\phi(x)\,dx\\[6pt] &=\int_z^\infty x\phi(x)\,dx-z\int_z^\infty\phi(x)\,dx. \end{aligned}$$Since $\phi(x)=(2\pi)^{-1/2}e^{-x^2/2}$, its derivative is $\phi'(x)=-x\phi(x)$. Therefore,
$$\begin{aligned} \int_z^\infty x\phi(x)\,dx&=[-\phi(x)]_z^\infty=\phi(z),\\[6pt] \int_z^\infty\phi(x)\,dx&=1-\Phi(z). \end{aligned}$$ $$\boxed{L(z)=\phi(z)-z[1-\Phi(z)]}.$$Here $x$ ranges over possible outcomes of $Z$. The threshold $z$ is fixed throughout.
Expected shortage, leftovers and profit at the optimal order
At $Q^*\approx113.49$, we have $z^*\approx0.6745$, and a table gives $L(0.6745)\approx0.1492$:
$$\begin{aligned} E[(D-Q^*)^+]&=20\times0.1492\approx2.98\text{ copies},\\[6pt] E[(Q^*-D)^+]&=113.49-100+2.98\approx16.47\text{ copies},\\[6pt] E[\pi(Q^*,D)]&=3\times100-1\times16.47-3\times2.98\\[4pt] &\approx274.58\text{ euros per week}. \end{aligned}$$ $$\boxed{E[\pi(Q^*,D)]\approx274.58\text{ euros per week}}.$$The expected shortage of 2.98 copies averages over all weeks, including weeks without a shortage. A shortage occurs in 25% of weeks, so in a week with a shortage about $2.98/0.25\approx11.9$ copies are missing on average.
Expected profit for every order quantity
Each point of the curve uses three steps: $z=(Q-100)/20$, then $L(z)$, then expected profit. Move the order slider to see the three steps for one order.
At the mean order $Q=100$, $z=0$ and $L(0)\approx0.3989$. Expected shortage and expected leftovers are both $20\times0.3989\approx7.98$ copies, so expected profit is $300-1\times7.98-3\times7.98\approx268.08$ euros per week, or €6.49 less than at $Q^*$. The curve is flat near its maximum.
Feasibility and integer orders
Solve the continuous problem, then check the feasible set. If the normal quantile gives $Q^* \lt 0$, the best feasible order is $Q=0$. Copies are whole numbers, so compare the integers just below and above $Q^*$:
| Order | Expected profit (€/week) |
|---|---|
| 113 | 274.5702 |
| 114 | 274.5696 |
The newsstand should order 113 copies. The two integer orders differ by less than one cent per week.
4. Safety stock: when to reorder
In Session 1, we modelled lead-time demand and used a quantile to find $r$ and safety stock. The probability of any shortage is $1-\alpha$.
Does a shortage miss one unit or many? What fraction of units is served immediately? Is the reduction in shortage cost worth extra safety stock?
First recall the policy, then distinguish shortage frequency from shortage size. We compare service targets using their costs.
Amélie, the sunglasses buyer from Sessions 1 and 2, also stocks phone cases, which she reorders regularly from the same supplier. To keep the numbers familiar, this example gives phone cases the weekly demand parameters of the sunglasses, $\mu=230.5$ and $\sigma=74.8$ phone cases per week, and the EOQ batch from Session 2:
$$Q=\sqrt{\frac{2Kd}{h}}=\sqrt{\frac{2\times250\times12{,}000}{2.4}}\approx1{,}581\ \text{phone cases},$$with $K=250$ euros per order, $h=2.40$ euros per unit per year and $d=12{,}000$ units per year. Here lowercase $d$ again denotes a fixed annual demand rate, as in Session 2, rather than one week's realization.
A recurring item needs both an order size and a trigger. The order size is the EOQ batch $Q$. The trigger is the reorder point $r$: Amélie orders $Q$ phone cases when the inventory position falls to $r$. The order arrives after a fixed lead time of $L$ weeks, so the stock available when the order is placed must cover demand during those $L$ weeks.
Inventory position includes outstanding orders
$$\text{inventory position}=\text{on hand}+\text{on order}-\text{backorders}.$$Demand reduces the inventory position. Placing an order increases the position by $Q$ immediately, before any delivery arrives. The receipt then moves units from “on order” to “on hand” and leaves the position unchanged. A negative net inventory (on hand minus backorders) means a backlog of unmet demand, not negative physical stock. Triggering replenishment on the position, rather than on the shelf stock alone, prevents a second order while the first is still in transit.
Session 1 recap: lead-time demand is a sum
Assume that weekly demands $D_t^{\text{(week)}}$ are independent and identically distributed $N(\mu,\sigma^2)$ and that lead time is a fixed $L$ weeks. The lead-time demand is $D_L=\sum_{t=1}^L D_t^{\text{(week)}}$. For independent weeks, means and variances add (Session 1):
$$\begin{aligned} E[D_L]&=\mu L,\\ \operatorname{Var}(D_L)&=L\sigma^2,\qquad \operatorname{SD}(D_L)=\sigma\sqrt L,\\ D_L&\sim N(\mu L,\ \sigma^2 L). \end{aligned}$$Session 1 recap: a given target determines a quantile
A shortage occurs in a replenishment cycle if lead-time demand exceeds $r$. The cycle service level $\alpha$ is the target probability of no shortage during the lead time. Setting $P(D_L\le r)=\alpha$ and standardizing,
$$\begin{aligned} P(D_L\le r)&=\alpha,\\ \Phi\!\left(\frac{r-\mu L}{\sigma\sqrt L}\right)&=\alpha,\\ \frac{r-\mu L}{\sigma\sqrt L}&=z_\alpha=\Phi^{-1}(\alpha),\\ r&=\mu L+z_\alpha\sigma\sqrt L,\qquad ss=z_\alpha\sigma\sqrt L. \end{aligned}$$The safety stock $ss$ is the part of $r$ above the expected
lead-time demand $\mu L$. For $Z\sim N(0,1)$, $z_\alpha$ satisfies $P(Z\le z_\alpha)=\alpha$.
In a spreadsheet, it is NORM.S.INV(α). As in Section 2, the decision is a
quantile, but here the probability $\alpha$ is a service target chosen by management
rather than the result of a cost trade-off.
Session 1 recap: two weeks and 95% cycle service
$$\begin{aligned} \mu L&=230.5\times2=461,\\ \sigma\sqrt L&=74.8\sqrt2\approx105.78,\\ ss&=1.64485\times105.78\approx174,\\ r&=461+174\approx635\ \text{phone cases}. \end{aligned}$$When the inventory position reaches about 635 phone cases, Amélie orders another batch of about 1,581. The holding cost of the safety stock is $h\cdot ss=2.4\times173.998\approx417.59$ euros per year.
How often does a replenishment cycle have a shortage?
$\alpha=P(D_L\le r),\qquad 1-\alpha=P(D_L>r).$Count each completed cycle once: did it have any shortage? The model predicts a fraction $1-\alpha$ of cycles with a shortage. In a simulated path, estimate this fraction by dividing shortage cycles by completed cycles. Several red points can belong to the same shortage cycle. A cycle missing one unit and a cycle missing 100 units both count as one.
Unmet demand is backordered here: customers wait and are served from the next delivery, so sales are delayed rather than lost.
Three simulated years of the (r, Q) policy for phone cases
Weekly demand is drawn from the assumed $N(230.5,\ 74.8^2)$ model and flows out at a constant rate within each week. The policy orders $Q\approx1{,}581$ phone cases when the inventory position reaches $r$. The order arrives $L$ weeks later, which appears as an upward jump. The lower panel shows the annual holding cost of the safety stock for each service target, at the current lead time.
An order is placed only when no other order is outstanding, so at that moment the net inventory equals the inventory position and the blue line touches $r$. A cycle is counted from one order to the next, and the first, partial cycle is not counted. With $\alpha=95\%$ and $L=2$, this path has no shortage in its 20 counted cycles. With $L=4$ and $\alpha=80\%$ ($ss\approx126$, $r\approx1{,}048$), one of 21 counted cycles has a shortage: 4.8% observed against a model probability of 20%. A sample of about 20 cycles is noisy, so the observed share need not match $1-\alpha$, and raising $\alpha$ need not reduce the count in every sample. The holding-cost curve becomes steep as $\alpha\to1$, because $z_\alpha\to\infty$: no finite reorder point guarantees 100% service under an unbounded normal model. At 99% and $L=2$, $ss\approx246.09$ and $h\cdot ss\approx590.61$ euros per year, about 173.02 euros more than at 95%.
Can the number of shortage cycles tell us the cost?
| In 100 cycles | Policy A | Policy B |
|---|---|---|
| Cycles with a shortage | 5 | 5 |
| Missing units in each shortage cycle | 1 | 100 |
| Total missing units | 5 | 500 |
Both have observed cycle service of 95%. With a penalty per missing unit, Policy B has 100 times the shortage cost. We need expected units missing per cycle, including zero in cycles without a shortage.
How many units are missing per replenishment cycle?
Hold $r$ fixed and apply the expected-shortage formula of Section 3, $E[(D-Q)^+]=\sigma L(z)$, to random lead-time demand:
$$n(r)=E[(D_L-r)^+],\qquad z=\frac{r-\mu L}{\sigma\sqrt L}.$$ $$\boxed{n(r)=\sigma\sqrt L\,L(z)}.$$We reuse the standard normal loss function from Section 3. It counts shortage size as well as shortage probability. At service target $\alpha$, $z=z_\alpha$. Here $L$ without parentheses is lead time and $L(z)$ is the normal loss function. This is the standard approximation to expected shortage units per replenishment cycle.
What fraction of demand units is served immediately?
How often is there no shortage at all? Shortage size does not enter this probability.
On average, $n(r)$ units per cycle wait for delivery. Each cycle supplies $Q$ units, so $n(r)/Q$ is the fraction not served immediately.
A penalty per delayed unit depends on $n(r)$, or equivalently on $1-\beta$, rather than just on $1-\alpha$. Backordered units are eventually served. This fill-rate relation is the standard $(r,Q)$ approximation.
For $L=2$, $z_{0.95}\approx1.64485$ and $Q\approx1{,}581.14$:
$$\begin{aligned} n(r)&=74.8\sqrt2\;L(1.64485)\approx2.2101\ \text{units per cycle},\\[4pt] \beta&\approx1-\frac{2.2101}{1{,}581.14}\approx99.86\%. \end{aligned}$$The model predicts shortages in 5% of cycles, but only about 2.21 delayed units per cycle on average. At roughly $12{,}000/1{,}581.14=7.59$ cycles/year, this is about 16.77 delayed units/year. The 2.21-unit average includes cycles with no shortage; it is not the shortage size conditional on a shortage.
What costs are we balancing when service rises?
$$\text{annual cost}\;\approx\;\underbrace{\frac{Kd}{Q}}_{\text{ordering}} +\underbrace{h\Big(\frac Q2+ss\Big)}_{\text{holding}} +\underbrace{c_p\frac dQn(r)}_{\text{shortage penalty}}.$$- $Q/2$ is cycle stock, $ss$ is safety stock and $d/Q$ is approximate cycles per year.
- $c_p$ is the penalty per delayed unit; $(d/Q)n(r)$ is expected delayed units per year.
- Hold $Q$ at its EOQ. Raising $\alpha$ raises $r$ and $ss$, increasing holding cost but reducing $n(r)$ and shortage cost.
Session 1 calculated stock for a given target. We can now compare the costs of targets, holding $Q$ and lead time fixed. Selecting EOQ first does not jointly minimize all the terms over $r$ and $Q$. The newsvendor's critical ratio is not the optimum for this recurring-order system.
Is moving from 95% to 99% service worth its cost?
For $L=2$ and $Q\approx1{,}581.14$, ordering and cycle-stock costs are unchanged:
| Target $\alpha$ | 95% | 99% |
|---|---|---|
| Safety-stock holding cost / year | €417.59 | €590.61 |
| Expected shortage $n(r)$ / cycle | 2.2101 | 0.3585 |
| Expected delayed units / year | 16.77 | 2.72 |
If $c_p=20$ euros per delayed unit, moving to 99% saves about €108/year overall. If $c_p=5$ euros, it adds about €103/year. Comparing two targets does not yet find the best target among all possibilities. Change $\alpha$ in the interactive above to see how holding cost, shortage frequency, expected shortage units and fill rate move.
The time scale is part of the demand-model assumption
The model uses weekly demand. Rescaling the same normal model to days gives a very different amount of probability on negative demand:
| Normal model | Mean | Standard deviation | Probability below zero |
|---|---|---|---|
| Weekly | 230.5 | 74.8 | about 0.10% |
| Daily rescaling | $230.5/7\approx32.9$ | $74.8/\sqrt7\approx28.3$ | about 12.2% |
A normal demand approximation is reasonable when $\sigma$ is small relative to $\mu$, so that little probability lies below zero. Weekly demand has $\mu/\sigma\approx3.1$ and about 0.1% negative mass. The daily rescaling, with $\mu/\sigma\approx1.2$, is much less plausible. Distributions on nonnegative values, such as the gamma or lognormal, avoid negative demand. In the simulation, negative weekly draws are set to zero, while the formulas use the untruncated normal approximation.
5. Yield uncertainty: when the delivered quantity is random
Amélie orders $Q$ units but receives $YQ$ usable units, where $Y$ is a random yield fraction. For example, part of a shipment may arrive damaged. Begin with a supplier whose mean yield is $\mu_Y=0.9$ and standard deviation is $\sigma_Y=0.1$. We choose $Q>0$ before observing $Y$.
Use Session 2's values: deterministic demand rate $d=12{,}000$ units/year, order cost $K=250$ euros and holding cost $h=2.4$ euros per unit per year.
- Successive yields are independent and identically distributed, with $0\le Y\le1$ and $\mu_Y>0$.
- Demand flows at the fixed rate $d$. Replenishment is instantaneous when stock reaches zero.
First solve this numerical problem with the tools of Sessions 1 and 2, then recover the general formula.
A realized yield determines both receipt and cycle length
Lowercase $y$ is a realized value of the random yield $Y$. The receipt $yQ$ lasts $T_y=yQ/12{,}000$ years. Inventory falls linearly from $yQ$ to zero, so its area is a triangle:
$$\begin{aligned} T_y&=\frac{yQ}{12{,}000},\\[4pt] \text{inventory area}&=\frac12(yQ)\frac{yQ}{12{,}000} =\frac{y^2Q^2}{2(12{,}000)},\\[4pt] H_y&=\frac{2.4y^2Q^2}{2(12{,}000)}. \end{aligned}$$Before yield is observed, cycle length $T_Y$ and cycle holding cost $H_Y$ are random. The triangle's area depends on $y^2$, so we will need the second moment $E[Y^2]$.
What are we minimizing, and what do we choose?
$$\min_{Q>0}G(Q),\qquad G(Q)=\frac{250+E[H_Y]}{E[T_Y]}.$$- Choice variable: ordered quantity $Q$, held fixed inside each expectation.
- Objective: long-run ordering and holding cost, in euros per year.
- A cycle costs $250+H_Y$ euros and lasts $T_Y$ years. Divide average cycle cost by average cycle length (the renewal-reward theorem).
Longer cycles occupy more time. Averaging each cycle's cost rate with equal weight would give the wrong time average. As in Session 2, we want $G'(Q^*)=0$ and a second-order check. First express $G$ as a deterministic function of $Q$.
Use linearity of expectation, holding $Q$ fixed
$$\begin{aligned} E[T_Y]&=E\!\left[\frac{YQ}{12{,}000}\right] =\frac{Q}{12{,}000}E[Y]=\frac{0.9Q}{12{,}000},\\[6pt] E[H_Y]&=E\!\left[\frac{2.4Y^2Q^2}{2(12{,}000)}\right] =\frac{2.4Q^2}{2(12{,}000)}E[Y^2],\\[6pt] G(Q)&=\frac{250+2.4Q^2E[Y^2]/[2(12{,}000)]}{0.9Q/12{,}000}\\[6pt] &=\frac{3{,}000{,}000}{0.9Q}+\frac{2.4E[Y^2]}{1.8}Q. \end{aligned}$$We know $E[Y]=0.9$. How can we obtain $E[Y^2]$ from the supplied standard deviation?
Rearrange Session 1's variance formula
$$\begin{aligned} \operatorname{Var}(Y)&=E[Y^2]-(E[Y])^2,\\[4pt] \sigma_Y^2&=E[Y^2]-\mu_Y^2,\\[4pt] E[Y^2]&=\mu_Y^2+\sigma_Y^2=0.9^2+0.1^2=0.82. \end{aligned}$$Substitute into the expected-cost function:
$$\boxed{G(Q)=\frac{3{,}000{,}000}{0.9Q}+\frac{2.4(0.82)}{1.8}Q}.$$Using just the average yield would miss the $0.1^2$ variance term. We now have a function of one choice variable, ready to differentiate.
Take the first-order condition: solve for the order
$$\begin{aligned} G'(Q)&=-\frac{3{,}000{,}000}{0.9Q^2}+\frac{2.4(0.82)}{1.8},\\[6pt] G'(Q^*)=0\quad&\Rightarrow\quad \frac{3{,}000{,}000}{0.9(Q^*)^2}=\frac{2.4(0.82)}{1.8},\\[6pt] (Q^*)^2&=\frac{2(250)(12{,}000)}{2.4(0.82)}. \end{aligned}$$ $$\boxed{Q^*\approx1{,}746.08\ \text{ordered units}}.$$The order is larger than the perfect-yield EOQ of 1,581.14. Average receipt is $0.9Q^*\approx1{,}571.47$ units.
Check the second-order condition and the boundaries
$$G''(Q)=\frac{2(3{,}000{,}000)}{0.9Q^3}>0\qquad\text{for every }Q>0.$$- Second-order condition: positive curvature makes the stationary point a minimum.
- Global check: $G$ is strictly convex on $Q>0$; the minimum is unique.
- As $Q\to0$, ordering cost tends to infinity. As $Q\to\infty$, holding cost tends to infinity.
Thus $Q^*\approx1{,}746.08$ minimizes long-run cost, about €3,818.09/year. For integer orders, compare 1,746 and 1,747; 1,746 is better.
The same steps give the general formula
If we leave $K$, $d$, $h$ and the yield moments as symbols,
$$\begin{aligned} G(Q)&=\frac{Kd}{\mu_YQ}+\frac{h(\mu_Y^2+\sigma_Y^2)}{2\mu_Y}Q,\\[6pt] G'(Q^*)&=-\frac{Kd}{\mu_Y(Q^*)^2} +\frac{h(\mu_Y^2+\sigma_Y^2)}{2\mu_Y}=0. \end{aligned}$$ $$\boxed{Q^*=\sqrt{\frac{2Kd}{h(\mu_Y^2+\sigma_Y^2)}}}.$$For positive $K$, $d$, $h$ and $\mu_Y$, $G''(Q)=2Kd/(\mu_YQ^3)>0$. If $Y=1$ always, $\mu_Y=1$ and $\sigma_Y=0$: we recover Session 2's EOQ.
More yield variability lowers the optimal order quantity
Long-run cost rate $G(Q)$ for a supplier with random yield, compared with the perfect-yield EOQ cost $Kd/Q+hQ/2$. Each dot is the minimum of its curve. The vertical axis starts at €3,000.
Base supplier, $\mu_Y=0.9$ and $\sigma_Y=0.1$: $Q^*\approx1{,}746$, average receipt $\mu_YQ^*\approx1{,}571$ and minimum cost €3,818.09 per year, about 0.62% above perfect yield. Raising $\sigma_Y$ to 0.3 gives $Q^*\approx1{,}667$, an average receipt of 1,500 and €4,000 per year (5.41% above perfect yield, 8 expected orders per year). Lowering $\mu_Y$ to 0.7 with $\sigma_Y=0.3$ gives $Q^*\approx2{,}076$, an average receipt of about 1,453 and €4,128.55 per year (8.80% above). The sliders keep $\sigma_Y^2\le\mu_Y(1-\mu_Y)$, which every yield fraction in $[0,1]$ satisfies.
Read yield comparisons within the model's assumptions
At a fixed mean yield, more variance raises $E[Y^2]$ and reduces $Q^*$. For a yield fraction in $[0,1]$, $E[Y^2]\le1$, so $Q^*$ is at least as large as the perfect-yield EOQ. The moments must satisfy $\sigma_Y^2\le\mu_Y(1-\mu_Y)$. In this model, smaller and more frequent orders balance ordering and holding costs, but they do not provide protection against stockouts, because replenishment is instantaneous. An order quantity and its average usable receipt $\mu_YQ^*$ are different quantities.
6. The general method: choosing the right model
- Identify the choice variable, the random variable and its assumed distribution, and the feasible set. The choice is made before the random variable is observed.
- Write the objective as a function of both, such as $\pi(Q,D)$, then take its expected value with the choice held fixed.
- Solve the first-order condition of the expected objective, check convexity for a cost or concavity for a profit, and inspect the boundaries of the feasible set.
- A service target instead fixes a probability requirement, which determines a quantile.
In this session, the newsvendor and reorder-point solutions are quantiles of a demand distribution, and the yield model gives a square-root formula. Other objectives may require numerical optimization.
| Decision | Random quantity | Condition or rule | Criterion |
|---|---|---|---|
| One-time order $Q$ | demand $D$ | $F(Q^*)=c_u/(c_u+c_o)$ | maximize expected profit (§2) |
| Reorder point $r$ | lead-time demand $D_L$ | $r=\mu L+z_\alpha\sigma\sqrt L$ | meet a cycle-service target (§4) |
| Recurring order $Q$ | yield $Y$ | $Q^*=\sqrt{2Kd/[h(\mu_Y^2+\sigma_Y^2)]}$ | minimize long-run cost rate (§5) |
Summary
- When a choice is made before a random variable is observed, the objective is a random variable. We optimize its expected value.
- The critical ratio compares the costs of the two newsvendor errors and gives the optimal order as a demand quantile.
- Safety stock covers lead-time demand uncertainty. Cycle service and fill rate measure different outcomes.
- Random yield changes the EOQ through the second moment $E[Y^2]$.
So far, each decision has been made by one decision-maker alone. In Session 4, the supplier also makes a choice, and we study how the two decision-makers' choices interact and how contracts change them.