This is a follow up post to complete How to get active Price at uniform time interval?
q)t
time x
——————-
08:00:01 0.2557052
08:00:07 0.20912
08:00:09 0.6004199
08:00:10 0.974358
08:00:15 0.08293808
q)select x by 2 xbar time.second from t
second | x
——–| ———-
08:00:00| 0.2557052
08:00:06| 0.20912
08:00:08| 0.6004199
08:00:10| 0.974358
08:00:14| 0.08293808
If we also want the active price at time point 08:00:02 08:00:04 and 08:00:12, we could do:
q)aj[`second;([]second:08:00:00 + 2*til 8);select second, x from select x by 2 xbar time.second from t]
second x
——————-
08:00:00 0.2557052
08:00:02 0.2557052
08:00:04 0.2557052
08:00:06 0.20912
08:00:08 0.6004199
08:00:10 0.974358
08:00:12 0.974358
08:00:14 0.08293808
Why does this work? It is because the special feature of Asof Join (aj) on KDB+ tables.
Above we are basically join two tables, where both table has a column named “second”. The left table has all the second point we would like to get data, the right table maps ‘x’ to known second point. The ‘aj’ operator will fill up the data for any second point missing from right table.
More details will be in next post on the “Filling missing data in KDB+ tables”.
Tags: all time interval, asof join, fill data, KDB+, last price, missing data, missing time, q