Session Ready
Exercise

Simulating periodic payments (I)

You have all the tools you'll need to simulate the mortgage payments over time.

Every time a mortgage payment is made, the following payment will have a slightly lower percentage, which is used to pay off interest. This means that more of the remainder will go towards the portion of the home that you own instead of the bank. This is important to determine how much you will gain from selling the home before paying off your mortgage, or to determine when your mortgage is underwater. But more on that later.

You will now write a simple program to calculate the interest and mortgage portions of each payment over time.

The mortgage_loan, mortgage_rate_periodic, and periodic_mortgage_payment variables from the third exercise are available for use.

The principal_remaining variable is initialized as an array of 0's with length equal to the number of payment periods.

Instructions
100 XP
  • Set the previous_principal_remaining for the first period, i.e. when (i == 0), equal to the mortgage loan value.
  • Set the previous_principal_remaining for all other periods equal to the remaining principal from the previous period ([i - 1]).
  • Calculate the interest payment (the product of previous principal remaining and the periodic mortgage rate) and principal payment (the difference between periodic mortgage payment and the interest paid) for each period.