diff options
author | Eduardo Julian | 2023-02-12 02:54:39 -0400 |
---|---|---|
committer | Eduardo Julian | 2023-02-12 02:54:39 -0400 |
commit | 049dcdc0c6dc678786dbf854a20385fb6ef06f9a (patch) | |
tree | 65188f9d0858116d20051930705aa73b66d2aaa5 /stdlib/source/library/lux/world/finance/interest/rate.lux | |
parent | 6c4c9a8c10950e3244f15451fe18fb768abee924 (diff) |
Added an abstraction for interest rates.
Diffstat (limited to 'stdlib/source/library/lux/world/finance/interest/rate.lux')
-rw-r--r-- | stdlib/source/library/lux/world/finance/interest/rate.lux | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/world/finance/interest/rate.lux b/stdlib/source/library/lux/world/finance/interest/rate.lux new file mode 100644 index 000000000..61fd9f9a5 --- /dev/null +++ b/stdlib/source/library/lux/world/finance/interest/rate.lux @@ -0,0 +1,63 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.require + [library + [lux (.except) + [abstract + [monoid (.only Monoid)]] + [control + [function + [predicate (.only Predicate)]]] + [data + [text + ["%" \\format]]] + [math + [number + ["n" nat] + ["f" frac]]]]] + [/// + ["[0]" money (.only Money)]]) + +... https://en.wikipedia.org/wiki/Interest_rate +(type .public Rate + Frac) + +... https://en.wikipedia.org/wiki/Break-even +(def .public break_even + Rate + +1.0) + +... https://en.wikipedia.org/wiki/Compound_interest +(def .public compound + (-> Rate Rate + Rate) + f.*) + +(with_template [<order> <name>] + [(def .public <name> + (Predicate Rate) + (<order> ..break_even))] + + [f.< loss?] + [f.> gain?] + [f.= break_even?] + ) + +(def .public monoid + (Monoid Rate) + (implementation + (def identity ..break_even) + (def composite ..compound))) + +(def .public format + (%.Format Rate) + (|>> (f.- ..break_even) + %.percentage)) + +(def .public (rate before after) + (All (_ $) + (-> (Money $) (Money $) + Rate)) + (f./ (n.frac (money.amount before)) + (n.frac (money.amount after)))) |