@@ -3,8 +3,10 @@ jupytext:
33 text_representation :
44 extension : .md
55 format_name : myst
6+ format_version : 0.13
7+ jupytext_version : 1.16.7
68kernelspec :
7- display_name : Python 3
9+ display_name : Python 3 (ipykernel)
810 language : python
911 name : python3
1012---
@@ -29,10 +31,9 @@ kernelspec:
2931
3032In addition to what's in Anaconda, this lecture will need the following libraries:
3133
32- ``` {code-cell} ipython
33- ---
34- tags: [hide-output]
35- ---
34+ ``` {code-cell} ipython3
35+ :tags: [hide-output]
36+
3637!pip install quantecon
3738```
3839
@@ -57,9 +58,8 @@ Other references include chapter 7 of {cite}`Ljungqvist2012`.
5758
5859Let's start with some standard imports:
5960
60- ``` {code-cell} ipython
61+ ``` {code-cell} ipython3
6162import matplotlib.pyplot as plt
62- plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
6363import numpy as np
6464import quantecon as qe
6565```
@@ -431,8 +431,10 @@ Consider the previously presented duopoly model with parameter values of:
431431
432432From these, we compute the infinite horizon MPE using the preceding code
433433
434- ``` {code-cell} python3
434+ ``` {code-cell} ipython3
435435:load: _static/lecture_specific/markov_perf/duopoly_mpe.py
436+
437+
436438```
437439
438440Running the code produces the following output.
@@ -443,7 +445,7 @@ In particular, let's take F2 as computed above, plug it into {eq}`eq_mpe_p1p` an
443445
444446We hope that the resulting policy will agree with F1 as computed above
445447
446- ``` {code-cell} python3
448+ ``` {code-cell} ipython3
447449Λ1 = A - B2 @ F2
448450lq1 = qe.LQ(Q1, R1, Λ1, B1, beta=β)
449451P1_ih, F1_ih, d = lq1.stationary_values()
@@ -454,7 +456,7 @@ This is close enough for rock and roll, as they say in the trade.
454456
455457Indeed, np.allclose agrees with our assessment
456458
457- ``` {code-cell} python3
459+ ``` {code-cell} ipython3
458460np.allclose(F1, F1_ih)
459461```
460462
@@ -470,7 +472,7 @@ The following program
470472* computes the evolution of $x_t$ using {eq}` eq_mpe_cle ` .
471473* extracts and plots industry output $q_t = q_ {1t} + q_ {2t}$ and price $p_t = a_0 - a_1 q_t$.
472474
473- ``` {code-cell} python3
475+ ``` {code-cell} ipython3
474476AF = A - B1 @ F1 - B2 @ F2
475477n = 20
476478x = np.empty((3, n))
@@ -527,7 +529,7 @@ The optimal policy in the monopolist case can be computed using [QuantEcon.py](h
527529
528530First, let's compute the duopoly MPE under the stated parameters
529531
530- ``` {code-cell} python3
532+ ``` {code-cell} ipython3
531533# == Parameters == #
532534a0 = 10.0
533535a1 = 2.0
@@ -558,7 +560,7 @@ F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1, R2, Q1,
558560Now we evaluate the time path of industry output and prices given
559561initial condition $q_ {10} = q_ {20} = 1$.
560562
561- ``` {code-cell} python3
563+ ``` {code-cell} ipython3
562564AF = A - B1 @ F1 - B2 @ F2
563565n = 20
564566x = np.empty((3, n))
@@ -600,7 +602,7 @@ in the law of motion $x_{t+1} = A x_t + B u_t$.
600602We solve for the optimal policy $u_t = - Fx_t$ and track the
601603resulting dynamics of $\{ q_t\} $, starting at $q_0 = 2.0$.
602604
603- ``` {code-cell} python3
605+ ``` {code-cell} ipython3
604606R = a1
605607Q = γ
606608A = B = 1
@@ -613,13 +615,13 @@ x0 = qm[0] - q_bar
613615x = x0
614616for i in range(1, n):
615617 x = A * x - B * F * x
616- qm[i] = float(x) + q_bar
618+ qm[i] = float(x.item() ) + q_bar
617619pm = a0 - a1 * qm
618620```
619621
620622Let's have a look at the different time paths
621623
622- ``` {code-cell} python3
624+ ``` {code-cell} ipython3
623625fig, axes = plt.subplots(2, 1, figsize=(9, 9))
624626
625627ax = axes[0]
@@ -712,7 +714,7 @@ The exercise is to calculate these matrices and compute the following figures.
712714
713715The first figure shows the dynamics of inventories for each firm when the parameters are
714716
715- ``` {code-cell} python3
717+ ``` {code-cell} ipython3
716718δ = 0.02
717719D = np.array([[-1, 0.5], [0.5, -1]])
718720b = np.array([25, 25])
@@ -743,7 +745,7 @@ In this exercise, reproduce the figure when $\delta = 0.02$.
743745
744746We treat the case $\delta = 0.02$
745747
746- ``` {code-cell} python3
748+ ``` {code-cell} ipython3
747749δ = 0.02
748750D = np.array([[-1, 0.5], [0.5, -1]])
749751b = np.array([25, 25])
772774
773775we set up the matrices as follows:
774776
775- ``` {code-cell} python3
777+ ``` {code-cell} ipython3
776778# == Create matrices needed to compute the Nash feedback equilibrium == #
777779
778780A = np.array([[δ_1, 0, -δ_1 * b[0]],
@@ -812,7 +814,7 @@ M2 = np.copy(M1)
812814
813815We can now compute the equilibrium using ` qe.nnash `
814816
815- ``` {code-cell} python3
817+ ``` {code-cell} ipython3
816818F1, F2, P1, P2 = qe.nnash(A, B1, B2, R1,
817819 R2, Q1, Q2, S1,
818820 S2, W1, W2, M1, M2)
@@ -827,7 +829,7 @@ print(F2)
827829Now let's look at the dynamics of inventories, and reproduce the graph
828830corresponding to $\delta = 0.02$
829831
830- ``` {code-cell} python3
832+ ``` {code-cell} ipython3
831833AF = A - B1 @ F1 - B2 @ F2
832834n = 25
833835x = np.empty((3, n))
@@ -843,6 +845,3 @@ ax.set_title(rf'$\delta = {δ}$')
843845ax.legend()
844846plt.show()
845847```
846-
847- ``` {solution-end}
848- ```
0 commit comments