subtract from principal payment if remaining balance < 0

This commit is contained in:
- 2024-02-09 16:47:56 -08:00
parent 4b6958a06a
commit 2bf6ec00e2

View File

@ -1,3 +1,4 @@
import argparse, json
def generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment=None):
@ -30,6 +31,10 @@ def generate_amortization_schedule(principal, interest_rate, loan_term, one_time
# Update remaining balance
remaining_balance -= principal_payment
if remaining_balance < 0:
principal_payment = principal_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,
@ -47,7 +52,6 @@ if __name__ == "__main__":
# principal = 100000
# interest_rate = 5.0
# loan_term = 3
#
def get_arguments():
p = argparse.ArgumentParser()
p. add_argument("--principal", "-p", type=float, \
@ -73,10 +77,12 @@ if __name__ == "__main__":
schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment)
# Display the amortization schedule
print("id, paid, interest payment, principal payment, remaining")
for payment in schedule:
# print(payment)
if payment["Remaining Balance"] < 0:
break
attrs = [payment[key] for key in payment]
print(attrs)
print("%s" % ", ".join([str(attr) for attr in attrs]))