%consumer credit
%----------------
clear
load tbsm3m.txt -ascii

rate=tbsm3m(:,2)/100;
n=1;
j=145; 
%constructing quarterly averages
while j+2<449
   rateq(n)=(rate(j)+rate(j+1)+rate(j+2))/3 + (5.07/100);
j=j+3;
n=n+1;
end;





%terms of consumer credit (published by Federal reserve)
% http://www.federalreserve.gov/releases/G19/hist/cc_hist_tc.html
load termscr.txt -ascii
rate=termscr(:,2)/100;
%series starts in 71/06
i=1; 
%constructing quarterly averages
while i+2<343
rateq(n)=(rate(i)+rate(i+1)+rate(i+2))/3;
i=i+3;
n=n+1;
end;

 


loans_ls=2.8*1000;
load conscreda.txt -ascii  %code 123066005

%series starts in 52/01

loans_a(1)=.5
loans_a(2)=.8
loans_a(3)=.8
loans_a(4)=.6
loans_a(5)=1.1
loans_a(6)=.6




loans_a=loans_a*1000;

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


M=25+190-1;

loans_q(25:25+190,1)=conscreda(:,2);

loans_l(1)=loans_ls+loans_q(1);

for n=2:M
   loans_l(n)=loans_l(n-1)+loans_q(n);
end   

for l=1:M
   loans_int(l)=loans_l(l)*((1+rateq(l))^(1/4)-1);
end   
loans_int=loans_int';
save int_conscr loans_int  -ascii 
