The brief
A lender's customer wants to see where their money goes. They are taking a 25-year repayment mortgage of $300,000 at 4.5% a year, paid monthly, and are thinking of paying $200 a month on top.
The lending team needs a schedule it can hand over, and a clear answer to "what does the extra $200 buy me?".
Your task
- Write
monthly_payment(principal, annual_rate, years). The monthly rate is the annual rate divided by 12. - Write
schedule(principal, annual_rate, years, extra=0.0): one dict per month with the keysmonth,payment,interest,principalandbalance. With an extra payment the loan ends early, and the last payment only clears what is left. - Write
interest_saved(principal, annual_rate, years, extra).
The data
The loan terms are PRINCIPAL, ANNUAL_RATE and YEARS in the code.
Hint: Where to start
The payment makes the present value of every payment equal the loan. That present value is a finite geometric series, the subject of lesson 1.5.2; lesson 1.5.5 prices a mortgage the same way.
Hint: Building the schedule
Each month, interest is the balance times the monthly rate. The rest of the payment repays principal. Stop when the balance reaches zero.