In [1]:
%matplotlib inline
In [4]:
"""
Author:
KMR (Kandori-Mailath-Rob) Model
"""
import numpy as np
import quantecon as qe
def kmr_markov_matrix(p, N, epsilon):
"""
Generate the transition probability matrix for the KMR dynamics with
two acitons.
"""
P = np.zeros((N+1, N+1))
e = epsilon
P[0,0] = 1 - e
P[0,1] = e
P[N,N] = 1 - e
P[N,N-1] = e
for i in range(1,N):
if (i-1)/(N-1) < p :
select = 1
elif (i-1)/(N-1) == p :
select = 0.5
else:
select = 0
P[i,i-1] = i/N*(e/2 + (1-e)*select)
if i/(N-1) > p:
select2 = 1
elif i/(N-1) == p:
select2 = 0.5
else:
select2 = 0
P[i,i+1] = (N-i)/N*(e/2 + (1-e)*select2)
P[i,i] = 1-P[i,i-1]-P[i,i+1]
return P
In [14]:
p=0.3
N=10
epsilon=0.001
kmr_markov_matrix(p, N, epsilon)
Out[14]:
In [26]:
import quantecon as qe
P = kmr_markov_matrix(0.3,10,0.00001)
mc = qe.MarkovChain(P)
mc
Out[26]:
In [21]:
mc.stationary_distributions
Out[21]:
In [32]:
mc.simulate(0,100)
In [ ]: