首页 > 解决方案 > 为什么“asof”连接不能既是“最近的”又是“严格的”?

问题描述

通过演示,为什么Empirical禁止以下?

>>> join trades, events on symbol asof timestamp nearest strict
Error: join 'asof' cannot be both 'nearest' and 'strict'

有没有办法匹配最接近但不准确的时间戳?

标签: empirical-lang

解决方案


这是不允许的,因为匹配的行可能是乱序的。想象一下这个设置:

data LeftItem: time: Time, code1: Char end
data RightItem: time: Time, code2: Char end
let left = !LeftItem([Time("09:30"), Time("09:31")], ['A', 'B'])
let right = !RightItem([Time("09:30"), Time("09:31")], ['a', 'b'])

我们现在有这些数据框:

>>> left
     time code1
 09:30:00     A
 09:31:00     B

>>> right
     time code2
 09:30:00     a
 09:31:00     b

如果有一个“最近的严格”,那么结果将是

     time code1 code2
 09:30:00     A     b
 09:31:00     B     a

从某种意义上说,这是正确的,因为我们有不准确的最接近的行,但这没有任何意义。我们期望时间单调增加,所以匹配的行不应该是倒序的。

所以最明智的做法是在“向后”和“向前”方向上允许“严格”,而不是“最近”。


推荐阅读