Reputation: 133
I have a trade table that contains historical execution records which contains timestamp, ric, side, price, quantity (where ric are all equities). Additionally, I have aj'ed the futures price snapshot table at each execution time. So, the trade table contains: timestamp, ric, side, price, quantity, futures_price.
I am trying to create an intra-day backtesting system where:
as each execution record is parsed (via { BACKTESTNIG_LOGIC_HERE } each trade
), different set of logics will be used to decide hedging timing.
Is it possible for me to create hedge table which can write down timestamp for executing futures, execution price, trade_qty, cumulative_qty without writing to the disk? Basically, I want to see if it is possible to dynamically update hedge table (as each execution record is passed) and pass hedge table.
I was looking at over
or scan
, but i wasn't sure if that was the right approach of doing it. Can you guys provide some insights on this matter?
Thank you!
Upvotes: 1
Views: 592
Reputation: 2991
Yes, it sounds like over is what you need to use in this case.
This allows you to pass in an initial state, update it and pass in back in for the next iteration.
For example:
q){.[x;(y`sym;`cnt);+;1]}/[([sym:()] cnt:`long$());trades]
sym | cnt
----| ---
ORCL| 114
YHOO| 110
AAPL| 105
IBM | 124
NOK | 120
CSCO| 112
MSFT| 95
DELL| 109
GOOG| 111
In this simple example, a trade table is iterated over (second arg to over), and the initial state is the simple keyed table ([sym:()] cnt:`long$())
On each iteration, we simply add 1 to the count for the relevant sym. In the real usage, you would perform your backtesting here and return the updated hedge
table from the lambda function - this updated table will be passed back into the function in the next iteration (e.g. in this example each time the cnt for a sym is increased, the next iteration receives the table with that cnt increased)
Upvotes: 1