Yeah so a best-practice for stuff like is to center the system on rule sets. They can be maintained in excel, and saved as a .csv. All these ANDs and ORs are clumsy, difficult to debug/maintain, and to be avoided.
Create n rule sets and apply the ones you want; E.g.:
Set 1: Action: BUY 100
or as JSON:
A rule engine parses market data. When the stars align and all rules within a set evaluate to true, take specified action. Written in a functional style/language like Haskell or even modern C++!
Market data are stored as rows in a database. Advance a pointer through the datasets, test rules at every iteration. Probably MariaDB or Postgres. Personally I like to store times for a day as units from market open (so for US equities 9:30:00.000000ET is time 0). This is debatable but I like it for different reasons. Regardless, times must be properly synched for accurate results.
As for language for the framework, I'd use Python or Kotlin, unless things get too slow, then C++, Go, or even just C.
This architecture permits quick and easy testing of a variety of rule sets: just add them into excel and dump it as a .csv or JSON structure. Rule sets can even be generated; e.g. write a little script to generate rules ranging +/-5% stepping by 1%. Write the csv, feed it into the rule engine, and see what it spits out. Rules can even be dynamically added/modified as market conditions change.
Rule sets can also be created for results; set rules to detect anomalies in the data and write out a report for idea generation.
If you have a Mac, look at their "Advanced Search" in Finder for a simple example of a rule set and engine. It finds files based on a set of rules and conditions you provide.
Create n rule sets and apply the ones you want; E.g.:
Set 1: Action: BUY 100
Code:
OP, lt, CL.1*.98
CL.1,lt,MA.1
MPD#SPYOP.1,lt,MPD#SPYCL.1
DAY,ne,5
or as JSON:
Code:
[
"TSLA": {
"action": {
"side": "buy",
"qty": 100,
// etc
},
"rule": [ // array
{
"lhs": "OP",
"oper": "lt",
"rhs": "MA.1"
},
{
"lhs": "CL.1"
// etc
}
A rule engine parses market data. When the stars align and all rules within a set evaluate to true, take specified action. Written in a functional style/language like Haskell or even modern C++!
Market data are stored as rows in a database. Advance a pointer through the datasets, test rules at every iteration. Probably MariaDB or Postgres. Personally I like to store times for a day as units from market open (so for US equities 9:30:00.000000ET is time 0). This is debatable but I like it for different reasons. Regardless, times must be properly synched for accurate results.
As for language for the framework, I'd use Python or Kotlin, unless things get too slow, then C++, Go, or even just C.
This architecture permits quick and easy testing of a variety of rule sets: just add them into excel and dump it as a .csv or JSON structure. Rule sets can even be generated; e.g. write a little script to generate rules ranging +/-5% stepping by 1%. Write the csv, feed it into the rule engine, and see what it spits out. Rules can even be dynamically added/modified as market conditions change.
Rule sets can also be created for results; set rules to detect anomalies in the data and write out a report for idea generation.
If you have a Mac, look at their "Advanced Search" in Finder for a simple example of a rule set and engine. It finds files based on a set of rules and conditions you provide.
Last edited: