66. Markov Perfect Equilibrium#
Contents
In addition to what’s in Anaconda, this lecture will need the following libraries:
!pip install quantecon
Show code cell output
Requirement already satisfied: quantecon in /opt/conda/envs/quantecon/lib/python3.12/site-packages (0.8.0)
Requirement already satisfied: numba>=0.49.0 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from quantecon) (0.60.0)
Requirement already satisfied: numpy>=1.17.0 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.26.4)
Requirement already satisfied: requests in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from quantecon) (2.32.3)
Requirement already satisfied: scipy>=1.5.0 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.13.1)
Requirement already satisfied: sympy in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from quantecon) (1.13.1)
Requirement already satisfied: llvmlite<0.44,>=0.43.0dev0 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from numba>=0.49.0->quantecon) (0.43.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from requests->quantecon) (2024.8.30)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /opt/conda/envs/quantecon/lib/python3.12/site-packages (from sympy->quantecon) (1.3.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable.It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
66.1. Overview#
This lecture describes the concept of Markov perfect equilibrium.
Markov perfect equilibrium is a key notion for analyzing economic problems involving dynamic strategic interaction, and a cornerstone of applied game theory.
In this lecture, we teach Markov perfect equilibrium by example.
We will focus on settings with
two players
quadratic payoff functions
linear transition rules for the state
Other references include chapter 7 of [Ljungqvist and Sargent, 2018].
Let’s start with some standard imports:
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
import numpy as np
import quantecon as qe
66.2. Background#
Markov perfect equilibrium is a refinement of the concept of Nash equilibrium.
It is used to study settings where multiple decision-makers interact non-cooperatively over time, each pursuing its own objective.
The agents in the model face a common state vector, the time path of which is influenced by – and influences – their decisions.
In particular, the transition law for the state that confronts each agent is affected by decision rules of other agents.
Individual payoff maximization requires that each agent solve a dynamic programming problem that includes this transition law.
Markov perfect equilibrium prevails when no agent wishes to revise its policy, taking as given the policies of all other agents.
Well known examples include
Choice of price, output, location or capacity for firms in an industry (e.g., [Ericson and Pakes, 1995], [Ryan, 2012], [Doraszelski and Satterthwaite, 2010]).
Rate of extraction from a shared natural resource, such as a fishery (e.g., [Levhari and Mirman, 1980], [Van Long, 2011]).
Let’s examine a model of the first type.
66.2.1. Example: A Duopoly Model#
Two firms are the only producers of a good, the demand for which is governed by a linear inverse demand function
Here
In (66.1) and what follows,
the time subscript is suppressed when possible to simplify notation
denotes a next period value of variable
Each firm recognizes that its output affects total output and therefore the market price.
The one-period payoff function of firm
Substituting the inverse demand curve (66.1) into (66.2) lets us express the one-period payoff as
where
The objective of the firm is to maximize
Firm
An essential aspect of a Markov perfect equilibrium is that each firm takes the decision rule of the other firm as known and given.
Given
Definition A Markov perfect equilibrium of the duopoly model is a pair of value functions
The value function
satisfies Bellman equation (66.4).The maximizer on the right side of (66.4) equals
.
The adjective “Markov” denotes that the equilibrium decision rules depend only on the current values of the state variables, not other parts of their histories.
“Perfect” means complete, in the sense that the equilibrium is constructed by backward induction and hence builds in optimizing behavior for each firm at all possible future states.
These include many states that will not be reached when we iterate forward on the pair of equilibrium strategies
starting from a given initial state.
66.2.2. Computation#
One strategy for computing a Markov perfect equilibrium is iterating to convergence on pairs of Bellman equations and decision rules.
In particular, let
Imagine constructing the iterates
These iterations can be challenging to implement computationally.
However, they simplify for the case in which one-period payoff functions are quadratic and transition laws are linear — which takes us to our next topic.
66.3. Linear Markov Perfect Equilibria#
As we saw in the duopoly example, the study of Markov perfect equilibria in games with two players leads us to an interrelated pair of Bellman equations.
In linear-quadratic dynamic games, these “stacked Bellman equations” become “stacked Riccati equations” with a tractable mathematical structure.
We’ll lay out that structure in a general setup and then apply it to some simple problems.
66.3.1. Coupled Linear Regulator Problems#
We consider a general linear-quadratic regulator game with two players.
For convenience, we’ll start with a finite horizon formulation, where
Player
while the state evolves according to
Here
is an state vector and is a vector of controls for player is is is is is is is
66.3.2. Computing Equilibrium#
We formulate a linear Markov perfect equilibrium as follows.
Player
A Markov perfect equilibrium is a pair of sequences
solves player 1’s problem, taking as given, and solves player 2’s problem, taking as given
If we take
subject to
where
This is an LQ dynamic programming problem that can be solved by working backwards.
Decision rules that solve this problem are
where
Similarly, decision rules that solve player 2’s problem are
where
Here, in all cases
The solution procedure is to use equations (66.10), (66.11), (66.12), and (66.13), and “work backwards” from time
Since we’re working backward,
Moreover, since
some terms on the right-hand side of (66.10) contain
some terms on the right-hand side of (66.12) contain
we need to solve these
66.3.2.1. Key Insight#
A key insight is that equations (66.10) and (66.12) are linear in
After these equations have been solved, we can take
66.3.2.2. Infinite Horizon#
We often want to compute the solutions of such games for infinite horizons, in the hope that the decision rules
In practice, we usually fix
This is the approach we adopt in the next section.
66.3.3. Implementation#
We use the function nnash from QuantEcon.py that computes a Markov perfect equilibrium of the infinite horizon linear-quadratic dynamic game in the manner described above.
66.4. Application#
Let’s use these procedures to treat some applications, starting with the duopoly model.
66.4.1. A Duopoly Model#
To map the duopoly model into coupled linear-quadratic dynamic programming problems, define the state and controls as
If we write
where
then we recover the one-period payoffs in expression (66.3).
The law of motion for the state
The optimal decision rule of firm
66.4.2. Parameters and Solution#
Consider the previously presented duopoly model with parameter values of:
From these, we compute the infinite horizon MPE using the preceding code
import numpy as np
import quantecon as qe
# Parameters
a0 = 10.0
a1 = 2.0
β = 0.96
γ = 12.0
# In LQ form
A = np.eye(3)
B1 = np.array([[0.], [1.], [0.]])
B2 = np.array([[0.], [0.], [1.]])
R1 = [[ 0., -a0 / 2, 0.],
[-a0 / 2., a1, a1 / 2.],
[ 0, a1 / 2., 0.]]
R2 = [[ 0., 0., -a0 / 2],
[ 0., 0., a1 / 2.],
[-a0 / 2, a1 / 2., a1]]
Q1 = Q2 = γ
S1 = S2 = W1 = W2 = M1 = M2 = 0.0
# Solve using QE's nnash function
F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1, R2, Q1,
Q2, S1, S2, W1, W2, M1,
M2, beta=β)
# Display policies
print("Computed policies for firm 1 and firm 2:\n")
print(f"F1 = {F1}")
print(f"F2 = {F2}")
print("\n")
Computed policies for firm 1 and firm 2:
F1 = [[-0.66846615 0.29512482 0.07584666]]
F2 = [[-0.66846615 0.07584666 0.29512482]]
Running the code produces the following output.
One way to see that
In particular, let’s take F2 as computed above, plug it into (66.8) and (66.9) to get firm 1’s problem and solve it using LQ.
We hope that the resulting policy will agree with F1 as computed above
Λ1 = A - B2 @ F2
lq1 = qe.LQ(Q1, R1, Λ1, B1, beta=β)
P1_ih, F1_ih, d = lq1.stationary_values()
F1_ih
array([[-0.66846613, 0.29512482, 0.07584666]])
This is close enough for rock and roll, as they say in the trade.
Indeed, np.allclose agrees with our assessment
np.allclose(F1, F1_ih)
True
66.4.3. Dynamics#
Let’s now investigate the dynamics of price and output in this simple duopoly model under the MPE policies.
Given our optimal policies
The following program
imports
and from the previous program along with all parameters.computes the evolution of
using (66.14).extracts and plots industry output
and price .
AF = A - B1 @ F1 - B2 @ F2
n = 20
x = np.empty((3, n))
x[:, 0] = 1, 1, 1
for t in range(n-1):
x[:, t+1] = AF @ x[:, t]
q1 = x[1, :]
q2 = x[2, :]
q = q1 + q2 # Total output, MPE
p = a0 - a1 * q # Price, MPE
fig, ax = plt.subplots(figsize=(9, 5.8))
ax.plot(q, 'b-', lw=2, alpha=0.75, label='total output')
ax.plot(p, 'g-', lw=2, alpha=0.75, label='price')
ax.set_title('Output and prices, duopoly MPE')
ax.legend(frameon=False)
plt.show()

Note that the initial condition has been set to
To gain some perspective we can compare this to what happens in the monopoly case.
The first panel in the next figure compares output of the monopolist and industry output under the MPE, as a function of time.
The second panel shows analogous curves for price.

Here parameters are the same as above for both the MPE and monopoly solutions.
The monopolist initial condition is
As expected, output is higher and prices are lower under duopoly than monopoly.
66.5. Exercises#
Exercise 66.1
Replicate the pair of figures showing the comparison of output and prices for the monopolist and duopoly under MPE.
Parameters are as in duopoly_mpe.py and you can use that code to compute MPE policies under duopoly.
The optimal policy in the monopolist case can be computed using QuantEcon.py’s LQ class.
Solution to Exercise 66.1
First, let’s compute the duopoly MPE under the stated parameters
# == Parameters == #
a0 = 10.0
a1 = 2.0
β = 0.96
γ = 12.0
# == In LQ form == #
A = np.eye(3)
B1 = np.array([[0.], [1.], [0.]])
B2 = np.array([[0.], [0.], [1.]])
R1 = [[ 0., -a0/2, 0.],
[-a0 / 2., a1, a1 / 2.],
[ 0, a1 / 2., 0.]]
R2 = [[ 0., 0., -a0 / 2],
[ 0., 0., a1 / 2.],
[-a0 / 2, a1 / 2., a1]]
Q1 = Q2 = γ
S1 = S2 = W1 = W2 = M1 = M2 = 0.0
# == Solve using QE's nnash function == #
F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1, R2, Q1,
Q2, S1, S2, W1, W2, M1,
M2, beta=β)
Now we evaluate the time path of industry output and prices given
initial condition
AF = A - B1 @ F1 - B2 @ F2
n = 20
x = np.empty((3, n))
x[:, 0] = 1, 1, 1
for t in range(n-1):
x[:, t+1] = AF @ x[:, t]
q1 = x[1, :]
q2 = x[2, :]
q = q1 + q2 # Total output, MPE
p = a0 - a1 * q # Price, MPE
Next, let’s have a look at the monopoly solution.
For the state and control, we take
To convert to an LQ problem we set
in the payoff function
in the law of motion
We solve for the optimal policy
R = a1
Q = γ
A = B = 1
lq_alt = qe.LQ(Q, R, A, B, beta=β)
P, F, d = lq_alt.stationary_values()
q_bar = a0 / (2.0 * a1)
qm = np.empty(n)
qm[0] = 2
x0 = qm[0] - q_bar
x = x0
for i in range(1, n):
x = A * x - B * F * x
qm[i] = float(x) + q_bar
pm = a0 - a1 * qm
/tmp/ipykernel_3211/1048199155.py:13: DeprecationWarning: Conversion of an array with ndim > 0 to a scalar is deprecated, and will error in future. Ensure you extract a single element from your array before performing this operation. (Deprecated NumPy 1.25.)
qm[i] = float(x) + q_bar
Let’s have a look at the different time paths
fig, axes = plt.subplots(2, 1, figsize=(9, 9))
ax = axes[0]
ax.plot(qm, 'b-', lw=2, alpha=0.75, label='monopolist output')
ax.plot(q, 'g-', lw=2, alpha=0.75, label='MPE total output')
ax.set(ylabel="output", xlabel="time", ylim=(2, 4))
ax.legend(loc='upper left', frameon=0)
ax = axes[1]
ax.plot(pm, 'b-', lw=2, alpha=0.75, label='monopolist price')
ax.plot(p, 'g-', lw=2, alpha=0.75, label='MPE price')
ax.set(ylabel="price", xlabel="time")
ax.legend(loc='upper right', frameon=0)
plt.show()

Exercise 66.2
In this exercise, we consider a slightly more sophisticated duopoly problem.
It takes the form of infinite horizon linear-quadratic game proposed by Judd [Judd, 1990].
Two firms set prices and quantities of two goods interrelated through their demand curves.
Relevant variables are defined as follows:
= inventories of firm at beginning of = production of firm during period = price charged by firm during period = sales made by firm during period = costs of production of firm during period = costs of carrying inventories for firm during
The firms’ cost functions are
where are positive scalars
Inventories obey the laws of motion
Demand is governed by the linear schedule
where
is a negative definite matrix and is a vector of constants
Firm
We can convert this to a linear-quadratic problem by taking
Decision rules for price and quantity take the form
The Markov perfect equilibrium of Judd’s model can be computed by filling in the matrices appropriately.
The exercise is to calculate these matrices and compute the following figures.
The first figure shows the dynamics of inventories for each firm when the parameters are
δ = 0.02
D = np.array([[-1, 0.5], [0.5, -1]])
b = np.array([25, 25])
c1 = c2 = np.array([1, -2, 1])
e1 = e2 = np.array([10, 10, 3])

Inventories trend to a common steady state.
If we increase the depreciation rate to
This is indeed the case, as the next figure shows

In this exercise, reproduce the figure when
Solution to Exercise 66.2
We treat the case
δ = 0.02
D = np.array([[-1, 0.5], [0.5, -1]])
b = np.array([25, 25])
c1 = c2 = np.array([1, -2, 1])
e1 = e2 = np.array([10, 10, 3])
δ_1 = 1 - δ
Recalling that the control and state are
we set up the matrices as follows:
# == Create matrices needed to compute the Nash feedback equilibrium == #
A = np.array([[δ_1, 0, -δ_1 * b[0]],
[ 0, δ_1, -δ_1 * b[1]],
[ 0, 0, 1]])
B1 = δ_1 * np.array([[1, -D[0, 0]],
[0, -D[1, 0]],
[0, 0]])
B2 = δ_1 * np.array([[0, -D[0, 1]],
[1, -D[1, 1]],
[0, 0]])
R1 = -np.array([[0.5 * c1[2], 0, 0.5 * c1[1]],
[ 0, 0, 0],
[0.5 * c1[1], 0, c1[0]]])
R2 = -np.array([[0, 0, 0],
[0, 0.5 * c2[2], 0.5 * c2[1]],
[0, 0.5 * c2[1], c2[0]]])
Q1 = np.array([[-0.5 * e1[2], 0], [0, D[0, 0]]])
Q2 = np.array([[-0.5 * e2[2], 0], [0, D[1, 1]]])
S1 = np.zeros((2, 2))
S2 = np.copy(S1)
W1 = np.array([[ 0, 0],
[ 0, 0],
[-0.5 * e1[1], b[0] / 2.]])
W2 = np.array([[ 0, 0],
[ 0, 0],
[-0.5 * e2[1], b[1] / 2.]])
M1 = np.array([[0, 0], [0, D[0, 1] / 2.]])
M2 = np.copy(M1)
We can now compute the equilibrium using qe.nnash
F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1,
R2, Q1, Q2, S1,
S2, W1, W2, M1, M2)
print("\nFirm 1's feedback rule:\n")
print(F1)
print("\nFirm 2's feedback rule:\n")
print(F2)
Firm 1's feedback rule:
[[ 2.43666582e-01 2.72360627e-02 -6.82788293e+00]
[ 3.92370734e-01 1.39696451e-01 -3.77341073e+01]]
Firm 2's feedback rule:
[[ 2.72360627e-02 2.43666582e-01 -6.82788293e+00]
[ 1.39696451e-01 3.92370734e-01 -3.77341073e+01]]
Now let’s look at the dynamics of inventories, and reproduce the graph
corresponding to
AF = A - B1 @ F1 - B2 @ F2
n = 25
x = np.empty((3, n))
x[:, 0] = 2, 0, 1
for t in range(n-1):
x[:, t+1] = AF @ x[:, t]
I1 = x[0, :]
I2 = x[1, :]
fig, ax = plt.subplots(figsize=(9, 5))
ax.plot(I1, 'b-', lw=2, alpha=0.75, label='inventories, firm 1')
ax.plot(I2, 'g-', lw=2, alpha=0.75, label='inventories, firm 2')
ax.set_title(rf'$\delta = {δ}$')
ax.legend()
plt.show()
