c# - Any way to replicate the OR operator with only ANDs? -
so trying find way allow or operations on front-end of app , translate condition on back-end server talk intrinio (financial data api). endpoint trying use (to save on api call credits) allows , operator hoping there sort of way around this.
here endpoint trying use: http://docs.intrinio.com/#securities-search-screener
here example condition sending server translated:
open_price > 10 && (current_volume > 1000000 || current_volume > average_volume) p.s open_price, current_volume, , average_volume tags used within intrinio ecosystem
i should mention don't have nots
i implore guys @ link before commenting...
in general, can't.
in api, can negate atomic conditions only, changing ~gt~ ~lte~ etc., e. g. changing open_price~gt~10 open_price~lte~10.
but can't negate non-atomic conditions in api, in particular can't use de morgan's laws.
there 3n (+1) boolean functions of n variables, expressible using conjunction , atomic negation. total number of boolean functions of n variables 22ⁿ. way, of them expressible using conjunction , non-atomic negation. thus, there exist boolean functions not expressible using conjunction , atomic negation.
you should make 2 or more requests , union results on api client. there few ways differ in number of requests, in total number of records retrieved (some records might retrieved more once), , in api call credits required (it equal number of conditions).
let's suppose original data looks follows (let's skip open_price attribute).
{ { "identifier": "a-ok", "current_volume": 1000002, "average_volume": 1000001 }, { "identifier": "b-ok", "current_volume": 1000001, "average_volume": 999999 }, { "identifier": "d-ok", "current_volume": 999999, "average_volume": 999998 }, { "identifier": "e-ok", "current_volume": 1000001, "average_volume": 1000002 }, { "identifier": "g-no", "current_volume": 999999, "average_volume": 1000001 }, { "identifier": "h-no", "current_volume": 999998, "average_volume": 999999 } } you need retrieve records identifiers a-ok, b-ok, d-ok, e-ok.
approach 1 (two requests, resultsets not disjoint)
current_volume~gt~1000000 current_volume~gt~average_volume as can see, perform disjunction on client, not on server...
approach 2 (three requests, resultsets disjoint)
current_volume~gt~1000000,current_volume~gt~average_volume current_volume~gt~1000000,current_volume~lte~average_volume current_volume~lte~1000000,current_volume~gt~average_volume in approach, rely on fact: a||b equal (a && b) ^^ (a && !b) ^^ (!a && b).
approach 3 (two requests, resultsets disjoint)
current_volume~gt~1000000 current_volume~lte~1000000,current_volume~gt~average_volume in approach, rely on fact: a||b equal a ^^ (!a && b).
approach 4 (two requests, resultsets disjoint)
in particular case, there exists approach relies on transitivity of order relation on real numbers.
average_volume~gt~1000000,current_volume~gt~1000000 average_volume~lte~1000000,current_volume~gt~average_volume however, approach not give profit in terms of api call credits.
comparison
+----------+----------+-----------+--------------+----------+ | approach | number of| records | resultsets | total | | | requests | retrieved | disjointness | credits | +----------+----------+-----------+--------------+----------+ | # 1 | 2 | 6 (3+3) | no | 2 | | # 2 | 3 | 4 | yes | 6 | | # 3 | 2 | 4 | yes | 3 | | # 4 | 2 | 4 | yes | 4 | +----------+----------+-----------+--------------+----------+
Comments
Post a Comment