给定时间戳列表获取 asof 价格的最有效方法

most performant way to get asof price given a list of timestamps

我有一个跨越多个日期的时间戳列表(没有符号,只有时间戳)。这些有时可以是 1000/2000,跨越多个日期。

找到组屋并获得每个时间戳的最接近可用价格的最佳方式是什么?

select 来自 hdbtable where date = x -> can be over 60mm rows.

每个约会都这样做,然后在上面放一个 aj 是非常糟糕的。

欢迎提出任何建议

假设 HDB 遵循在 sym 上使用 `p# 属性进行日期分区的标准约定,aj 的最佳方式是

aj[`sym`time;select sym,time,other from myTable where …;select sym,time,price from prices where date=x]

除日期外,价格 table 不应有其他 filters/where-clause。

你说你没有符号只有时间戳,但这是什么意思?这是否意味着您想要该时间戳的所有符号的价格,或者您想要该时间戳的 any 符号的最后价格?前者很简单,因为您只需将时间戳加入不同的符号列表并将其用作 aj 中的“左”table。后者不会那么容易,因为 HDB 数据可能没有按时完全排序,它很可能按 sym 然后按时间排序。在这种情况下,您可能不得不再次将时间戳加入到不同的符号列表中,并为所有符号的价格添加 aj,然后从该结果中获取时间最长的那个。

所以我想这取决于几个因素。更多信息可能会有所帮助。

编辑:基于进一步讨论的建议:

targetTimes:update targetTime:time from ([]time:"n":43:19 10:27:58 13:12:11 15:34:03);
res:aj0[`sym`time;(select distinct sym from trade where date=2021.01.22)cross targetTimes;select sym,time,price from trade where date=2021.01.22];

select from res where not null price,time=(max;time)fby targetTime
sym  time                 targetTime           price
----------------------------------------------------
AQMS 0D09:43:18.999937967 0D09:43:19.000000000 4.5
ARNA 0D10:27:57.999842638 0D10:27:58.000000000 76.49
GE   0D15:34:02.999979520 0D15:34:03.000000000 11.17
HAL  0D13:12:10.997972224 0D13:12:11.000000000 18.81

这给出了最接近您的目标时间的交易品种的价格。然后你会 peach 这在多个日期:

{targetTimes: ...;res:aj0[...];select from res ...}peach mydates;

请注意,让事情变得复杂的原因是您要求 any 符号的价格最接近您的无符号目标时间。这看起来很奇怪 - 通常您会想要 sym(s) 在特定时间的价格,而不是最接近特定时间的任何东西的价格。

您可以使用多线程来优化您的查询,为每个线程分配一个日期来处理,本质上利用的不仅仅是一个核心:

{select from hdbtable where date = x} peach listofdates

可以找到有关多线程的更多信息here, and more info on peach can be found here