mirror of
https://notabug.org/scuti/amort
synced 2024-12-29 19:50:23 +05:30
fixed total payment when one-time payments are applied
This commit is contained in:
parent
2bf6ec00e2
commit
16ce241169
14
amort.py
14
amort.py
@ -33,12 +33,13 @@ def generate_amortization_schedule(principal, interest_rate, loan_term, one_time
|
||||
|
||||
if remaining_balance < 0:
|
||||
principal_payment = principal_payment + remaining_balance
|
||||
monthly_payment = monthly_payment + remaining_balance
|
||||
remaining_balance = 0
|
||||
|
||||
# Create a dictionary with payment details and add it to the amortization schedule
|
||||
payment_details = {
|
||||
'Payment Number': payment_number,
|
||||
'Payment Amount': monthly_payment,
|
||||
'Payment Amount': round(monthly_payment,2),
|
||||
'Interest Payment': interest_payment,
|
||||
'Principal Payment': round(principal_payment,2),
|
||||
'Remaining Balance': round(remaining_balance,2)
|
||||
@ -76,13 +77,22 @@ if __name__ == "__main__":
|
||||
|
||||
schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment)
|
||||
|
||||
total_paid = 0
|
||||
total_interest_paid = 0
|
||||
total_principal_paid = 0
|
||||
|
||||
# Display the amortization schedule
|
||||
print("id, paid, interest payment, principal payment, remaining")
|
||||
for payment in schedule:
|
||||
# print(payment)
|
||||
total_paid += payment["Payment Amount"]
|
||||
total_interest_paid += payment["Interest Payment"]
|
||||
total_principal_paid += payment["Principal Payment"]
|
||||
if payment["Remaining Balance"] < 0:
|
||||
break
|
||||
attrs = [payment[key] for key in payment]
|
||||
print("%s" % ", ".join([str(attr) for attr in attrs]))
|
||||
|
||||
|
||||
print("total paid: ", round(total_paid,2))
|
||||
print("total interest paid: ", round(total_interest_paid,2))
|
||||
print("total principal paid: ", round(total_principal_paid,2))
|
||||
|
Loading…
Reference in New Issue
Block a user