From 4280ae75857511f5edeccce03f1323e855f0ce45 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Wed, 28 Oct 2020 16:41:15 -0400 Subject: [PATCH] Add largest affordable loan --- mortgage-calculator.lisp | 51 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/mortgage-calculator.lisp b/mortgage-calculator.lisp index 0c400b4..e8036b0 100644 --- a/mortgage-calculator.lisp +++ b/mortgage-calculator.lisp @@ -1,16 +1,6 @@ ;;;; Mortgage Calculators #| -loan amount (p) -interest rate (r) -years (t) -payments per year (n) -loan type: fixed-rate - -Payment = P x (r/n) * [1+(r/n)^n * t]/(1+r/n)^n *t - 1 - -or - P = payment PV = Present Value r = rate per period @@ -18,16 +8,45 @@ n = number of periods P = (r(PV)) / (1-(1+r)^-n) +Okay, but I want to find PV instead +Guess I need to remember algebra + +P = (r(PV)) / (1-(1+r)^-n) +P * (1-(1+r)^-n) = r * PV + +(P * (1-(1+r)^-n) / r = PV + + monthly-payments conversion + + (find-payments loan-total (/ rate 12) (* number-of-payments 12))) + find-payments = loan-total |# -(defun payments (loan-total rate number-of-payments) +(defun find-payments (loan-total rate number-of-payments) + "Base loan calculation" (/ (* rate loan-total) (- 1 (expt (+ 1 rate) (* number-of-payments -1))))) -(defun monthly-payments(loan-total rate number-of-payments) - "Number of payments in years" - (payments loan-total (/ rate 12) (* number-of-payments 12))) -(defun payment-total-per-year (loan-total rate number-of-payments) - (* (payments loan-total (/ rate 12) (* number-of-payments 12)) 12)) + +(defun find-monthly-payments(loan-total rate number-of-payments) + "Modify loan calculation to show monthly payments" + (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)) + + +;; fixme: add function to take monthly-payments rate num-of-payments +(defun find-biggest-loan (payments rate number-of-payments) + "Base loan calculation" + (/ (* payments + (- 1 (expt (+ 1 rate) + (* -1 number-of-payments)))) + rate)) + +(defun find-biggest-loan-monthly (payments rate number-of-payments) + (find-biggest-loan payments (/ rate 12) (* number-of-payments 12))) +