Amortized Loans
Overview
An amortizing loan is structured so that the payments on the loan are all equal. This means that each payment will include
a payment for both interest, and a portion of the principal.
Mortgages are a common example of an amortized loan.
Beacause each payment contains a payment for principal, the interest due each period declines. Becuase the payment is a constant
fixed amount each period, this means that the payment will include an ever increasing amount of principal until the principal reaches
zero. That is, initially, interest comprises a large amount of the payments, with a small principal payments. Payments later in the
stream will be predominantly principal.
Calculating the Monthly Payment
Given a loan amount (the principal) and a desired number of periods (in this case, periods is the number of months) and a given
interest rate, {% r = rate/12 %}
{% Payment = Principal \times (1 + r)^{periods} \times [r/((1+r)^{periods} -1)] %}
The first term, {% Principal \times (1 + r)^{periods} %}, is the
future value of principal at the maturity.
Implementation
The amortization formula above can be implemented in a straightforward manner as
let payment = principal * Math.pow(1+r, periods) * r /(Math.pow(1+r, periods)-1)
Try it!
Remaining Principal
One can verify the veracity of this formula by iterating over the periods and calculating the appropriate values. This sample
code iterates through each period and adds the computed interest and subtracts the payment from the principal. The final value
will be zero. (In this case, the outputted number is not exactly zero, but very close due to the vagaries of
floating point arithmetic)
let principal = 100;
let r = 0.1/12;
let periods = 30*12;
let payment = principal * Math.pow(1+r, periods) * r /(Math.pow(1+r, periods)-1);
for(let i=1;i<=periods;i++){
principal += principal * r;
principal -= payment;
}
Try it!
The value of the principal at any point prior to maturity can be calculated by stopping the above loop after the desired number of
periods.
API
The amortization payment formula and remaining principal calculations is encapsulated in a
amortiziation module, which aids in code readability.