%mortgages on the asset side
%---------------------------------------------------
clear
load baa.txt -ascii  %average LT corporate bond yield Moody's BAA
rate=baa(:,2)/100;

j=325;
n=1
%constructing quarterly averages
while j+2<627
rateq(n)=(rate(j)+rate(j+1)+rate(j+2))/3;
j=j+3;
n=n+1;
end;






load cm.txt -ascii
%series on mortgage rates starts in 71/04
rate=cm(:,2)/100;
%before 71/04 constructed by adding constant spread to the prime rate
i=1; 
%constructing quarterly averages
while i+2<345
rateq(n)=(rate(i)+rate(i+1)+rate(i+2))/3;
i=i+3;
n=n+1;
end;




load mortgagesa.txt -ascii    % code 103065003
%series on mortgages starts in 52/01



M=25+190-1;
%level outstanding in 45
mort_l(1)=0;
%flows starting in 46 until 51
mort_a(1)=0;
mort_a(2)=0;
mort_a(3)=0;
mort_a(4)=0;
mort_a(5)=0;
mort_a(6)=0;

mort_a=mort_a*1000;

for n=1:6
   for i=1:4
   j=(n-1)*4+i
   mort_q(j,1)=(mort_a(n)/4);
  end
end

mort_q(25:25+190,1)=mortgagesa(:,2);

for n=2:M
   mort_l(n)=mort_l(n-1)+mort_q(n,1);
end   

for l=1:M
  mort_int(l)=mort_l(l)*rateq(l)^1/4;
end   

mort_int=mort_int';

save int_morta  mort_int  -ascii


