|  | 
|  | 1 | +""" | 
|  | 2 | +Filename: lqnash.py | 
|  | 3 | +Authors: Chase Coleman, Thomas Sargent | 
|  | 4 | +
 | 
|  | 5 | +This file provides an example of a Markov Perfect Equilibrium for a | 
|  | 6 | +simple duopoly example. | 
|  | 7 | +
 | 
|  | 8 | +See the lecture at http://quant-econ.net/markov_perfect.html for a | 
|  | 9 | +description of the model. | 
|  | 10 | +
 | 
|  | 11 | +""" | 
|  | 12 | +from __future__ import division | 
|  | 13 | +import sys | 
|  | 14 | +import numpy as np | 
|  | 15 | +import scipy.linalg as la | 
|  | 16 | +import matplotlib.pyplot as plt | 
|  | 17 | +from numpy import sqrt, max, eye, dot, zeros, cumsum, array | 
|  | 18 | +from numpy.random import randn | 
|  | 19 | +from quantecon.lqnash import nnash | 
|  | 20 | + | 
|  | 21 | + | 
|  | 22 | +#---------------------------------------------------------------------# | 
|  | 23 | +# Set up parameter values and LQ matrices | 
|  | 24 | +# Remember state is x_t = [1, y_{1, t}, y_{2, t}] and | 
|  | 25 | +# control is u_{i, t} = [y_{i, t+1} - y_{i, t}] | 
|  | 26 | +#---------------------------------------------------------------------# | 
|  | 27 | +a0 = 10. | 
|  | 28 | +a1 = 1. | 
|  | 29 | +beta = 1. | 
|  | 30 | +d = .5 | 
|  | 31 | + | 
|  | 32 | +a = eye(3) | 
|  | 33 | +b1 = array([[0.], [1.], [0.]]) | 
|  | 34 | +b2 = array([[0.], [0.], [1.]]) | 
|  | 35 | + | 
|  | 36 | +r1 = array([[a0, 0., 0.], | 
|  | 37 | +            [0., -a1, -a1/2.], | 
|  | 38 | +            [0, -a1/2., 0.]]) | 
|  | 39 | + | 
|  | 40 | +r2 = array([[a0, 0., 0.], | 
|  | 41 | +            [0., 0., -a1/2.], | 
|  | 42 | +            [0, -a1/2., -a1]]) | 
|  | 43 | + | 
|  | 44 | +q1 = array([[-.5*d]]) | 
|  | 45 | +q2 = array([[-.5*d]]) | 
|  | 46 | + | 
|  | 47 | + | 
|  | 48 | +#---------------------------------------------------------------------# | 
|  | 49 | +# Solve using QE's nnash function | 
|  | 50 | +#---------------------------------------------------------------------# | 
|  | 51 | + | 
|  | 52 | +f1, f2, p1, p2 = nnash(a, b1, b2, r1, r2, q1, q2, 0., 0., 0., 0., 0., 0., | 
|  | 53 | +                       tol=1e-8, max_iter=1000) | 
0 commit comments