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))
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.