# Optimal service level formula for inventory optimization

By Joannès Vermorel, last revised January 2012

Service level (inventory) represents the expected probability of not hitting a stock-out. This percentage is required to compute the safety stock. Intuitively, the service level represents a trade-off between the cost of inventory and the cost of stock-outs (which incur missed sales, lost opportunities and client frustration among others). In this article, we detail how to optimize the service level value. Then, the analysis is refined for the special case of perishable food.

The article has been written from a classic forecasting viewpoint back in 2011. However, a few years later, we now realize that there are much better options available if the forecasting technology is capable of entirely removing the need to optimize the service levels as it is the case with quantile grids.

## Model and formula

The classical supply chain literature is somewhat fuzzy concerning the numerical values that should be adopted for service level. Below, we propose to compute an optimal service level by modeling the respective cost of inventory and stock-outs.

Let's introduce the following variables:
• $p$ be the service level, i.e. the probably of not having a stock-out.
• $H$ be the carrying cost per unit for the duration of the lead time (1).
• $M$ be the marginal unit cost of stock-out (2).

Lokad is the leading inventory optimization company, our technology has been developed to go past traditional forecasting tools to provide better insight and guidance for true inventory and pricing optimization.

(1) The time scope considered here is the lead-time. Hence, instead of considering the more usual annual carrying cost $H_y$, we are considering $H = \frac{d}{365}H_y$ assuming that $d$ is the lead time expressed in days.

(2) The stock-out cost includes a minima the gross margin, i.e. instant profit that would have been generated if no stock-out had been encountered. However, the loss of gross margin is not the only cost: for example, customer frustration and loss of customer loyalty should also be taken into account. As a rule of thumb, we have observed that many food retailers consider $M$ to be equal to 3 times the gross margin.

The optimal service level is given by (the reasoning is detailed below): $$p=\Phi\left(\sqrt{2\ln\left(\frac{1}{\sqrt{2\pi}}\frac{M}{H}\right)}\right)$$ Where $\Phi$ is the cumulative distribution function associated to the normal distribution. This value can be computed easily in Excel, $\Phi$ is the NORMSDIST function. Also, for sake of numerical computation: $\sqrt{2 \pi} \approx 2.50$

## Cost function

In order to model the cost function, let's introduce two more variables:
• $Q$ the amortized inventory quantity (3), a function that depends on $p$.
• $O$ the average overflowing demand when a stock-out it hit.

(3) We are adopting here an Amortized Analysis viewpoint. The inventory level is varying all the time, but our goal here, in order to make the analysis practical, is to obtain a service level value that is decoupled from the demand forecast itself. Hence, we will assume $Q$ to be equal to the reorder point (check our guide about safety stock for the detail).

For a given service level, the total cost $C(p)$ that combines both inventory holding cost and stock-out costs can be written: $$C(p) = Q(p)H + (1-p)MO$$ Where $Q(p)H$ is the inventory cost and $MO$ the stock-out cost, only happening with a probability $1-p$. Using the formula introduced in our safety stock tutorial, and since $Q(q)$ is equal to the reorder point, we have $Q(p) = Z + \sigma \Phi^{-1}(p)$ where $Z$ is the lead demand, $\sigma$ expected forecast error and $\Phi(p)^{-1}$ the inverse of the cumulative distribution function associated to the standard normal distribution (zero mean and variance of one).

### Analysis of average missed sales

The analysis of $O$, the average missed sales, is subtle. Considering that distribution of the demand is the normal distribution $\mathcal{N}$ and that $q$ is the available inventory, $O(q)$ is the conditional mean of the demand $x$ when $x > q$ (minus the available inventory $q$), that is: $$O(q)=\frac{\int_q^\infty{x\mathcal{N}(x)dx}}{\int_q^\infty{\mathcal{N}(x)dx}}-q=\frac{1}{q}+\mathcal{o}\left(\frac{1}{q}\right)$$ Browse the function at (1).

This result can be interpreted as: if the demand is rigorously following the normal distribution, then the average quantity of missed sales in the (conditional) event of a stock-out quickly converges to zero as the inventory level grows.

Yet, in our experience, the forecast error does not have a convergence as good as the one the normal distribution would predict. Hence, below, we will assume that $O=\sigma$ that is to say that the average amount of missed sales is equal to the average forecast error. Obviously, this is more a rule of thumb than an in-depth analysis; but we have found that in practice, this approximation gives sensible results.

## Minimization of the cost function

