import numpy as np
import matplotlib.pyplot as plt
from numpy.linalg import matrix_power
from scipy.linalg import inv, solve, eig, eigvalsGraduate Quantitative Economics and Datascience
solve\[ A^2 = (Q \Lambda Q^{-1})(Q \Lambda Q^{-1}) = Q \Lambda (Q^{-1} Q) \Lambda Q^{-1} = Q \Lambda^2 Q^{-1} \]
\[ A^t = Q \Lambda^t Q^{-1},\quad \Lambda^t = \mathrm{diag}(\lambda_1^t, \ldots, \lambda_N^t) \]
Lambda = [1.07912878 0.62087122]
Q Lambda^t Q^-1 =
[[1.30777807 0.46547202]
[2.3273601 0.84230605]]
same as A^t? True
\[ x_{t+1} = A x_t,\quad A \equiv \begin{bmatrix} 0.9 & 0.1 \\ 0.5 & 0.8 \\ \end{bmatrix} \]
Iterate \(x_{t+1} = A x_t\) from \(x_0\) for \(t=200\)
rho(A) = 1.079128784747792
x_200 = [3406689.32410673 6102361.18640516]
rho(A) = 0.9449489742783178
x_200 = [6.03450418e-06 2.08159603e-05]
Lambda = [0.45505103 0.94494897]
c = [-0.88048573 -1.79575746]
x_10 = [0.28401728 0.97878213]
same as A^t x_0? True
Consider
\[ x_{t+1} = \begin{bmatrix}1.1 & 0 \\ 0 & 0.8\end{bmatrix} x_t, \qquad x_0 = \begin{bmatrix}0 \\ 1\end{bmatrix} \quad\text{or}\quad x_0 = \begin{bmatrix}0.001 \\ 1\end{bmatrix}. \]
Do these two initial conditions produce the same long-run behavior?
Explain without computing matrix powers.
solve\[ \hat{x}_{t+1} = A x_t + b - (A x^* + b) = A \hat{x}_t,\quad\text{so}\quad \hat{x}_t = A^t \hat{x}_0 \]
Fixed Point
Let \(f : S \to S\) for \(S \subseteq {\mathbb{R}}^N\). A fixed point \(x^* \in S\) of \(f\) is one where
\[ x^* = f(x^*) \]
Fixed points may not exist, or there may be several.
Infinite Series
If \({\varrho\!\left( {A} \right)} < 1\) then \(I - A\) is invertible and \((I - A)^{-1} = \sum_{s=0}^{\infty} A^s = I + A + A^2 + \ldots\)
solve: \(x_t = A^t x_0 + \sum_{s=0}^{t-1} A^s b \to (I - A)^{-1} b = x^*\)For a diagonalizable matrix \(A\), consider
\[ I + A + A^2 + \cdots, \qquad {\varrho\!\left( {A} \right)} = \max_i |\lambda_i|. \]
Why is checking \({\varrho\!\left( {A} \right)} < 1\) enough for this series to converge?
What happens along the eigenvector direction with the largest \(|\lambda_i|\)?
\[ \begin{aligned} E_{t+1} &= (1-\alpha) E_t + \phi U_t\\ U_{t+1} &= \alpha E_t + (1-\phi) U_t \end{aligned} \]
\[ \underbrace{\begin{bmatrix} E_{t+1}\\U_{t+1}\end{bmatrix}}_{X_{t+1}} = \underbrace{\begin{bmatrix} 1-\alpha & \phi \\ \alpha & 1-\phi \end{bmatrix}}_{ A} \underbrace{\begin{bmatrix} E_{t}\\U_{t}\end{bmatrix}}_{X_t} \]
Simulate by iterating \(X_{t+1} = A X_t\) from \(X_0\) until \(T=100\)
Find \(X_{\infty}\) by iterating \(X_{t+1} = A X_t\) many times from a \(X_0\)?
Alternatively, note that this expression is the same as
\[ 1 \times \bar{X} = A \bar{X} \]
real eigenvalues = [1. 0.85]
eigenvectors in columns of =
[[ 0.89442719 -0.70710678]
[ 0.4472136 0.70710678]]
first eigenvalue = 1? True
X_bar = [666666.66666667 333333.33333333]
X_100 = [666666.6870779 333333.31292209]
Suppose both probabilities double:
Does long-run unemployment rise, fall, or stay the same?
Does the economy approach it faster or slower? Explain using worker flows.
A_fast =
[[0.8 0.4]
[0.2 0.6]]
alpha_fast/alpha = 4, phi_fast/phi = 4
X_100 = [666666.66666667 333333.33333333]

