% ASSETSS.M
%  Computes asset price and some interest factors for a seasonal
%  recursive linear equilibrium model.  The programs SOLVES.M, ASSETS.M, and
%  SIMULS.M must be run first, and their outputs must reside in memory.
%  ASSETSS.M generates a simulation of length nT-1 (where nT is the same
%  integer set in SIMULS.M) of the asset that is priced in ASSETS.M.
%  It also generates simulations of R1, R2, and R5, the interest factors
%  associated with sure one, two, and five period loans.
%  The user is prompted for the number of the consumption good that is to
%  serve as numeraire.  The asset priced is a perpetual claim to a stream
%  y(t)=Ua*x(t), where Ua is the matrix named in ASSETS.M.  
% 
%  The program prompts the user for the numeraire consumption good in 
%  terms of which the asset price is expressed.
%  The vector y returns [mrs, pays, as, ret], where mrs is the marginal
%  rate of substitution of consumption one period forward for consumption
%  today, pays=Ua*x(t), as is the asset price, and ret is the rate of
%  return on the asset.  The interest factors are returned in R1, R2, and
%  R5.
%
%  See also ASSETS.M.
numer=input('which consumption good is the numeraire?'  )
disp(' Calculating asset prices, please wait')
n=max(size(ao1));
H=zeros(p,n*p)';
for j=1:p
nj=int2str(j);
eval(['H((j-1)*n+1:j*n,j)=mc',nj,'(numer,:)'';'])
end
Y=X*H;YY=Y';
mus1=YY(:);          %  This is Mc1(j)*x(t).
										
H=zeros(p,n*p)';
for j=1:p
nj=int2str(j);
eval(['H((j-1)*n+1:j*n,(j-1)*n+1:j*n)=mua',nj,';'])
end
Xmu=X*H;
as=zeros(nT*p,1);
for j=1:p
										
for i=1:nT
as(j+(i-1)*p)=Xmu(i,(j-1)*n+1:j*n)*X(i,(j-1)*n+1:j*n)';
end
end
										
H=zeros(p,p);
for j=1:p
nj=int2str(j);
eval(['H(j,j)=siga',nj,';'])
end
XX=ones(nT,p);
Y=XX*H;YY=Y';
y=YY(:);
as=as+y;
										
aprice=as./mus1;
										
%  Term structure of interest rates
mn=zeros(1,nc);
mn(1,numer)=1;
										
for j=1:5
npj=int2str(j+p);
nj=int2str(j);
eval(['ao',npj,'=ao',nj,';'])
eval(['mc',npj,'=mc',nj,';'])
end
H=zeros(p,p*n)';
for j=1:p
nj=int2str(j);
np1=int2str(j+1);
eval(['H((j-1)*n+1:n*j,j)=(mn*mc',np1,'*ao',nj,')'';'])
end
Y=X*H;YY=Y';
R1=YY(:);     % numerator of R1
										
H=zeros(p,p*n)';
for j=1:p
nj=int2str(j);
np1=int2str(j+1);
np2=int2str(j+2);
eval(['H((j-1)*n+1:j*n,j)=(mn*mc',np2,'*ao',np1,'*ao',nj,')'';'])
end
Y=X*H;YY=Y';
R2=YY(:);    %  numerator of R2
										
H=zeros(p,p*n)';
for j=1:p
nj=int2str(j);
nj1=int2str(j+1);
nj2=int2str(j+2);
nj3=int2str(j+3);
nj4=int2str(j+4);
nj5=int2str(j+5);
eval(['H((j-1)*n+1:n*j,j)=(mn*mc',nj5,'*ao',nj4,'*ao',nj3,'*ao',nj2,...
	    '*ao',nj1,'*ao',nj,')'';'])
end
Y=X*H;YY=Y';
R5=YY(:);     %numerator of R5
										
R1=beta*R1./mus1;
R2=(beta^2)*R2./mus1;
R5=(beta^5)*R5./mus1;
										
H=zeros(n*p,p);
for j=1:p
nj=int2str(j);
eval(['H((j-1)*n+1:j*n,j)=pay'';'])
end
Y=X*H;YY=Y';
pays=YY(:);
T=max(size(as));
ret=as(2:T)./(as(1:T-1)-pays(1:T-1));
as=as(2:T);
										
mrs=beta*mus1(2:T)./mus1(1:T-1);
mus1=mus1(2:T);
pays=pays(2:T);
y=[mrs,pays,as,ret];
										
disp(' The simulated values for the marginal rate of substitution,')
disp(' the payoff of the asset, the asset price, and the return ')
disp(' are in y.')
disp(' The interest factors are returned in R1, R2, and R5')