By applying the replacements defined here above to the expression of $C(p)$, we obtain: $$C(p) = \left(Z + \sigma \Phi^{-1}(p)\right)H + (1-p)M\sigma$$ Then, the $C(p)$ expression can be differentiated in $p$ with: $$\frac{\partial C}{\partial p} = \sigma H \partial \Phi^{-1}(p) - \sigma M$$ Since we are looking for the minimum value, we try to solve $\frac{\partial C}{\partial p} = 0$ which gives: $$\sigma H \partial \Phi^{-1}(p) - \sigma M = 0$$ Which can be simplified in $\sigma$, with: $$H \partial \Phi^{-1}(p) - M = 0$$ And finally: $$\partial \Phi^{-1}(p) = \frac{M}{H}$$ Then, we will use the relationship between $\partial \Phi^{-1}$ and $\Phi^{-1}$ : $$\partial \Phi^{-1}(p)=\sqrt{2\pi}e^{\frac{1}{2}\Phi^{-1}(p)^2}$$ For a visual proof of the equality you can compare (1) and (2).

This relationship let us obtain: $$\sqrt{2\pi}e^{\frac{1}{2}\Phi^{-1}(p)^2}=\frac{M}{H}$$ $$\frac{1}{2}\Phi^{-1}(p)^2=\ln\left(\frac{1}{\sqrt{2\pi}}\frac{M}{H}\right)$$ We take the positive root solution of the equation (the negative root corresponds to a local maximum of the function) with: $$\Phi^{-1}(p)=\sqrt{2\ln\left(\frac{1}{\sqrt{2\pi}}\frac{M}{H}\right)}$$ And finally by applying $\Phi$ to both sides, we obtain the optimal service level with: $$p=\Phi\left(\sqrt{2\ln\left(\frac{1}{\sqrt{2\pi}}\frac{M}{H}\right)}\right)$$

## Discussion of the formula

The first interesting aspect of the formula is that the optimal service level only depends on $H$ (inventory cost) and $M$ (stock-out cost). However, there is an implicit dependency on the lead-time as $H$ has been defined as the carrying cost for the duration of the lead time.

Second, a greater inventory cost lowers the optimal service level; and similarly a greater stock-out cost increases the service level. This behavior is rather intuitive because the service level is a trade-off between more inventory and more stock-outs.

Then, the formula is not valid for all values of $M$ and $H$. We need $\sqrt{2\pi}\frac{M}{H} > 1$ or the logarithm will produce a negative value which is not tractable considering the outer square root. This gives $M > \sqrt{2 \pi} H$, which can be approximated as $M > 2.5 H$. If this condition is not verified, then it means that the initial cost function $C(p)$ has no minimum, or rather that the minimum is $-\infty$ for $p=0$. From a practical angle, $M < 2.5 H$ could be interpreted as a pathological situation where the most profitable stock level is zero stock (i.e. 100% stock-outs).

## Practical example

Let's consider a 1L milk pack at 1.50€ selling price sold with 10% margin (i.e. 0.15€ of gross margin). Let's assume that the lead time is 4 days. The annual carrying cost is 1.50€ (the value is high because milk is a highly perishable product). We assume that the stock-out cost is 3 time the gross margin, that is to say 0.45€. This gives $M=0.45$ and $H=\frac{4}{365} 1.5\approx 0.0055$.

Based on those values and on the formula for optimal service level obtained here above, we obtain $p\approx 98.5\%$ which is a typical value for must-have fresh products stored in warehouses feeding grocery store networks.

## Perishable food

Question raised by Vyacheslav Grinkevych, supply chain expert, 2012-02-13:

I am working on Forecasting and Supply Planning for short-life dairy products where the optimal service level is a very important subject. The most interesting and tricky component here is H – the carrying cost and the question of its proper value in practice.

For example, for short-life dairy products one of the important part of H should be not only pure financial cost of cash frozen in inventory and operational logistics storage cost but also the cost of potential losses due to write-off of expired products or sales with discounts when we are trying to sell-out more just before expiration. This happens when your sales are well below the forecast.

This tradeoff can be described as the risk of potential over-stocks vs. the risk of potential stock-out – two risks that work in opposite directions while they have the same origin by nature – i.e. interconnected with the safety stock. In case of big overforecasting, which usually causes expiry issue, forecast errors are not normally distributed. Thus I am wondering how to better express such potential over-stocks risks.

Back to your formula, its further development could be to try to find a relationship between H and p or to make H a function of p, i.e. H(p), before going for the minimization of the total cost C(p). What are your thoughts on this matter?

The service level formula given here above is indeed based on a simplistic assumption where costs, both storage and stock-outs, are stricly linear. However, in practice, brutal non-linearities can be found such as:

• Warehouse is full, and there is a point where 1 extra unit of stock actually involve the massive overhead of getting an extra warehousing location.
• Stock-outs cause incremental lost sales to reach the point where one extra stock-out causes the loss of the whole recurring client.

Perishable products present another twist: if the stock cover, that is to say the stock expressed in days rather than in unit of stock, gets close to the product expiration lifetime, then $H$, the carrying cost increases toward an infinite value.

Indeed, $H$ represents the friction associated with having inventory in the first place. A stock cover greater than the expiration lifetime of the product represents an absurd situation where, assuming a FIFO (First In, First Out) inventory, no product would get out of the storage location without hitting first its expiration date.

