mirror of
https://notabug.org/scuti/amort
synced 2024-11-25 16:28:50 +05:30
added arguments
This commit is contained in:
parent
7706949f76
commit
4b6958a06a
36
amort.py
36
amort.py
@ -1,3 +1,5 @@
|
||||
import argparse, json
|
||||
|
||||
def generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment=None):
|
||||
# Convert interest rate to decimal and calculate periodic interest rate
|
||||
monthly_interest_rate = interest_rate / 12 / 100
|
||||
@ -42,19 +44,39 @@ def generate_amortization_schedule(principal, interest_rate, loan_term, one_time
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Example usage
|
||||
principal = 100000
|
||||
interest_rate = 5.0
|
||||
loan_term = 3
|
||||
# principal = 100000
|
||||
# interest_rate = 5.0
|
||||
# loan_term = 3
|
||||
#
|
||||
def get_arguments():
|
||||
p = argparse.ArgumentParser()
|
||||
p. add_argument("--principal", "-p", type=float, \
|
||||
help="set value for principal")
|
||||
p.add_argument("---interest-rate", "-i", type=float,\
|
||||
help="set the value for interest rate (percentage)")
|
||||
p.add_argument("--term", "-t", type=int,\
|
||||
help="sets the term (years)")
|
||||
p.add_argument("--one-time", "-ot", type=str,\
|
||||
help="factors in a one-time payment (json, example: {\"payment_number\":13,\"amount\":5000}")
|
||||
args = p.parse_args()
|
||||
return args.principal, args.interest_rate, args.term, args.one_time
|
||||
|
||||
one_time_payment = {
|
||||
'payment_number': 13,
|
||||
'amount': 5000
|
||||
}
|
||||
principal, interest_rate, loan_term, one_time = get_arguments()
|
||||
if one_time is not None:
|
||||
one_time_payment = json.loads(one_time)
|
||||
else: one_time_payment = None
|
||||
# one_time_payment = {
|
||||
# 'payment_number': 13,
|
||||
# 'amount': 5000
|
||||
# }
|
||||
|
||||
schedule = generate_amortization_schedule(principal, interest_rate, loan_term, one_time_payment)
|
||||
|
||||
# Display the amortization schedule
|
||||
for payment in schedule:
|
||||
# print(payment)
|
||||
if payment["Remaining Balance"] < 0:
|
||||
break
|
||||
attrs = [payment[key] for key in payment]
|
||||
print(attrs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user