diff options
Diffstat (limited to 'stdlib/source/library/lux/world/finance/trade/session.lux')
-rw-r--r-- | stdlib/source/library/lux/world/finance/trade/session.lux | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/world/finance/trade/session.lux b/stdlib/source/library/lux/world/finance/trade/session.lux new file mode 100644 index 000000000..821135300 --- /dev/null +++ b/stdlib/source/library/lux/world/finance/trade/session.lux @@ -0,0 +1,67 @@ +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)]] + [data + [text + ["%" \\format (.only Format)]]] + [math + [number + ["n" nat]]]]] + [/// + ["[0]" money (.only Money) + [currency (.only Currency)]]]) + +(type .public (Price $) + (Money $)) + +(type .public Volume + Nat) + +(type .public (Session $) + (Record + [#open (Price $) + #high (Price $) + #low (Price $) + #close (Price $) + #volume Volume])) + +(def .public equivalence + (All (_ $) + (Equivalence (Session $))) + (implementation + (def (= reference subject) + (`` (and (,, (with_template [<=> <slot>] + [(<=> (the <slot> reference) (the <slot> subject))] + + [money.= #open] + [money.= #high] + [money.= #low] + [money.= #close] + [n.= #volume] + ))))))) + +(def .public (composite before after) + (All (_ $) + (-> (Session $) (Session $) + (Session $))) + [#open (the #open before) + #high (money.max (the #high before) (the #high after)) + #low (money.min (the #low before) (the #low after)) + #close (the #close after) + #volume (n.+ (the #volume before) (the #volume after))]) + +... https://en.wikipedia.org/wiki/Open-high-low-close_chart +(def .public (format it) + (All (_ $) + (Format (Session $))) + (`` (%.format (,, (with_template [<header> <slot> <format>] + [<header> ": " (`` (<format> (the <slot> it)))] + + ["O" #open money.format] + [" | H" #high money.format] + [" | L" #low money.format] + [" | C" #close money.format] + [" | V" #volume %.nat] + ))))) |