In order to model the effect of the perishability of the inventory, let's introduce a couple of key durations:

• $\lambda$, the lead time.
• $\lambda_\infty$, the lifetime of the product before hitting terminal expiration (i.e. zero market value).
• $\lambda_½$, the duration that doubles the original carrying cost of the product because of loss of its market value.
• $\lambda_c(p)$, the stock cover, that is the stock expressed in days rather than product units. This duration depends on the safety stock factor, hence depends of $p$.

With those durations, we can model the carrying cost as:

$$H(p) = H \left(1 - \frac{\lambda_\infty - \lambda_½}{\lambda_\infty - \lambda} + \frac{\lambda_\infty - \lambda_½}{\lambda_\infty - \lambda_c(p)} \right)$$ Let's detail the implicit assumption here, because we are somewhat bending the usual notion of the carrying cost in order to factor the risk of write-off.

First, we have $H(0.5)=H$. This is obtained from the very definition here above. Indeed $\lambda_c(0.5)=\lambda$, with a service level at 50%, the stock cover equals the lead time. Hence, we are stating here that, in this model, $H$ represents the carrying cost where the write-off costs associated to a service level of 50% have already been factored into the cost $H$. It's notable to remark that zero safety stocks do not imply zero write-offs, only infrequent write-offs.

Second, for the service level $p_½$ such as $\lambda_c(p_½) = \lambda_½$, then we have $H(p_½)=2H$. Again, this is only a consequence of the definition adopted for $H(p)$. Intuitively, $\lambda_½$ represents the duration that doubles the combination of carrying costs plus write-off costs, as compared to the zero safety stock situation. It's clear that in practice, the cost overhead involved with end-of-life discounts and write-offs will go through discrete steps. However, we believe that trying to express this overhead through a typical duration which in practice would be defined as a certain fraction of the life-time of the product is likely to be much more resilient to the various approximations that entail the whole approach, as opposed to a more finer-grained model relying on even more uncertain variables.

Finally, as $p$ gets closer from $p_\infty$ with $\lambda_c(p_\infty)=\lambda_\infty$, then $H(p)$ tends to infinity, again by definition of the adopted function for $H(p)$. At first glance, it seems odd to have a carrying cost that goes over the product unit cost, but there is no paradox here. The value $H(p)$ represents the friction cost to get one unit shipped to the client. If, because of massive write-offs, in order to ship 1 unit to the final client, the warehouse receives 3 units on average (2 units expiring before being delivered), then the friction costs will be much greater than the original unit price of the product.

In summary, $\lambda_½$ is only one uncertain variable being introduced. $\lambda$ and $\lambda_\infty$ can safely be assumed to be known. We believe that this model for $H(p)$ is about the simplest possible that can be achieve by introducing only 1 extra variable. Then, for $\lambda_c(p)$, with a modest approximation, we have:

$$\lambda_c(p) = \lambda \left(1 +\frac{\sigma}{Z}\Phi^{-1}(p)\right)$$ Indeed, $\lambda_c$, the stock-cover can be be seen as a ratio over the lead-time that includes the lead demand plus a normalized safety stock factor. This gives the alternative cost function:

$$C^*(p) = \left(Z + \sigma \Phi^{-1}(p)\right)H\left(1 - \frac{\lambda_\infty - \lambda_½}{\lambda_\infty - \lambda} + \frac{ \lambda_\infty - \lambda_½}{\lambda_\infty - \lambda \left(1 +\frac{\sigma}{Z}\Phi^{-1}(p)\right)} \right) + (1-p)M\sigma$$ Unlike the previous cost function, this function does not seem to have a simple algebraic mimimum. However, by adopting an approach similar to the one used for the calculation of the economic order quantity, it is relatively straightforward to find an approximate solution by iterating through 0.1% increments from 80% to 99.9%. This represents 200 iterations to achieve 0.1% precision that would be vastly sufficient for practical purposes.

## Intended practical use

The service level formula comes with a couple of approximations, so the numerical values may not be usable out of the box: it will typically require a bit of tuning. In particular, the factor $\frac{1}{\sqrt(2\pi)}\approx0.4$ can be adjusted on a need basis. However, we believe that this formula gives a good insight how the respective service levels of your items should compare. For example, if for two products A and B, you get service levels of respectively 95% (for A) and 90% (for B), then for the final production setup, it would be expected that the service level for A to be greater than the service level for B.

Then, considering the nature of the analysis that has been made here above, we believe that this formula is not relevant for products associated to a low or intermittent demand. Indeed, such low volume products are typically associated to low reorder point at 0 or 1 unit; and a linear modeling of the storage cost for the product does not necessarily make sense as the complexity for storing one extra reference should also be taken into account.

Get optimized sales forecasts with our inventory optimization software technology. Lokad specializes in inventory optimization through demand forecasting. Service levels - and much more - are native features of Lokad.