format short
rand('normal')
clc
clg
echo on
%
%
%  This demo shows how to calculate an equilbrium of a recursive
%  dynamic economy.  The economy is entered in the form
%  of a list of matrices [phic,phii,phig,gamma,deltak,thetak]
%  that determine the technology, a list of matrices [deltah,thetah,
%  lambda,pih] and a scalar beta that determine preferences, and
%  matrices [a22,c2,ud,ub] that determine information flows.
%
  pause   % Press any key to see the social planning problem
clc
%
%
%  The equilibrium of the economy is determined by the solution of
%  the following linear quadratic programming problem:
%
%   Maximize
%
%      -.5 SUM (beta ^ t) [(s(t)-b(t)).(s(t)-b(t)) + l(t)^2]
%
%   subject to
%
%      phic * c(t) + phig * g(t) + phii * i(t) = gamma * k(t-1) + d(t)
%                              g(t).g(t) = l(t)^2
%                                   k(t) = deltak * k(t-1) + thetak * i(t)
%                                   h(t) = deltah * h(t-1) + thetah * c(t)
%                                   s(t) = lambda * h(t-1) + pih * c(t)
%                                 z(t+1) = a22 * z(t) + c2 * w(t+1)
%                                   b(t) = ub * z(t), d(t) = ud * z(t)
%
%  The program solvea.m maps this problem into an optimal linear
%  regulator problem, and solves it by using fast algorithms.
%
pause  %  Press a key to see the form of the solution
clc
%
%
%   The solution of the social planning problem is represented as follows.
%   Let the STATE of the economy be x(t) = [h(t)',k(t)',z(t)']'.
%   The solution of the social planning problem is then represented
%   in the state space form
%
%        x(t+1) = ao * x(t) + c * w(t+1)
%        j(t) = sj * x(t)
%
%   where j = k, h, c, s, g, i, b, and d.  The program solvea.m computes
%   the solution and returns it in the form of the matrices
%   [ao,c] and [sj] for j = k, h, c, s, g, i, b, and d.
%   The program solvea.m also computes the  Lagrange multipliers
%
%        muj = mj * x(t)
%   for j=k,c,h,s, and i.
%   These multipliers are used to compute the Arrow-Debreu price system.
%
pause  % Press any key to continue demonstration
clc
%
%
%   Now we'll read in the parameters of a version of a linear
%   quadratic stochastic growth model.  The program clex11.m creates
%   all of the relevant matrices, as well as setting the initial
%   value of the state vector, x0.  We just type `clex11' to read in
%   these parameter values.
%
pause %  Press a key to read in the parameter values
clex11
clc
%
%
%   Here are some of the matrices that have been read in:
%
a22
ud
pause  %  Press a key to continue demo.
clc
%
%
%   We compute the equilibrium (i.e., solve the social planning problem)
%   by typing `solvea'.
echo off
solvea
echo on
pause  %  Press a key to continue demonstration.
clc
%
%
%   The solution of the social planning problem is represented
%   in the state space form
%
%        x(t+1) = ao * x(t) + c * w(t+1)
%        j(t) = sj * x(t)
%
%   where j = k, h, c, s, g, i, b, and d.
pause  %  Press a key to see ao
ao
pause  %  Press a key to continue
clc
%
%
pause  %  Press a key to see c
c
pause  %  Press a key to see sc (c(t) = sc*x(t))
sc
pause  %  Press a key to see mc  (the multiplier for c = mc*x(t))
clc
mc
pause  %  Press a key to see si (i(t) = si*x(t))
si
pause  %  Press a key to see mi (the multiplier for i = mi*x(t))
mi
clc
%
%
pause  %  Press a key to see the endogenous eigenvalues (endo)
endo
pause  %  Press a key to see the endogenous eigenvalues in long format
format long
endo
format short
%
%  Notice the nearly unit eigenvalue.  This is a symptom of the `random walk'
%  character of consumption in Hall's model.
%  This stems from the very small value of the costs of adjustment
%  parameter that we have set.  Press a key to see the cost of
%  adjustment paramter (phii(2)):
pause
format long
phii(2)
format short
%  That the adjustment cost is positive explains why the root is
%  a little less than unity.
%  Later we'll raise this parameter and recompute the equilibrium.
%  Note that the second endogenous eigenvalue just equals the
%  value of deltah, which has no effect on the equilibrium
%  because lambda has been set at zero.
pause  %  Press a key to continue
clc
%
%
pause  %  Press a key to see the exogenous eigenvalues (exo)
exo
pause  %  Press a key to continue
clc
%
%
%   To compute the nonstochastic steady state of the system, we specify
%   the place of the constant term in the state (3 in this case- recall
%   what a22 and ao look like for this economy) and set nnc=3.
%   Then we type `steadst'.  Press a key to continue.
nnc=3
echo off
steadst
echo on
%   The nonstochastic steady state value of the state x is recorded
%   in zs.  To get the steady state value of, e.g.,  sc or mc, just
%   type sc*zs or mc*zs.
pause  %  Press a key to continue
clc
%
%
pause  %  Press a key to see zs, sc*zs, and mc*zs
zs
sc*zs
mc*zs
pause  %  Press a key to continue
clc
%
%
%  For this particular model, zs,sc*zs, and mc*zs are virtually meaningless,
%  because the model has a near unit endogenous eigenvalue.
%  When the model has a unit eigenvalue, a nonstochastic steady
%  state does not exist.
pause   %  Press a key to continue
clc
%
%
%   Now we'll perform a simulation.  There are two programs
%   that compute simulations: `simul' is an interactive program,
%   while `asimul' is noninteractive (you must input sy, where
%   y(t) = sy*x*(t) is the vector to be simulated, and t1, the
%   desired number of observations.
%
%   We want to simulate consumption and investment, so we set
%   sy = [sc;si].  We'll set t1 = 100.
pause  %  Press a key to continue
sy=[sc;si];
t1=100;
pause  %  To compute the simulation, we type `asimul'. Press key to continue
echo off
asimul
echo on
clc
%
%
pause%   We plot the simulation by typing plot(y),title('cons and invest')
plot(y),title('cons and invest'),pause
clg
clc
%
%
%  Now we'll raise the adjustment cost parameter to .3, and we'll
%  recompute the equilibrium.
%
phii(2)=.8;
echo off
solvea
echo on
clc
%
%
pause  %  press a key to compute the endogenous eigenvalues
endo
pause  %  press a key to continue
clc
%
%
pause  %  Press a key to simulate consumption and investment

sy=[sc;si];
echo off
asimul;
echo on
plot(y),title('c and i with higher adjustment costs'),pause
clc
%
%
%   Notice that relative to the first economy, consumption is less smooth
%   and investment is smoother.  This is a consequence of the higher
%   adjustment costs.
%
%
pause  %  This concludes the demonstration.  Press a key to return to menu.