\[ M = \begin{array}{c c l} & \textcolor{gray}{\begin{array}{cccc} A & B & C & D \end{array}} & \\ \textcolor{gray}{\begin{array}{c} A \\ B \\ C \\ D \end{array}} & \begin{bmatrix} 0 & 1 & 1 & 0 \\ 0 & 0 & 1 & 1 \\ 1 & 0 & 0 & 0 \\ 1 & 0 & 0 & 0 \end{bmatrix} & \begin{array}{l} x_t = \textcolor{gray}{A} \;\to\; x_{t+1} = \textcolor{gray}{B} \text{ or } \textcolor{gray}{C} \\ x_t = \textcolor{gray}{B} \;\to\; x_{t+1} = \textcolor{gray}{C} \text{ or } \textcolor{gray}{D} \\ x_t = \textcolor{gray}{C} \;\to\; x_{t+1} = \textcolor{gray}{A} \\ x_t = \textcolor{gray}{D} \;\to\; x_{t+1} = \textcolor{gray}{A} \end{array} \end{array} \]
One interpretation of this is that you can
Pages \(A\) and \(C\) each have two incoming links.
If someone keeps clicking randomly among the available links, which page will they spend more time on?
Give an argument from the picture.
Alternatively,
\[ r_{t+1} = S^{\top} r_t \]
|eigenvalues| = [1. 0.707 0.707 0. ]
r_bar = [0.4 0.2 0.3 0.1]
\[ p_t = \sum_{s=0}^{\infty} \beta^s y_{t+s} \]
Assume dividends follow \(y_{t+1} = a y_t\) for \(t=0,1,\ldots\) and \(y_0\) is given
\(a > 0\) shows how period-payoffs evolve. Can only be a growth or shrinkage factor here.
\[ p_t = \sum_{s=0}^{\infty} \beta^s y_{t+s} = \frac{y_t}{1-\beta a} \]
More generally for vector \(x_t\in{\mathbb{R}}^N\) capturing the relevant state of the world for payoff \(y_t\):
\[ \begin{aligned} p_t &= y_t + \beta y_{t+1} + \beta^2 y_{t+2} + \ldots = G x_t + \beta G A x_t + \beta^2 G A A x_t + \ldots\\ &= G \sum_{s=0}^{\infty} (\beta A)^s x_t = G (I - \beta A)^{-1} x_t \end{aligned} \]
The Neumann series with \(\beta A\) requires \({\varrho\!\left( {\beta A} \right)} = \beta {\varrho\!\left( {A} \right)} < 1\): the maximum expansion of \(A\) in its worst direction must be less than the discounting, or the infinite PDV is not defined
The scalar case is \(A = \begin{bmatrix} a \end{bmatrix}\), \(G = \begin{bmatrix} 1 \end{bmatrix}\) and \({\varrho\!\left( {A} \right)} = a\)
Here is an example with \(1 < {\varrho\!\left( {A} \right)} < 1/\beta\). Try with different \(A\)
beta = 0.9
A = np.array([[0.85, 0.1],
[0.2, 0.9]])
G = np.array([[1.0, 1.0]]) # row vector
x_0 = np.array([1.0, 1.0])
p_t = G @ solve(np.eye(2) - beta * A, x_0)
#p_t = G @ inv(np.eye(2) - beta * A) @ x_0 # alternative
rho_A = np.max(np.abs(eigvals(A)))
print(f"p_t = {p_t[0]:.4g}, spectral radius = {rho_A:.4g}, \
1/beta = {1/beta:.4g}")p_t = 24.43, spectral radius = 1.019, 1/beta = 1.111
\[ \begin{aligned} x_{t+1} &= f(x^*) + \nabla f(x^*) (x_t - x^*) + \text{second order and smaller terms}\\ x_{t+1} - x^* &\approx \nabla f(x^*) (x_t - x^*)\\ \hat{x}_{t+1} &\approx \nabla f(x^*) \hat{x}_t \end{aligned} \]
\[ \begin{aligned} k_{t+1} &= s z k_t^{\alpha} + (1-\delta)k_t = s z k_t^{\alpha} + (1-\delta) k_t \equiv g(k_t),\quad \text{ given } k_0 \end{aligned} \]
\[ \begin{aligned} k_{t+1} = g(k_t) &\approx g(k^*) + g'(k^*)(k_t - k^*)\\ \underbrace{k_{t+1} - k^*}_{\equiv \hat{k}_{t+1}} &\approx g'(k^*) \underbrace{(k_t - k^*)}_{\equiv \hat{k}_t}\\ \hat{k}_{t+1} &\approx \left(\alpha s z k^{*\alpha-1} + 1-\delta\right) \hat{k}_t = \underbrace{\left(1 - (1-\alpha)\delta\right)}_{\equiv A} \hat{k}_t \end{aligned} \]
z, s, alpha, delta = 2, 0.3, 0.3, 0.4
def g(k):
return s * z * k**alpha + (1 - delta) * k
k_star = (s * z / delta)**(1 / (1 - alpha))
g_prime = alpha * s * z * k_star**(alpha - 1) + 1 - delta
k = 0.25
for _ in range(10):
k = g(k)
print(f"k_star = {k_star:.4f}, g(k_star) = {g(k_star):.4f}")
print(f"g'(k_star) = {g_prime:.4f} = {1 - (1 - alpha) * delta:.4f}")
print(f"k_10 = {k:.4f}")k_star = 1.7847, g(k_star) = 1.7847
g'(k_star) = 0.7200 = 0.7200
k_10 = 1.7053
The matrix
\[ A = \begin{bmatrix}0.9 & 0.3 \\ 0.3 & 0.9\end{bmatrix} \quad\text{has eigenvalues}\quad 1.2,\ 0.6. \]
For which of these discount factors does \(\sum_{s=0}^{\infty} \beta^s A^s\) converge?
A. \(\beta = 0.8\) only.
B. \(\beta = 0.9\) only.
C. Both \(\beta = 0.8\) and \(\beta = 0.9\).
D. Neither.
For \(x_{t+1} = A x_t + b\), let \(x^*\) be a steady state.
Define \(\hat{x}_t = x_t - x^*\). Which recursion is correct?
A. \(\hat{x}_{t+1} = A\hat{x}_t + b\)
B. \(\hat{x}_{t+1} = A\hat{x}_t\)
C. \(\hat{x}_{t+1} = (A-I)\hat{x}_t\)
Subtract \(x^* = A x^* + b\) from \(x_{t+1} = A x_t + b\):
\[ \hat{x}_{t+1} = A \hat{x}_t. \]
The constant cancels; \(A\) alone governs the evolution of deviations.
Two employment models have the same steady-state shares. Their transition matrices have eigenvalues
\[ A_1:\quad 1,\ 0.9, \qquad A_2:\quad 1,\ 0.4. \]
Which model’s deviations from its steady state decay faster?
A. The model with \(A_1\).
B. The model with \(A_2\).
C. They decay at the same rate because both have an eigenvalue of \(1\).
An eigenvector of \(S^{\top}\) with eigenvalue \(1\) is
\[ q = \begin{bmatrix}2 \\ 1\end{bmatrix}. \]
What stationary probability vector does it represent?
A. \(\bar{r} = \begin{bmatrix}2 & 1\end{bmatrix}^{\top}\)
B. \(\bar{r} = \frac{1}{\sqrt{5}}\begin{bmatrix}2 & 1\end{bmatrix}^{\top}\)
C. \(\bar{r} = \frac{1}{3}\begin{bmatrix}2 & 1\end{bmatrix}^{\top}\)