55 lines
1.4 KiB
Common Lisp
55 lines
1.4 KiB
Common Lisp
;;;; Mortgage Calculators
|
|
|
|
#|
|
|
P = payment
|
|
PV = Present Value
|
|
r = rate per period
|
|
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 find-payments (loan-total rate number-of-payments)
|
|
"Generic payment calculation"
|
|
(/ (* rate loan-total)
|
|
(- 1 (expt (+ 1 rate) (* number-of-payments -1)))))
|
|
|
|
(defun find-monthly-payments(loan-total rate number-of-payments)
|
|
"Monthly payment by loan/rate/number of years"
|
|
(find-payments loan-total (/ rate 12) (* number-of-payments 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)
|
|
"Generic loan calculation"
|
|
(/ (* 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)))
|
|
|
|
|
|
|
|
|
|
|