How many cupcakes should you bake?
A look at a classic operations management model for deciding how much inventory to carry.
This week’s post is about one of my favorite concepts from business school: the newsvendor model. This model comes from operations management. Specifically, it is a tool that helps people decide how much inventory to order for a fixed period when demand is uncertain. Let’s jump in.
The cupcake stand
Suppose you have a cupcake stand and sell cupcakes everyday to passersby. You bake all the cupcakes the night before, so every night you need to decide how many to bake for the next day. This is a major decision because:
You sell each cupcake for p = $3, so if you run out of cupcakes, you’ll miss out on revenue.
Each cupcake costs you c = $1 to make, so if you bake too many, you’ll have to eat (no pun intended) the costs of producing the extra cupcakes. (Cupcakes go stale before the following day.)
How would you decide how many cupcakes to bake? Well, you haven’t gone out of business yet, so you probably have the good sense to keep track of your historical demand. Let’s say that you reviewed your records and discovered that daily demand is approximately normally distributed with mean μ = 100 cupcakes and standard deviation σ = 20 cupcakes. Practically speaking, this means that most of the time (~2 out of every 3 days) your demand will be between 80 and 120 cupcakes.
In light of this information, one sensible answer is to bake 100 cupcakes each night based on your average demand. Let’s calculate what your profit would be on a day in which the demand for cupcakes is X. Your margin on each cupcake is $(3 - 1) = $2. The number of cupcakes that you sell is equal to the smaller of X and 100, since you can’t sell more than you bake. However, if you bake more cupcakes than are demanded, it costs you $1 for each extra cupcake. Putting these together, we arrive at the profit formula:
To calculate the payoff of this decision, I simulated 100 days of cupcake demand in Excel using NORM.INV(RAND(), 100, 20).1 Baking 100 cupcakes each night resulted in an average daily profit of $180.29, with a minimum profit of $65 and maximum of $200. Note that $200 is the maximum you would earn on any given day because you can’t sell more cupcakes than you bake. The minimum profit of $65 occurred on a day when only 55 customers visited, resulting in gross profits of $110, less $45 for wasted cupcakes.
Is this good? I don’t know. To investigate further, I calculated the daily profit for the same daily demand for output levels of {90, 95, 100, 105, 110} cupcakes. The results are as follows:
Evidently, 100 cupcakes is not the right number to bake each night. Your average daily profit will be higher if you bake more than 100. The tradeoff is that the standard deviation of your daily profit increases, and the minimum daily profit decreases. In other words, you’ll have higher average profit, but larger swings in profit, if you bake more cupcakes each night. The above chart suggests that 110 cupcakes is the optimal amount to bake among these 5 options. I confirmed with Excel’s solver that 110 is globally optimal (cf., attached workbook).
The newsvendor model
I used a simulation to determine the optimal quantity of cupcakes to bake each night. It’s fair to ask if you can derive the answer analytically. To that end, suppose that you have already baked 100 cupcakes, and you want to decide if you should bake one more. (Pretend you have an Easy Bake Oven.) Under what circumstances would it be a good idea to bake one more cupcake? The logical answer is that it would be smart if doing so increases your expected profit. The expected value of a random variable is the weighted average of the possible outcomes. The weight for each outcome is the probability of that outcome occurring. In this case, the two outcomes are that you sell it—which increases your profit by (p - c)—or that you don’t—which decreases your profit by c.
What about the probability of each outcome? The probability of losing money on the 101st cupcake is equivalent to the probability of demand being less than 101. Keeping in mind that demand is normally distributed, this probability is found by taking the area under the normal curve to the left of Q = 101. The same argument shows that the probability of increasing your profits is given by the area under the curve to the right of Q = 101. Define the function Φ(Q) to be the area under the normal curve to the left of Q.2 (In other words, Φ is the cumulative density function for the normal curve.) Note that 1 - Φ(Q) is the area under the curve to the right of Q. We now have all the ingredients (again, no pun intended) to calculate the expected impact on profit of baking the 101st cupcake:
The expected change to profit is positive, so indeed you should bake the 101st cupcake. What about the 102nd cupcake? Applying the same reasoning yields an expected profit increase of E[Δ profit] = 2 - 3*(.54) = .38 > 0. If you keep asking this question, you’ll find that the first time that your profit is expected to decrease with an extra cupcake is the 109th. Therefore, you should stop at 108 cupcakes. (This differs slightly from the simulation because the average demand over the 100 simulated days was 103 cupcakes per day, slightly higher than expected.)
Checking each cupcake for the incremental expected profit is pretty tedious. The shortcut is to realize that we’re looking for the cupcake where E[Δ profit] changes from positive to negative. In other words, we want to know when E[Δ profit] = 0. Solving that equation for Φ(Q) yields:
Remember that Φ(Q) is the area under the normal curve to the left of Q. So we want the value of Q that has area 2/3 = .667 to the left of it, which Excel says is Q = 108.6. Not even an Easy Bake Oven can bake a fraction of a cupcake, so you would round to 109. Cumulative density functions increase monotonically, which means that you can invert them. It therefore makes sense to write
We just derived what is known as the newsvendor model.3 The model is used to determine the optimal inventory level for a product for a fixed period of time in the face of uncertain demand. For example, a clothing retailer might face such a decision when ordering clothes for a season. The key to the newsvendor setup is that you incur a cost for unsold inventory at the end of the period. This is what forces you to balance the cost of stocking too much and too little. The value of Q that maximizes your expected profit—given by the formula just above—is called the critical fractile.
To build some intuition for the critical fractile, define the cost of overage (Co) = c and the cost of underage (Cu) = p - c to be the cost to the cupcake stand of overproducing by one unit and underproducing by one unit, respectively. Notice that Cu + Co = p, so we can rewrite the critical fractile in terms of these quantities.
Written this way, it’s clear that we’re picking Q to balance the cost of being understocked versus the cost of being overstocked. The larger that Cu is compared to Co, the larger the critical fractile, hence the more you want to err on the side of overproducing. Note that the only time you want to produce exactly as many cupcakes as you expect to sell is when the cost of overage and underage are equal. One final observation about the critical fractile: I assumed that demand was normally distributed in this example. You don’t need to make that assumption. Φ could be a generic cumulative density function, and this formula is still valid. This is an underrated benefit of this model, as many of the analytical tools used in operations management do lean on an assumption of normality.
That’s all for today. In a future edition, I’ll bring some calculus to the newsvendor party. Additionally, I’ll show you what the newsvendor model can teach us about classification problems. If you enjoyed reading, please subscribe and share the newsletter with your network.
The RAND() part generates a random number between 0 and 1. The NORM.INV part finds the value whose left-tail probability under the normal distribution with μ = 100 and σ = 20 is equal to that random number. You could use this paradigm for any other probability distribution, as long as you have a formula for the CDF.
In Excel, Φ(Q) = NORM.DIST(Q, 100, 20, 1). The “1” denotes cumulative probability, which is the area under the curve.
The name newsvendor comes from the example used to explain the concept in an early textbook on the topic: a boy delivering newspapers must decide how many to order each morning.