2020.02.03
Source: adopted from here
Introduction¶
One frequently asked question in analyzing the behavior of a Smart Order Router (SOR) is how many time periods in which there is no open child orders on market and what are the start time and length of the no-slice period.
The following function genOrders
simulates 5,000 child orders with order submission time and the time each order exits from the limit order book. It is assumed that the trading hours is from 09:30
to 16:00
and the parent order arrives exactly at 09:30
.
genOrders:{[nOrders;seed;openTime;closeTime]
system "S ",string seed;
submitTimes:asc closeTime&openTime+nOrders?390*60*1000;
system "S ",string seed;
exitTimes:closeTime&submitTimes+nOrders?60*1000;
([] orderId:1000+til nOrders;subT:submitTimes;exitT:exitTimes)
};
openTime:`time$09:30;
closeTime:`time$16:00;
simOrders:genOrders[5000;-314159;openTime;closeTime];
Question¶
We want to find all the time periods when there is no open child orders on market and how long each no-order period lasts. The expected output is a table which should look like:
startTime | periodLength |
---|---|
09:30:00.000 | 00:00:17.080 |
10:25:57.802 | 00:00:04.595 |
10:29:43.843 | 00:00:00.676 |
11:08:07.079 | 00:00:05.682 |
12:30:43.199 | 00:00:08.152 |
15:29:06.359 | 00:00:08.213 |
Answer¶
Below is the suggested answer to this question:
times:update maxT:maxs exitT from simOrders;
times:update noOrderDur:subT-prev maxT from times;
times:update noOrderDur:subT-openTime from times where null noOrderDur;
select startTime:`time$subT-noOrderDur,periodLength:`time$noOrderDur from times where noOrderDur>0
Some detailed explanations on the suggested solution:
- Line 1: Find the running maximum time of order exiting from market.
- Line 2: Take the difference between the order submission time of each child order and the previous maximum exiting time. There is at least one open order on market if this time difference is negative.
- Line 3: Determine the period of no orders between market open and the time the first child order is sliced out.
- Line 4: Select the time period when the length of no-order period is positive.