35 lines
713 B
Common Lisp
35 lines
713 B
Common Lisp
;;;; 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))
|
|
|
|
|
|
|
|
|