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

59 lines
1.6 KiB
Common Lisp
Raw Normal View History

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