%   hsdemo4.m
echo on
clc
clg
%
%
%
%                   Stochastic Growth Economy
%                     Asset Pricing Example
%                  (Very Low Adjustment Costs)
%
%   This demonstration shows how to use programs from Hansen
%   and Sargent's RECURSIVE LINEAR MODELS OF DYNAMIC ECONOMIES
%   to compute asset prices and the term structure of interest
%   rates for an equilibrium version of an economy studied by
%   Robert Hall in his 1978 JPE paper on the permanent income
%   hypothesis.  The model is a linear quadratic stochastic
%   growth model.
%
pause  % press any key to continue demonstration
clc
%
%
%   The economy consists of a representative agent who maximizes
%   
%       -.5 E SUM { beta^t * (c(t) - 30)^2 ) + L(t)^2}
%
%       subject to c(t) + i(t) = gamma(1)* k(t-1) + d1(t),
%                  k(t) = deltak * k(t-1) + i(t)
%                  g(t) = phii(2)* i(t)
%                  L(t)^2 = g(t)^2
%   
%   where d1(t) is a first order autoregressive process with
%   mean 5, c(t) is consumption, L(t) is labor supplied, k(t) is
%   capital at end of period t, i(t) is investment, and g(t)^2 is
%   labor using intermediate production goods absorbed in adjusting capital.
%  
%   We want to price the dividend stream {d1(t)}; this is like a
%   `Lucas tree', which is an equity that
%   entitles the owner to the dividend d1(t) each period.
%   We also want to compute the term structure of interest rates.
%
pause    %  Press any key to continue the demonstration
clc  
% 
%   To price the tree, we first construct the Arrow-Debreu
%   price process, which we denote pj(t).  The Arrow-Debreu price
%   process,  normalized in terms of time j as the time of the opening
%   market is determined by the formula pj(t) = Mc*x(t)/numj, where
%   numj is the numeraire for the time j price system, and where
%   x(t) is the state vector of the economy.  Let the dividend on
%   the tree be represented as d1(t) = pay * x(t), where pay is
%   a vector that determines the payoff.  For this example,
%   pay = sd(:,1), the first component of the matrix determining
%   the d(t) process.  Let the asset price be denoted a(j) at time
%   j.  Then   we have the representation
%
%        a(j) = E ( Sum beta^(t-j) (p(t) * x(t)) )| I(j) 
%
%    where I(j) is the time j information set.
%
%   Hansen and Sargent show that
%    
%        a(j) = x(t)' v2 x(t) + riskpr
%
%   where v2 is a matrix and riskpr a scalar that are reported below.
%
%
pause    %  Press any key to continue the demonstration

clc
%
%
%   We also compute the term structure of interest rates.
%   Let R(k) be the reciprocal of the gross interest rate on
%   k period ahead sure loans.  The formula for R(k) at time t is
%  
%      R(j) = beta^k (Mc ao ^ k ) x(t) / numt.
%
pause    %  Press any key to continue the demonstration

clc
%
%
%   We have created a version of Hall's economy in the file
%   clex11.m.  We load in the matrices defining this economy by
%   typing `clex11'; we modify the adjustment cost parameter phii(2) =.005,
%   which is small enough for Hall's random walk theory to approximate well.
%   We also set gamma(1) =.1.  We set beta =1/1.05, and deltak = .95.
%   The `Jones-Manuelli growth condition' (beta * (gamma + deltak) > 1  or =1)
%   is satisfied with equality.  (The condition for
%   consumption to be a random walk in Hall's model is that 
%   the Jones-Manuelli condition be satisfied at equality, and
%   that phii(2) is a very small positive number. 
    
pause    %  Press any key to continue the demonstration
clc
%
%
%
%
%   
clex11
phii(2)=.005;
gamma(1)=.1;       %  If gamma(1) =.1, the Jones-Manuelli cond holds with =.
pause    %  Press any key to continue the demonstration
clc
%
%  
%   The matrices have been read in.  For example, to see what
%   values have been assigned to a22 and ud, we type
a22
ud
%
pause    %  Press any key to continue the demonstration
clc
%
%
%   Now we'll compute the equilibrium of the economy using
%   the program solvea.  We just type `solvea'.
echo off
solvea 

echo on


pause    %  Press any key to continue the demonstration
clc
%
%
%   The equilibrium has been computed.
%   To see the values of the equilibrium transition equation,
%   we just type ao and c:
%
ao
c
pause    %  Press any key to continue the demonstration
clc
%
%
%   Now  we'll construct a simulation 
%   of the economy using the
%   program asimul.m.  We set the length of the simulation t1=100.
%   We specify that sy=sc, so that we are simulating the consumption
%   process.   
nnc=3;   %  Specify place of constant in state vector
echo off
steadst;  %  Compute nonstochastic steady state
echo on
x0=zs;
t1=100;


sy=[sc;si]    %    We type asimul to compute the simulation.
echo off
asimul
echo on
pause    %  Press any key to continue the demonstration
clc
%
%
%    We'll plot the value of consumption and investment
%
pause  %  press a key to see the plot of consumption and investment
%

plot(y),title('Cons and invest in Hall economy with very small adj costs'),pause
%
%
pause    %  Press any key to continue the demonstration
clc
%
%
%   Now we'll simulate asset prices.  We set the length of the
%   simulation at nt=100.  We want to price the Lucas tree,
%   so we set pay = sd(1,:).   After setting these, we just
%   type asseta.
nt=t1;
pay=sd(1,:)       %   Type asseta to compute the asset prices and simulate 
echo off          %   them.
asseta
echo on
pause    %  Press any key to continue the demonstration
clc
%  
%   The riskpremium for the asset price is stored in riskpr,
%   while the matrix in the quadratic form for the
%   asset price is stored in v2.  Let's look at them.
riskpr
v2
pause    %  Press any key to continue the demonstration
clc
%
%
%    Now let's plot the price of the `tree'.
pause  %  press any key to see the tree price

plot(y(:,3)),title('Price of Lucas tree living in Hall economy'),pause
clc
%    The one period gross return on the tree and the one-period 
%    gross return on a risk free one period bond are now plotted.
%    The solid line is the return on the Lucas tree, the dotted line
%    is the return on the risk-free bond.
%
%    Notice that the safe one period return barely moves.  Why?
%
pause  %  Press a key to see the plot

r1=R1(2:nt).^(-1);r1=r1';
RR=[y(:,4) r1];

plot(RR),title('Rates of return on Lucas tree and safe asset'),pause,clc
%
%     The correlation between these two returns can now be computed.


corrcoef(RR)
pause    %  Press any key to continue the demonstration
clc
%
%   Now let's plot the net one-period rate of return on sure
%   one-period and five-period bonds. The solid line will be the
%   one period return, the dotted line the five period return. 
%  
%   Notice that the scale on the y-axis: neither return moves.  Why?
%
pause  %  press a key to see the rates of return

r5=R5(2:nt).^(-1);r5=r5';

r2=R2(2:nt).^(-1);r2=r2';

lr1=log(r1);
lr2=log(r2)./2;
lr5=log(r5)./5;

lr=[lr1 lr5];
plot(lr),title('Rates of return on one- and five-period safe bonds'),pause
%
clc
clg
pause %  This concludes demo.  Press any key to return to menu.
return
