mortgage-calculator/mortgage-calculator.lisp

57 lines
1.2 KiB
Common Lisp
Raw Permalink Normal View History

2020-10-28 15:54:16 -04:00
;;;; Mortgage Calculators
#|
2020-10-28 17:04:37 -04:00
Formulas:
2020-10-28 15:54:16 -04:00
P = payment
PV = Present Value
r = rate per period
n = number of periods
2020-10-28 17:04:37 -04:00
Find payments
2020-10-28 15:54:16 -04:00
P = (r(PV)) / (1-(1+r)^-n)
2020-10-28 17:04:37 -04:00
Find total
2020-10-28 16:41:15 -04:00
P = (r(PV)) / (1-(1+r)^-n)
P * (1-(1+r)^-n) = r * PV
(P * (1-(1+r)^-n) / r = PV
2020-10-28 17:04:37 -04:00
Find rate
TODO
Find payments
TODO
2020-10-28 16:41:15 -04:00
2020-10-28 15:54:16 -04:00
|#
2020-10-28 16:41:15 -04:00
(defun find-payments (loan-total rate number-of-payments)
2020-10-28 17:01:09 -04:00
"Generic payment calculation"
2020-10-28 15:54:16 -04:00
(/ (* rate loan-total)
(- 1 (expt (+ 1 rate) (* number-of-payments -1)))))
2020-10-28 16:41:15 -04:00
(defun find-monthly-payments(loan-total rate number-of-payments)
2020-10-28 17:01:09 -04:00
"Monthly payment by loan/rate/number of years"
2020-10-28 16:41:15 -04:00
(find-payments loan-total (/ rate 12) (* number-of-payments 12)))
2020-10-28 17:01:09 -04:00
(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))
2020-10-28 16:41:15 -04:00
;; fixme: add function to take monthly-payments rate num-of-payments
(defun find-biggest-loan (payments rate number-of-payments)
2020-10-28 17:01:09 -04:00
"Generic loan calculation"
2020-10-28 16:41:15 -04:00
(/ (* payments
2020-10-28 17:01:09 -04:00
(- 1
(expt (+ 1 rate) (* -1 number-of-payments))))
2020-10-28 16:41:15 -04:00
rate))
(defun find-biggest-loan-monthly (payments rate number-of-payments)
2020-10-28 17:01:09 -04:00
"Largest loan by payments/interest rate/number of years"
2020-10-28 16:41:15 -04:00
(find-biggest-loan payments (/ rate 12) (* number-of-payments 12)))
2020-10-28 15:54:16 -04:00