mirror of
https://notabug.org/scuti/amort
synced 2025-01-01 13:01:50 +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:
|
if remaining_balance < 0:
|
||||||
principal_payment = principal_payment + remaining_balance
|
principal_payment = principal_payment + remaining_balance
|
||||||
|
monthly_payment = monthly_payment + remaining_balance
|
||||||
remaining_balance = 0
|
remaining_balance = 0
|
||||||
|
|
||||||
# Create a dictionary with payment details and add it to the amortization schedule
|
# Create a dictionary with payment details and add it to the amortization schedule
|
||||||
payment_details = {
|
payment_details = {
|
||||||
'Payment Number': payment_number,
|
'Payment Number': payment_number,
|
||||||
'Payment Amount': monthly_payment,
|
'Payment Amount': round(monthly_payment,2),
|
||||||
'Interest Payment': interest_payment,
|
'Interest Payment': interest_payment,
|
||||||
'Principal Payment': round(principal_payment,2),
|
'Principal Payment': round(principal_payment,2),
|
||||||
'Remaining Balance': round(remaining_balance,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)
|
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
|
# Display the amortization schedule
|
||||||
print("id, paid, interest payment, principal payment, remaining")
|
print("id, paid, interest payment, principal payment, remaining")
|
||||||
for payment in schedule:
|
for payment in schedule:
|
||||||
# print(payment)
|
# print(payment)
|
||||||
|
total_paid += payment["Payment Amount"]
|
||||||
|
total_interest_paid += payment["Interest Payment"]
|
||||||
|
total_principal_paid += payment["Principal Payment"]
|
||||||
if payment["Remaining Balance"] < 0:
|
if payment["Remaining Balance"] < 0:
|
||||||
break
|
break
|
||||||
attrs = [payment[key] for key in payment]
|
attrs = [payment[key] for key in payment]
|
||||||
print("%s" % ", ".join([str(attr) for attr in attrs]))
|
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