diff --git a/amort.py b/amort.py index 456db38..17ab4cd 100644 --- a/amort.py +++ b/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 - - one_time_payment = { - 'payment_number': 13, - 'amount': 5000 - } + # 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 + + 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) +