mortgage-calculator/mortgage-calculator.lisp

35 lines
713 B
Common Lisp
Raw Normal View History

2020-10-28 15:54:16 -04:00
;;;; 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
n = number of periods
P = (r(PV)) / (1-(1+r)^-n)
|#
(defun payments (loan-total rate number-of-payments)
(/ (* 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))