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

j=325;
n=1



%before 71 I use the av. corp bond yield
%---------------------------------------

%constructing quarterly averages
%-------------------------------

while j<=627  %March 1971
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;
i=1; 
%constructing quarterly averages
while i<=345
rateq(n)=(rate(i)+rate(i+1)+rate(i+2))/3;
i=i+3;
n=n+1;
end;




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



M=191+25
%level outstanding in 45
mort_ls=9.1*1000;

%flows starting in 46 until 51
mort_a(1)=1.1;
mort_a(2)=1.7;
mort_a(3)=1.8;
mort_a(4)=1.4;
mort_a(5)=1.4;
mort_a(6)=1.4;

mort_a=mort_a*1000;

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

mort_q(25:25+190,1)=mortgages(:,2);
M=191+25
rateq(M-1)=rateq(M-2);

mort_l(1)=mort_ls+mort_q(1);
for n=2:M
   mort_l(n)=mort_l(n-1)+mort_q(n);
end   
%calculating interest rate payments
for l=1:M-1
  mort_int(l)=mort_l(l)*((1+rateq(l))^(1/4)-1);
end   
mort_int=mort_int';
save int_mort  mort_int  -ascii


