In [ ]:
from __future__ import division
import numpy as np
import quantecon as qe
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}
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']]
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']]
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: