% ASSETS.M
%  A script file.
%  Computes the matrices muas(t) and sigas(t) that are used in
%  pricing an asset for a seasonal recursive linear economy.
%  The program SOLVES.M must be run first, and its output must reside
%  in memory.
%  The asset priced is a stream of returns y(t) = Ua*x(t), where Ua is
%  a vector named by the user.  The price of the asset at time t is
%
%     a(t) = [x(t)'*muas(t)*x(t) + sigas(t)]/ i(j)*mcs(t)*x(t).
%
%  The user is prompted for Ua.  For example, if the user wants to compute
%  the price of an asset that represents a perpetual claim to the first 
%  endowment shock, he would respond "sd1(1,:)". This assumes that sd is 
%  the same for all seasons. The program assumes
%  that Ua is itself not seasonal. The program can be edited to
%  permit Ua to be seasonal.
%  The program returns the matrices muas(t) and  the scalars sigas(t).
%
%  See also SIMULS.M, SIMULASS.M.
Ua=input('Vector giving payoffs of asset you wish to price  ')
disp(' Calculating mua`s  and siga`s, please wait')
pay=Ua;
Ua=Ua';
for j=1:p
n=int2str(j);
eval(['Za',n,'=Ua*mc',n,';'])
end
betah=beta^(.5);
for j=1:p
n=int2str(j);
np1=int2str(j+1);
eval(['D',n,'=Za',n,';'])
eval(['H',n,'=betah*ao',n,';'])
eval(['G',n,'=betah*ao',n,';'])
end
h1=H1;
g1=G1;
npp=int2str(p);
eval(['d1=D',npp,';'])
for j=2:p
n=int2str(j);
npj=int2str(p+1-j);
nm1=int2str(j-1);
eval(['g',n,'=G',n,'*g',nm1,';'])
eval(['h',n,'=H',n,'*h',nm1,';'])
eval(['d',n,'=G',npj,'''*d',nm1,'*H',npj,'+D',npj,';'])
end
eval(['G=g',n,';'])
eval(['H=h',n,';'])
eval(['D=d',n,';'])
nz=max(size(D));
mua1=doublej2(G',D,H',eye(nz));
										
pp1=int2str(p+1);
eval(['mua',pp1,'=mua1;'])
for j=p:-1:2
n=int2str(j);
np1=int2str(j+1);
eval(['mua',n,'=D',n,'+G',n,'''*mua',np1,'*H',n,';'])
end
										
										
np1=int2str(p+1);
eval(['mua',np1,'=mua1;'])
for j=1:p
n=int2str(j);
np1=int2str(j+1);
eval(['g',n,'=beta*trace(mua',np1,'*C',n,'*C',n,''');'])
end
b=zeros(p,1);
for j=1:p
n=int2str(j);
eval(['b(j,:)=g',n,';'])
end
AA=zeros(p,p);
for j=1:p-1
AA(j,j+1)=-beta;
AA(p,1)=-beta;
end
										
sig=AA\b;
for j=1:p
n=int2str(j);
eval(['siga',n,'=sig(j);'])
end
disp(' The objects needed to price the asset that you specified are ')
disp(' stored in mua1, mua2, ..., muap and siga1, siga2, ... ,sigap.' )
