Code covered by the BSD License  

Highlights from
Amortization schedule with variable interest rates

image thumbnail

Amortization schedule with variable interest rates

by

 

14 Jun 2011 (Updated )

Computes & optionally saves & plots some variables, like interest paid and balance outstanding.

amorvar(K0,Rates,Prop,Plop,Freq,Comp)
function [Amorout,T,ratio] = amorvar(K0,Rates,Prop,Plop,Freq,Comp)
%  Amortization schedule with variable interest rates, by Guido Travaglini,  jay_of_may@yahoo.com, July 2011
%   Makes use of amortize.m, Financial TB, and assumes end-of-period payments
%   Function is: [Amorout,T,ratio] = amorvar(K0,Rates,Prop,Plop,Freq,Comp)
%   
%  INPUTS:
%
%  (1) K0: Initial capital amount (principal) borrowed
%  (2) Rates: Tx1 time series of interest rates applied in the loan contract expressed in % (e.g. 12.25)
%  (3) Prop: print option to XLS file in the current MATLAB directory, 1=yes, 0=no
%  (4) Plop: plot option, 1=yes, 0=no
%  (5) Freq: yearly periodicity at end of which payment is due (1=annual,2=semi-annually,12=monthly)
%  (6) Comp: compute periodic rate as fraction of annual rate (1) or by compounding formula (0)
%
%  OUTPUT:
%
%  I) Amorout: Tx8 matrix containing:
%  (1) Tx1 vector of t.th step, t=1,...,T
%  (2) Tx1 vector of Interest rate in % available at step t
%  (3) Tx1 vector of Periodic Principal paid at step t
%  (4) Tx1 vector of Periodic Interest paid at step t
%  (5) Tx1 vector of Balance Outstanding  at step t
%  (6) Tx1 vector of Periodic Payment due at step t
%  (7) Tx1 vector of Cumulative Payment due at step t
%  (8) Tx1 vector of Ratio of (7) w.r.t. K0 at step t
%
%  II) T: Total number of steps (scalar)
%  III) ratio: Cumulative Payment at time T / K0 (scalar)
%
%  NOTICE: Produces correct output also with fixed interest rates, where  Rates=repmat(R/Freq,T,1). Then: [Amorout,T,ratio] = amorvar(K0,Rates,Prop,Plop,Freq,Comp);
%  Proof: if Rates is a scalar R/(Freq*100), then:  [prin, int, bal, A] = amortize(R, T, K0, 0, 0), where [.] coincides with corresponding  variables in Amorout
%
T=size(Rates,1);itime=flipud((1:T)');
labs={'Step','Interest Rate','Principal Paid','Interest Paid','Balance Outstanding','Curr. Payment Due','Cum. Payment Due','Cum. Payment Due/K0'};
K=K0;AA=zeros(T,1);
for j=1:T
    if Comp==1
     r=Rates(j)/(100*Freq);
    else
     r= ((1 + Rates(j)/100)^(1/Freq) - 1) ;
    end
  [prin, int, bal,A] = amortize(r, itime(j), K, 0, 0); 
  pall(j).a=[prin', int', bal'];
  K=bal(1);AA(j)=A;                                              %Uses as Principal the previous balance for t=1,...,T
  am(j,:)=[j,Rates(j),pall(j).a(1,:),AA(j)];
end
am=[am,cumsum(am(:,end))];Amorout=[am,am(:,end)./K0];ratio=Amorout(end,end);
%
if Plop==1
 prin=Amorout(:,3);int=Amorout(:,4);bal=Amorout(:,5);
 rate=Amorout(:,2);paid=Amorout(:,6);cpaid=Amorout(:,8);
  %
 subplot(2,1,1)
 plot(bal,'-b'), hold('on')
 plot(cumsum(prin),'--k')
 plot(cumsum(int),':r')
 xlabel('Period')
 ylabel('Currency')
 grid('on')
 title({'Pane 1';'Outstanding Balance, Cumulative Principal and Interest'})
 legend('Outstanding Balance', 'Cumulative Principal', 'Cumulative Interest','Location','West')
 legend('boxoff')
  %
 subplot(2,1,2)
 plot(rate,'-b'), hold('on')
 plot(paid,'--k')
 plot(cpaid,':r')
 xlabel('Period')
 ylabel('Currency, Rate & Ratio')
 grid('on')
 title({'Pane 2';'Interest Rate, Periodic Payment and Ratio of Cumulative Payment to Principal'})
 legend('Interest Rate', 'Periodic Payment', 'Ratio of Cumulative Payment to Principal','Location','West')
 legend('boxoff')
 %
 %  h=   suptitle({'Main Variables of Amortization Schedule'});  set(h,'Fontsize', 16);  hold on;
end
%
if Prop==1
    cellmat= num2cell(Amorout);Amorout=[labs;cellmat];
    xlswrite('temp_amor.xls',Amorout); 
end
%
%
%
end

Contact us