Hello,
The following provides an alternative function and example output over several different offsets, again, using an asof join. A sample trade table, t, and quote table, q, are defined with random time,sym and price columns generated:
q)n:100;s:(a
bc
d);t:time xasc ([]time:n?.z.T;sym:n?s;price:n?10.); n:n*10; q:update
g#sym from `time xasc (time:n?.z.T;sym:n?s;price:n?10.)
The following function then uses an asof join between t and an offsetted q to create a table displaying the original price of each record followed by the price price_x at each offset time ot_x.
q){[q;t;offset]aj[sym
time;t;(time
sym,($string[
price],““,string[offset]),($string[
ot],””,string[offset])) xcol update time:time+offset,otime:time from q]}[q]/[t;10 20 30]
time sym price price_10 ot_10 price_20 ot_20 price_30 ot_30
-------------------------------------------------------------------------------------------
00:09:18.738 a 4.041054 2.968421 00:07:48.897 2.968421 00:07:48.897 2.968421 00:07:48.897
00:09:43.119 b 9.340615 4.793682 00:07:47.124 4.793682 00:07:47.124 4.793682 00:07:47.124
00:25:31.716 c 8.360091 1.102165 00:20:27.655 1.102165 00:20:27.655 1.102165 00:20:27.655
00:41:12.135 b 7.060537 5.494765 00:40:50.102 5.494765 00:40:50.102 5.494765 00:40:50.102
00:45:52.815 a 3.802801 6.090168 00:45:46.468 6.090168 00:45:46.468 6.090168 00:45:46.468
01:11:02.464 b 4.429798 7.082719 01:10:22.765 7.082719 01:10:22.765 7.082719 01:10:22.765
01:15:15.002 a 4.378904 4.249544 01:01:59.277 4.249544 01:01:59.277 4.249544 01:01:59.277
01:26:38.948 b 8.44846 2.609256 01:23:27.476 2.609256 01:23:27.476 2.609256 01:23:27.476
01:27:36.694 d 6.558275 2.558815 01:22:23.671 2.558815 01:22:23.671 2.558815 01:22:23.671
01:30:13.931 a 6.808597 7.414788 01:30:12.227 7.414788 01:30:12.227 7.414788 01:30:12.227
01:30:42.933 b 4.295886 8.941862 01:30:37.033 8.941862 01:30:37.033 8.941862 01:30:37.033
01:41:12.267 d 7.658848 2.230976 01:33:19.334 2.230976 01:33:19.334 2.230976 01:33:19.334
01:43:25.069 d 1.763493 1.707678 01:42:42.586 1.707678 01:42:42.586 1.707678 01:42:42.586
01:51:22.574 b 9.493308 7.882397 01:42:37.855 7.882397 01:42:37.855 7.882397 01:42:37.855
02:12:12.972 b 4.285788 8.034015 02:08:50.226 8.034015 02:08:50.226 8.034015 02:08:50.226
..
At the minute, the offsets are set to 10, 20 and 30 ms but you can cast offset to your desired format.
Hope this helps.
Regards,
Craig