我有一个跨越多个日期的时间戳列表(没有符号,只有时间戳)。这些有时可能是 1000/2000,跨越多个日期。
达到 hdb 并获得每个时间戳的最接近价格的最高效方法是什么?
从 hdbtable 中选择,其中 date = x -> 可以超过 60 毫米行。
为每个日期执行此操作,然后在顶部添加一个 aj 非常糟糕。
欢迎任何建议
我有一个跨越多个日期的时间戳列表(没有符号,只有时间戳)。这些有时可能是 1000/2000,跨越多个日期。
达到 hdb 并获得每个时间戳的最接近价格的最高效方法是什么?
从 hdbtable 中选择,其中 date = x -> 可以超过 60 毫米行。
为每个日期执行此操作,然后在顶部添加一个 aj 非常糟糕。
欢迎任何建议
假设 HDB 遵循在 sym 上使用 `p# 属性进行日期分区的标准约定,最高效的 aj 方式是
aj[`sym`time;select sym,time,other from myTable where …;select sym,time,price from prices where date=x]
除日期外,价格表上不应有其他过滤器/where 子句。
你是说你没有符号只是时间戳,但这是什么意思?这是否意味着您想要该时间戳的所有 sym 的价格,或者您想要该时间戳的任何sym 的最后价格?前者很简单,因为您只需将时间戳加入您的不同符号列表并将其用作 aj 中的“左”表。后者并不容易,因为 HDB 数据可能没有按时完全排序,它可能先按 sym 排序,然后按时间排序。在这种情况下,您可能必须再次将您的时间戳加入您的不同符号列表,并为所有符号添加 aj 的价格,并从该结果中获取具有最长时间的那个。
所以我想这取决于几个因素。更多信息可能会有所帮助。
编辑:基于进一步讨论的建议:
targetTimes:update targetTime:time from ([]time:"n"$09: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
这给出了最接近您的 targetTime 的任何 sym 的价格。然后你会peach
在多个日期这样做:
{targetTimes: ...;res:aj0[...];select from res ...}peach mydates;
请注意,使这变得复杂的是您要求它是最接近您的无符号目标时间的任何符号的价格。这看起来很奇怪——通常你会想要特定时间的 sym(s) 价格,而不是最接近特定时间的任何东西的价格。