mirror of
https://notabug.org/scuti/amort
synced 2024-11-26 00:38:49 +05:30
fixed error when invoked without extra-payments, relocated stuff relating to main block
This commit is contained in:
parent
5cc813a346
commit
b9d1382cd0
2
Makefile
2
Makefile
@ -3,5 +3,5 @@ reference:
|
||||
amortize -P 100000 -r 0.05 -f monthly -n 36 -s > ref.txt
|
||||
|
||||
test:
|
||||
python amort.py -p 100000 -i 5.0 -t 3 -ot "{\"payment_number\":13,\"amount\":5000}"
|
||||
python src/amort.py -p 100000 -i 5.0 -t 3 -ot "{\"payment_number\":13,\"amount\":5000}"
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
|
||||
import argparse, json
|
||||
|
||||
def generate_amortization_schedule(principal, interest_rate, loan_term, extra_payments=[]):
|
||||
# Convert interest rate to decimal and calculate periodic interest rate
|
||||
monthly_interest_rate = interest_rate / 12 / 100
|
||||
@ -73,7 +71,30 @@ def get_totals(amortization_schedule, func=None):
|
||||
func(messages)
|
||||
return total_paid, total_interest_paid, total_principal_paid
|
||||
|
||||
def compare(with_extra_payments, without):
|
||||
x,y,z = get_totals(with_extra_payments)
|
||||
a,b,c = get_totals(without)
|
||||
term_length = len(without) - len(with_extra_payments)
|
||||
print(chr(916), "paid: ", round(x-a,2))
|
||||
print(chr(916), "interest paid: ", round(y-b,2))
|
||||
print(chr(916), "principal paid: ", round(abs(z-c),2))
|
||||
print(chr(916), "term (months): ", term_length)
|
||||
|
||||
def display(table):
|
||||
print("id, paid, interest payment, principal payment, remaining")
|
||||
for row in table:
|
||||
print(row)
|
||||
|
||||
def export(table, filename="schedule.csv"):
|
||||
with open(filename, 'w') as f:
|
||||
print("id, paid, interest payment, principal payment, remaining", file=f)
|
||||
for row in table:
|
||||
print(row, file=f)
|
||||
print("wrote to file", filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse, json
|
||||
|
||||
def get_arguments():
|
||||
p = argparse.ArgumentParser()
|
||||
p. add_argument("--principal", "-p", type=float, \
|
||||
@ -94,29 +115,12 @@ if __name__ == "__main__":
|
||||
# print(extra["extra-payments"])
|
||||
if args.one_time is not None:
|
||||
l.append(json.loads(args.one_time))
|
||||
extra = []
|
||||
if "extra-payments" in l:
|
||||
extra = l["extra-payments"]
|
||||
extra.sort(key=lambda k: k["payment_number"])
|
||||
return args.principal, args.interest_rate, args.term, extra
|
||||
|
||||
def compare(with_extra_payments, without):
|
||||
x,y,z = get_totals(with_extra_payments)
|
||||
a,b,c = get_totals(without)
|
||||
print(chr(916), "paid: ", round(x-a,2))
|
||||
print(chr(916), "interest paid: ", round(y-b,2))
|
||||
print(chr(916), "principal paid: ", round(abs(z-c),2))
|
||||
|
||||
def display(table):
|
||||
print("id, paid, interest payment, principal payment, remaining")
|
||||
for row in table:
|
||||
print(row)
|
||||
|
||||
def export(table, filename="schedule.csv"):
|
||||
with open(filename, 'w') as f:
|
||||
print("id, paid, interest payment, principal payment, remaining", file=f)
|
||||
for row in table:
|
||||
print(row, file=f)
|
||||
print("wrote to file", filename)
|
||||
|
||||
principal, interest_rate, loan_term, extra_payments = get_arguments()
|
||||
|
||||
schedule = generate_amortization_schedule(principal, interest_rate, loan_term, extra_payments)
|
Loading…
Reference in New Issue
Block a user