Calculation of Mortgage Amortization

I’m trying to match the mortgage amortization calculation of online calculators, but I end up off about \$0.71 at the end of the 360 month schedule. I assume this has something to do with floating point calculations, but can’t figure out what is going wrong. Here is the code for the amortization calculation:

``````curr_principal = round(P, 2)
data = []
for i in range(1, (n + 1), 1):
month_interest = curr_principal * r
month_principal = round(monthly_total - month_interest, 2)
curr_principal = curr_principal - month_principal
data.append([i, month_interest, month_principal, round(curr_principal, 2)])

import pandas as pd
pd.set_option('display.max_rows', None)
df = pd.DataFrame(data, columns=["Period", "Interest", "Principal", "Remaining"], index= None)
print(df.to_string(index=False))
``````

Please post a complete working example and say what you expected and what you’re getting.

OK, sorry about that. Here is a complete example:

``````r = 0.04625 / 12
P = 1100000
n = 360

common = (1 + r) ** n
numerator = r * common
denominator = common - 1
monthly_total = round(P * (numerator / denominator), 2)
print(monthly_total)

curr_principal = round(P, 2)
data = []
for i in range(1, (n + 1), 1):
month_interest = curr_principal * r
month_principal = round(monthly_total - month_interest, 2)
curr_principal = curr_principal - month_principal
data.append([i, month_interest, month_principal, round(curr_principal, 2)])

import pandas as pd
pd.set_option('display.max_rows', None)
df = pd.DataFrame(data, columns=["Period", "Interest", "Principal", "Remaining"], index= None)
print(df.to_string(index=False))
``````

Which prints this

``````5655.53
Period     Interest  Principal   Remaining
1  4239.583333    1415.95  1098584.05
2  4234.126026    1421.40  1097162.65
3  4228.647714    1426.88  1095735.77
``````

``````    358    64.905015    5590.62    11249.60
359    43.357833    5612.17     5637.43
360    21.727595    5633.80        3.63
``````

At the end the last number in the remaining column should be 0.00, but as you can see here it is 3.63.

What makes you think that a balance of \$3.63 after 360 payments is wrong? I’ve just checked it in LibreOffice and I get the same balance.

If it very common for the final payment of a mortgage to different from the rest. The final payment is either increased to cover the remaining balance, or decreased if the balance is less than the payment plus interest.

Thanks, I didn’t actually think of that! Now that I look more closely, the final payment is different in the mortgage calculator. But I’m still off by a different amount than I see in the online calculator.

How do you know that the online calculator is correct?

Maybe if you tell us the URL to the calculator, we can check it.

Right, maybe it is wrong, this is the one I was using: