mirror of
https://notabug.org/scuti/amort
synced 2024-11-25 16:28:50 +05:30
subtract from principal payment if remaining balance < 0
This commit is contained in:
parent
4b6958a06a
commit
2bf6ec00e2
10
amort.py
10
amort.py
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
import argparse, json
|
import argparse, json
|
||||||
|
|
||||||
def generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment=None):
|
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
|
# Update remaining balance
|
||||||
remaining_balance -= principal_payment
|
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
|
# 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,
|
||||||
@ -47,7 +52,6 @@ if __name__ == "__main__":
|
|||||||
# principal = 100000
|
# principal = 100000
|
||||||
# interest_rate = 5.0
|
# interest_rate = 5.0
|
||||||
# loan_term = 3
|
# loan_term = 3
|
||||||
#
|
|
||||||
def get_arguments():
|
def get_arguments():
|
||||||
p = argparse.ArgumentParser()
|
p = argparse.ArgumentParser()
|
||||||
p. add_argument("--principal", "-p", type=float, \
|
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)
|
schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment)
|
||||||
|
|
||||||
# Display the amortization schedule
|
# Display the amortization schedule
|
||||||
|
print("id, paid, interest payment, principal payment, remaining")
|
||||||
for payment in schedule:
|
for payment in schedule:
|
||||||
# print(payment)
|
# print(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(attrs)
|
print("%s" % ", ".join([str(attr) for attr in attrs]))
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user