In [ ]:
from __future__ import division
import numpy as np
import quantecon as qe

Economic Dynamics, Chapter 4: Exercises

Exercises using Hamilton's Markov chain:


In [ ]:
P = [[0.971, 0.029, 0    ],
     [0.145, 0.778, 0.077],
     [0    , 0.508, 0.492]]
mc_H = qe.MarkovChain(P)

In [ ]:
mc_H.P

In [ ]:
states = {'NG': 0, 'MR': 1, 'SR': 2}

4.2 Finite State Markov Chains

4.2.2 Marginal Distributions

Exercise 4.2.3

Let us use the following function from the previous exercise set:


In [ ]:
def cross_sectional_dist(mc, init, T, num_reps=100):
    """
    Return a distribution of visits at time T across num_reps sample paths
    of mc with an initial state init.
    
    """
    x = np.empty(num_reps, dtype=int)
    for i in range(num_reps):
        x[i] = mc.simulate(init=init, sample_size=T+1)[-1]
    bins = np.arange(mc.n+1)
    hist, bin_edges = np.histogram(x, bins=bins)
    dist = hist/len(x)
    return dist

In [ ]:
psi = [0, 0, 1]
psi_10 = cross_sectional_dist(mc_H, init=psi, T=10)
print psi_10

In [ ]:
psi_10[states['NG']]

4.2.3 Other Identities

Exercise 4.2.12


In [ ]:
profits = [1000, 0, -1000]

In [ ]:
t = 5
exp_profits_vec = np.linalg.matrix_power(mc_H.P, t).dot(profits)
print exp_profits_vec

In [ ]:
exp_profits_vec[states['SR']]

Exercise 4.2.13


In [ ]:

Exercise 4.2.14


In [ ]:

4.2.4 Constructing Joint Distributions

Exercise 4.2.15


In [ ]:

Exercise 4.2.16


In [ ]:

Exercise 4.2.18


In [ ]:

Exercise 4.2.19


In [ ]:

Exercise 4.2.20


In [ ]:

Exercise 4.2.22


In [ ]:

Exercise 4.2.23


In [ ]:

4.3 Stability of Finite State MCs

4.3.1 Stationary Distributions

Exercise 4.3.9


In [ ]:

Exercise 4.3.10


In [ ]:

4.3.3 Stability

Exercise 4.3.27


In [ ]:

4.3.4 The Law of Large Numbers

Exercise 4.3.34


In [ ]:

Exercise 4.3.36


In [ ]: