transcendental-lisp/lisp/finance/interest-compounder.lisp

50 lines
1.3 KiB
Common Lisp
Raw Normal View History

(load "../lang/dlambda.lisp")
(defun interest-compounder (initial-principal initial-interest-rate)
(let ((private) (public)
(principal initial-principal)
2017-03-07 11:37:27 -05:00
(interest-rate initial-interest-rate)
(years-passed 0))
(setf private
(eval
(dlambda
2017-03-07 11:37:27 -05:00
(:add-years (years)
(if (> years 0)
(setf years-passed (+ years-passed years))))
(:percent-of-number (n percentage)
(if (> percentage 0)
(/ (+ (* n percentage) 50) 100)
(/ (- (* n percentage) 50) 100)))
(:compound-interest (years)
(if (> years 0)
(progn
(setf principal
(+ principal
(call private :percent-of-number principal interest-rate)))
(call private :compound-interest (- years 1))))))))
(setf public
(eval
(dlambda
2017-03-07 11:37:27 -05:00
(:get-years-passed ()
years-passed)
(:get-principal ()
principal)
(:get-interest-rate ()
interest-rate)
2017-03-07 11:37:27 -05:00
(:set-interest-rate (new-interest-rate)
(setf interest-rate new-interest-rate))
(:move-forward-years (years)
2017-03-07 11:37:27 -05:00
(progn
(call private :add-years years)
(call private :compound-interest years))))))))