From 967d7d594d3737c4a986345aeb8fe1d0decc7c0f Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 28 Oct 2020 17:01:09 -0400 Subject: [PATCH] Refactor monthly totals --- mortgage-calculator.lisp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mortgage-calculator.lisp b/mortgage-calculator.lisp index e8036b0..0acfb12 100644 --- a/mortgage-calculator.lisp +++ b/mortgage-calculator.lisp @@ -23,28 +23,29 @@ P * (1-(1+r)^-n) = r * PV |# (defun find-payments (loan-total rate number-of-payments) - "Base loan calculation" + "Generic payment calculation" (/ (* rate loan-total) (- 1 (expt (+ 1 rate) (* number-of-payments -1))))) (defun find-monthly-payments(loan-total rate number-of-payments) - "Modify loan calculation to show monthly payments" + "Monthly payment by loan/rate/number of years" (find-payments loan-total (/ rate 12) (* number-of-payments 12))) -(defun find-montly-payment-total-per-year (loan-total rate number-of-payments) - "Modify loan calculation to show total montly payments per year" - (* (find-payments loan-total (/ rate 12) (* number-of-payments 12)) 12)) +(defun find-monthly-payment-total-per-year (loan-total rate number-of-payments) + "Total monthly payments per year" + (* (find-monthly-payments loan-total rate number-of-payments) 12)) ;; fixme: add function to take monthly-payments rate num-of-payments (defun find-biggest-loan (payments rate number-of-payments) - "Base loan calculation" + "Generic loan calculation" (/ (* payments - (- 1 (expt (+ 1 rate) - (* -1 number-of-payments)))) + (- 1 + (expt (+ 1 rate) (* -1 number-of-payments)))) rate)) (defun find-biggest-loan-monthly (payments rate number-of-payments) + "Largest loan by payments/interest rate/number of years" (find-biggest-loan payments (/ rate 12) (* number-of-payments 12)))