62. Production Smoothing via Inventories#

In addition to what’s in Anaconda, this lecture employs the following library:

!pip install quantecon
Hide code cell output
Requirement already satisfied: quantecon in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (0.8.1)
Requirement already satisfied: numba>=0.49.0 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from quantecon) (0.60.0)
Requirement already satisfied: numpy>=1.17.0 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.26.4)
Requirement already satisfied: requests in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from quantecon) (2.32.3)
Requirement already satisfied: scipy>=1.5.0 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.13.1)
Requirement already satisfied: sympy in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.14.0)
Requirement already satisfied: llvmlite<0.44,>=0.43.0dev0 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from numba>=0.49.0->quantecon) (0.43.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (2024.8.30)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/runner/miniconda3/envs/quantecon/lib/python3.12/site-packages (from sympy->quantecon) (1.3.0)

62.1. Overview#

This lecture can be viewed as an application of this quantecon lecture about linear quadratic control theory.

It formulates a discounted dynamic program for a firm that chooses a production schedule to balance

  • minimizing costs of production across time, against

  • keeping costs of holding inventories low

In the tradition of a classic book by Holt, Modigliani, Muth, and Simon [Holt et al., 1960], we simplify the firm’s problem by formulating it as a linear quadratic discounted dynamic programming problem of the type studied in this quantecon lecture.

Because its costs of production are increasing and quadratic in production, the firm holds inventories as a buffer stock in order to smooth production across time, provided that holding inventories is not too costly.

But the firm also wants to make its sales out of existing inventories, a preference that we represent by a cost that is quadratic in the difference between sales in a period and the firm’s beginning of period inventories.

We compute examples designed to indicate how the firm optimally smooths production while keeping inventories close to sales.

To introduce components of the model, let

  • St be sales at time t

  • Qt be production at time t

  • It be inventories at the beginning of time t

  • β(0,1) be a discount factor

  • c(Qt)=c1Qt+c2Qt2, be a cost of production function, where c1>0,c2>0, be an inventory cost function

  • d(It,St)=d1It+d2(StIt)2, where d1>0,d2>0, be a cost-of-holding-inventories function, consisting of two components:

    • a cost d1It of carrying inventories, and

    • a cost d2(StIt)2 of having inventories deviate from sales

  • pt=a0a1St+vt be an inverse demand function for a firm’s product, where a0>0,a1>0 and vt is a demand shock at time t

  • π_t=ptStc(Qt)d(It,St) be the firm’s profits at time t

  • t=0βtπt be the present value of the firm’s profits at time 0

  • It+1=It+QtSt be the law of motion of inventories

  • zt+1=A22zt+C2ϵt+1 be a law of motion for an exogenous state vector zt that contains time t information useful for predicting the demand shock vt

  • vt=Gzt link the demand shock to the information set zt

  • the constant 1 be the first component of zt

To map our problem into a linear-quadratic discounted dynamic programming problem (also known as an optimal linear regulator), we define the state vector at time t as

xt=[Itzt]

and the control vector as

ut=[QtSt]

The law of motion for the state vector xt is evidently

[It+1zt]=[100A22][Itzt]+[1100][QtSt]+[0C2]ϵt+1

or

xt+1=Axt+But+Cϵt+1

(At this point, we ask that you please forgive us for using Qt to be the firm’s production at time t, while below we use Q as the matrix in the quadratic form utQut that appears in the firm’s one-period profit function)

We can express the firm’s profit as a function of states and controls as

πt=(xtRxt+utQut+2utNxt)

To form the matrices R,Q,N in an LQ dynamic programming problem, we note that the firm’s profits at time t function can be expressed

πt=ptStc(Qt)d(It,St)=(a0a1St+vt)Stc1Qtc2Qt2d1Itd2(StIt)2=a0Sta1St2+GztStc1Qtc2Qt2d1Itd2St2d2It2+2d2StIt=(d1It+d2It2xtRxt+a1St2+d2St2+c2Qt2utQuta0StGztSt+c1Qt2d2StIt2utNxt)=([Itzt][d2d12Scd12Sc0]R[Itzt]+[QtSt][c200a1+d2]Q[QtSt]+2[QtSt][0c12Scd2a02ScG2]N[Itzt])

where Sc=[1,0].

Remark on notation: The notation for cross product term in the QuantEcon library is N.

The firms’ optimum decision rule takes the form

ut=Fxt

and the evolution of the state under the optimal decision rule is

xt+1=(ABF)xt+Cϵt+1

The firm chooses a decision rule for ut that maximizes

E0t=0βtπt

subject to a given x0.

This is a stochastic discounted LQ dynamic program.

Here is code for computing an optimal decision rule and for analyzing its consequences.

import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (11, 5)  #set default figure size
import numpy as np
import quantecon as qe
class SmoothingExample:
    """
    Class for constructing, solving, and plotting results for
    inventories and sales smoothing problem.
    """

    def __init__(self,
                 β=0.96,           # Discount factor
                 c1=1,             # Cost-of-production
                 c2=1,
                 d1=1,             # Cost-of-holding inventories
                 d2=1,
                 a0=10,            # Inverse demand function
                 a1=1,
                 A22=[[1,   0],    # z process
                      [1, 0.9]],
                 C2=[[0], [1]],
                 G=[0, 1]):

        self.β = β
        self.c1, self.c2 = c1, c2
        self.d1, self.d2 = d1, d2
        self.a0, self.a1 = a0, a1
        self.A22 = np.atleast_2d(A22)
        self.C2 = np.atleast_2d(C2)
        self.G = np.atleast_2d(G)

        # Dimensions
        k, j = self.C2.shape        # Dimensions for randomness part
        n = k + 1                   # Number of states
        m = 2                       # Number of controls

        Sc = np.zeros(k)
        Sc[0] = 1

        # Construct matrices of transition law
        A = np.zeros((n, n))
        A[0, 0] = 1
        A[1:, 1:] = self.A22

        B = np.zeros((n, m))
        B[0, :] = 1, -1

        C = np.zeros((n, j))
        C[1:, :] = self.C2

        self.A, self.B, self.C = A, B, C

        # Construct matrices of one period profit function
        R = np.zeros((n, n))
        R[0, 0] = d2
        R[1:, 0] = d1 / 2 * Sc
        R[0, 1:] = d1 / 2 * Sc

        Q = np.zeros((m, m))
        Q[0, 0] = c2
        Q[1, 1] = a1 + d2

        N = np.zeros((m, n))
        N[1, 0] = - d2
        N[0, 1:] = c1 / 2 * Sc
        N[1, 1:] = - a0 / 2 * Sc - self.G / 2

        self.R, self.Q, self.N = R, Q, N

        # Construct LQ instance
        self.LQ = qe.LQ(Q, R, A, B, C, N, beta=β)
        self.LQ.stationary_values()

    def simulate(self, x0, T=100):

        c1, c2 = self.c1, self.c2
        d1, d2 = self.d1, self.d2
        a0, a1 = self.a0, self.a1
        G = self.G

        x_path, u_path, w_path = self.LQ.compute_sequence(x0, ts_length=T)

        I_path = x_path[0, :-1]
        z_path = x_path[1:, :-1]
        𝜈_path = (G @ z_path)[0, :]

        Q_path = u_path[0, :]
        S_path = u_path[1, :]

        revenue = (a0 - a1 * S_path + 𝜈_path) * S_path
        cost_production = c1 * Q_path + c2 * Q_path ** 2
        cost_inventories = d1 * I_path + d2 * (S_path - I_path) ** 2

        Q_no_inventory = (a0 + 𝜈_path - c1) / (2 * (a1 + c2))
        Q_hardwired = (a0 + 𝜈_path - c1) / (2 * (a1 + c2 + d2))

        fig, ax = plt.subplots(2, 2, figsize=(15, 10))

        ax[0, 0].plot(range(T), I_path, label="inventories")
        ax[0, 0].plot(range(T), S_path, label="sales")
        ax[0, 0].plot(range(T), Q_path, label="production")
        ax[0, 0].legend(loc=1)
        ax[0, 0].set_title("inventories, sales, and production")

        ax[0, 1].plot(range(T), (Q_path - S_path), color='b')
        ax[0, 1].set_ylabel("change in inventories", color='b')
        span = max(abs(Q_path - S_path))
        ax[0, 1].set_ylim(0-span*1.1, 0+span*1.1)
        ax[0, 1].set_title("demand shock and change in inventories")

        ax1_ = ax[0, 1].twinx()
        ax1_.plot(range(T), 𝜈_path, color='r')
        ax1_.set_ylabel("demand shock", color='r')
        span = max(abs(𝜈_path))
        ax1_.set_ylim(0-span*1.1, 0+span*1.1)

        ax1_.plot([0, T], [0, 0], '--', color='k')

        ax[1, 0].plot(range(T), revenue, label="revenue")
        ax[1, 0].plot(range(T), cost_production, label="cost_production")
        ax[1, 0].plot(range(T), cost_inventories, label="cost_inventories")
        ax[1, 0].legend(loc=1)
        ax[1, 0].set_title("profits decomposition")

        ax[1, 1].plot(range(T), Q_path, label="production")
        ax[1, 1].plot(range(T), Q_hardwired, label='production when  $I_t$ \
            forced to be zero')
        ax[1, 1].plot(range(T), Q_no_inventory, label='production when \
            inventories not useful')
        ax[1, 1].legend(loc=1)
        ax[1, 1].set_title('three production concepts')

        plt.show()

Notice that the above code sets parameters at the following default values

  • discount factor β=0.96,

  • inverse demand function: a0=10,a1=1

  • cost of production c1=1,c2=1

  • costs of holding inventories d1=1,d2=1

In the examples below, we alter some or all of these parameter values.

62.2. Example 1#

In this example, the demand shock follows AR(1) process:

νt=α+ρνt1+ϵt,

which implies

zt+1=[1vt+1]=[10αρ][1vt]zt+[01]ϵt+1.

We set α=1 and ρ=0.9, their default values.

We’ll calculate and display outcomes, then discuss them below the pertinent figures.

ex1 = SmoothingExample()

x0 = [0, 1, 0]
ex1.simulate(x0)
_images/9cc38be528729acc22e1078e5bfd44623414932ebf97aa76a579c1372aa49a14.png

The figures above illustrate various features of an optimal production plan.

Starting from zero inventories, the firm builds up a stock of inventories and uses them to smooth costly production in the face of demand shocks.

Optimal decisions evidently respond to demand shocks.

Inventories are always less than sales, so some sales come from current production, a consequence of the cost, d1It of holding inventories.

The lower right panel shows differences between optimal production and two alternative production concepts that come from altering the firm’s cost structure – i.e., its technology.

These two concepts correspond to these distinct altered firm problems.

  • a setting in which inventories are not needed

  • a setting in which they are needed but we arbitrarily prevent the firm from holding inventories by forcing it to set It=0 always

We use these two alternative production concepts in order to shed light on the baseline model.

62.3. Inventories Not Useful#

Let’s turn first to the setting in which inventories aren’t needed.

In this problem, the firm forms an output plan that maximizes the expected value of

t=0βt{ptQtC(Qt)}

It turns out that the optimal plan for Qt for this problem also solves a sequence of static problems maxQt{ptQtc(Qt)}.

When inventories aren’t required or used, sales always equal production.

This simplifies the problem and the optimal no-inventory production maximizes the expected value of

t=0βt{ptQtC(Qt)}.

The optimum decision rule is

Qtni=a0+νtc1c2+a1.

62.4. Inventories Useful but are Hardwired to be Zero Always#

Next, we turn to a distinct problem in which inventories are useful – meaning that there are costs of d2(ItSt)2 associated with having sales not equal to inventories – but we arbitrarily impose on the firm the costly restriction that it never hold inventories.

Here the firm’s maximization problem is

max{It,Qt,St}t=0βt{ptStC(Qt)d(It,St)}

subject to the restrictions that It=0 for all t and that It+1=It+QtSt.

The restriction that It=0 implies that Qt=St and that the maximization problem reduces to

maxQtt=0βt{ptQtC(Qt)d(0,Qt)}

Here the optimal production plan is

Qth=a0+νtc1c2+a1+d2.

We introduce this It is hardwired to zero specification in order to shed light on the role that inventories play by comparing outcomes with those under our two other versions of the problem.

The bottom right panel displays a production path for the original problem that we are interested in (the blue line) as well with an optimal production path for the model in which inventories are not useful (the green path) and also for the model in which, although inventories are useful, they are hardwired to zero and the firm pays cost d(0,Qt) for not setting sales St=Qt equal to zero (the orange line).

Notice that it is typically optimal for the firm to produce more when inventories aren’t useful. Here there is no requirement to sell out of inventories and no costs from having sales deviate from inventories.

But “typical” does not mean “always”.

Thus, if we look closely, we notice that for small t, the green “production when inventories aren’t useful” line in the lower right panel is below optimal production in the original model.

High optimal production in the original model early on occurs because the firm wants to accumulate inventories quickly in order to acquire high inventories for use in later periods.

But how the green line compares to the blue line early on depends on the evolution of the demand shock, as we will see in a deterministically seasonal demand shock example to be analyzed below.

In that example, the original firm optimally accumulates inventories slowly because the next positive demand shock is in the distant future.

To make the green-blue model production comparison easier to see, let’s confine the graphs to the first 10 periods:

ex1.simulate(x0, T=10)
_images/05408dd00dffd12c9e544517cbf92df74b22c250e1634216339f61631f89d3b2.png

62.5. Example 2#

Next, we shut down randomness in demand and assume that the demand shock νt follows a deterministic path:

νt=α+ρνt1

Again, we’ll compute and display outcomes in some figures

ex2 = SmoothingExample(C2=[[0], [0]])

x0 = [0, 1, 0]
ex2.simulate(x0)
_images/69bdc935f740d44f1550832d47a8ff023368b2e333d512516616e4e3d2030f44.png

62.6. Example 3#

Now we’ll put randomness back into the demand shock process and also assume that there are zero costs of holding inventories.

In particular, we’ll look at a situation in which d1=0 but d2>0.

Now it becomes optimal to set sales approximately equal to inventories and to use inventories to smooth production quite well, as the following figures confirm

ex3 = SmoothingExample(d1=0)

x0 = [0, 1, 0]
ex3.simulate(x0)
_images/dd7dee131af4e51b5c163e9ecfa32eed80eeba5d5cee94261a6e41b5f89463bf.png

62.7. Example 4#

To bring out some features of the optimal policy that are related to some technical issues in linear control theory, we’ll now temporarily assume that it is costless to hold inventories.

When we completely shut down the cost of holding inventories by setting d1=0 and d2=0, something absurd happens (because the Bellman equation is opportunistic and very smart).

(Technically, we have set parameters that end up violating conditions needed to assure stability of the optimally controlled state.)

The firm finds it optimal to set QtQ=c12c2, an output level that sets the costs of production to zero (when c1>0, as it is with our default settings, then it is optimal to set production negative, whatever that means!).

Recall the law of motion for inventories

It+1=It+QtSt

So when d1=d2=0 so that the firm finds it optimal to set Qt=c12c2 for all t, then

It+1It=c12c2St<0

for almost all values of St under our default parameters that keep demand positive almost all of the time.

The dynamic program instructs the firm to set production costs to zero and to run a Ponzi scheme by running inventories down forever.

(We can interpret this as the firm somehow going short in or borrowing inventories)

The following figures confirm that inventories head south without limit

ex4 = SmoothingExample(d1=0, d2=0)

x0 = [0, 1, 0]
ex4.simulate(x0)
_images/698fdcf035d5da38e6ce08232912f67d7e9b703e4fcaf4f29a4a0933b377196f.png

Let’s shorten the time span displayed in order to highlight what is going on.

We’ll set the horizon T=30 with the following code

# shorter period
ex4.simulate(x0, T=30)
_images/b911e535e3ca1d5974a5ea9a47ad6720cabb1e6662e2bc56d1b0b274b4902340.png

62.8. Example 5#

Now we’ll assume that the demand shock that follows a linear time trend

vt=b+at,a>0,b>0

To represent this, we set C2=[00] and

A22=[1011],x0=[10],G=[ba]
# Set parameters
a = 0.5
b = 3.
ex5 = SmoothingExample(A22=[[1, 0], [1, 1]], C2=[[0], [0]], G=[b, a])

x0 = [0, 1, 0] # set the initial inventory as 0
ex5.simulate(x0, T=10)
_images/5f4a921ad0023f11ca45b0851f3c7015f44c2c7a275ff1384f0268f37e53f08c.png

62.9. Example 6#

Now we’ll assume a deterministically seasonal demand shock.

To represent this we’ll set

A22=[1000000001010000010000010],C2=[00000],G=[ba000]

where a>0,b>0 and

x0=[10100]
ex6 = SmoothingExample(A22=[[1, 0, 0, 0, 0],
                            [0, 0, 0, 0, 1],
                            [0, 1, 0, 0, 0],
                            [0, 0, 1, 0, 0],
                            [0, 0, 0, 1, 0]],
                       C2=[[0], [0], [0], [0], [0]],
                       G=[b, a, 0, 0, 0])

x00 = [0, 1, 0, 1, 0, 0] # Set the initial inventory as 0
ex6.simulate(x00, T=20)
_images/f40143c4367ffa090a66f54aeda8dc7f8bb6f79877f3eb79ed21eff153a75e98.png

Now we’ll generate some more examples that differ simply from the initial season of the year in which we begin the demand shock

x01 = [0, 1, 1, 0, 0, 0]
ex6.simulate(x01, T=20)
_images/6766e5ecc35d771bc0cfe3eb79d041931bfc32474f11b28da93dae3fa7d085f4.png
x02 = [0, 1, 0, 0, 1, 0]
ex6.simulate(x02, T=20)
_images/d207d1e069a26ea3299d49bb75df7b16f37abf04f9c766b9efbe6fa60b9ce441.png
x03 = [0, 1, 0, 0, 0, 1]
ex6.simulate(x03, T=20)
_images/ea6259d593bc9a5706ae1b81f8ef76c387433f2409e3e170bedd552de67bf6fd.png

62.10. Exercises#

Please try to analyze some inventory sales smoothing problems using the SmoothingExample class.

Exercise 62.1

Assume that the demand shock follows AR(2) process below:

νt=α+ρ1νt1+ρ2νt2+ϵt.

where α=1, ρ1=1.2, and ρ2=0.3. You need to construct A22, C, and G matrices properly and then to input them as the keyword arguments of SmoothingExample class. Simulate paths starting from the initial condition x0=[0,1,0,0].

After this, try to construct a very similar SmoothingExample with the same demand shock process but exclude the randomness ϵt. Compute the stationary states x¯ by simulating for a long period. Then try to add shocks with different magnitude to ν¯t and simulate paths. You should see how firms respond differently by staring at the production plans.

Exercise 62.2

Change parameters of C(Qt) and d(It,St).

  1. Make production more costly, by setting c2=5.

  2. Increase the cost of having inventories deviate from sales, by setting d2=5.