diff options
author | Eduardo Julian | 2022-12-12 03:47:35 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-12-12 03:47:35 -0400 |
commit | fe9a58dfcd5732ef0c5e5c4b7e85370cdc0db45a (patch) | |
tree | 5ad844ea2bdf33a67cceaad437efaf82cf773a02 /stdlib/source/test/lux/world/finance/trade/session.lux | |
parent | eef4422b1f16be2b8c651461f2c006dc4c11f314 (diff) |
Added trade session (OHLCV) abstraction.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/test/lux/world/finance/trade/session.lux | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/world/finance/trade/session.lux b/stdlib/source/test/lux/world/finance/trade/session.lux new file mode 100644 index 000000000..6ce1979d2 --- /dev/null +++ b/stdlib/source/test/lux/world/finance/trade/session.lux @@ -0,0 +1,89 @@ +(.require + [library + [lux (.except) + [abstract + [monad (.only do)] + [\\specification + ["[0]S" equivalence]]] + [data + ["[0]" bit (.use "[1]#[0]" equivalence)] + ["[0]" text (.use "[1]#[0]" equivalence)] + [collection + ["[0]" list]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + [/// + ["[0]" money (.only) + ["[0]" currency (.only Currency)]]]]] + [/// + ["[0]T" money]]) + +(def .public (random $) + (All (_ $) + (-> (Currency $) + (Random (/.Session $)))) + (do random.monad + [p0 (moneyT.random $) + p1 (moneyT.random $) + p2 (moneyT.random $) + p3 (moneyT.random $) + bullish? random.bit + volume random.nat] + (when (list.sorted money.< (list p0 p1 p2 p3)) + (list low bottom top high) + (in [/.#open (if bullish? + bottom + top) + /.#high high + /.#low low + /.#close (if bullish? + top + bottom) + /.#volume volume]) + + _ + (undefined)))) + +(def .public test + Test + (<| (_.covering /._) + (do [! random.monad] + [before (..random currency.usd) + after (..random currency.usd)]) + (_.for [/.Session /.Price /.Volume + /.#open /.#high /.#low /.#close /.#volume]) + (all _.and + (_.for [/.equivalence] + (equivalenceS.spec /.equivalence (..random currency.usd))) + + (_.coverage [/.composite] + (let [both (/.composite before after)] + (and (money.= (the /.#open before) + (the /.#open both)) + (and (money.>= (the /.#high before) + (the /.#high both)) + (money.>= (the /.#high after) + (the /.#high both))) + (and (money.<= (the /.#low before) + (the /.#low both)) + (money.<= (the /.#low after) + (the /.#low both))) + (money.= (the /.#close after) + (the /.#close both)) + (and (n.>= (the /.#volume before) + (the /.#volume both)) + (n.>= (the /.#volume after) + (the /.#volume both)))))) + (_.coverage [/.format] + (bit#= (of /.equivalence = + before + after) + (text#= (/.format before) + (/.format after)))) + ))) |