【问题标题】:Can we do asof join in excel as we do in kdb我们可以像在 kdb 中那样在 excel 中加入 asof 吗
【发布时间】:2019-04-12 03:59:44
【问题描述】:

我对excel一无所知,我想知道是否有一种方法可以将q-coding中的asof join语句转换为使用excel公式的方法

:update string issueSeries from aj[`sym`issueSeries`stockExchange`time;update `$issueSeries from table;update `g#sym from `time xasc select time+maxinterval,sym,`$issueSeries,stockExchange,refprice,refpricetime,prevpricetime,prevprice from reftable];

Table 1
 Time        Exc    sym  price
2:40:29 PM  25001   AMX 14.47
2:40:48 PM  25001   AMX 14.48
2:40:53 PM  25001   AMX 14.45
2:41:21 PM  25001   AMX 14.44
2:41:29 PM  25001   AMX 14.49   

   Table 2
    Exc     Sym  Refprice  ref-time
    25001   AMX   14.47   2:39:54 PM
    25001   AMX   14.46   2:40:36 PM
    25001   AMX   14.46   2:41:19 PM
    25001   AMX   14.46   2:41:20 PM
    25001   AMX   14.46   2:41:31 PM

Table 3 (result)
Time        ref-time     sym   exc    price   refprice

2:40:29 PM  2:39:54 PM   AMX   25001  14.47   14.47
2:40:48 PM  2:40:36 PM   AMX   25001  14.48   14.46
2:40:53 PM  2:40:36 PM   AMX   25001  14.45   14.46
2:41:21 PM  2:41:20 PM   AMX   25001  14.44   14.46
2:41:29 PM  2:41:20 PM   AMX   25001  14.49   14.46

Simplified example where exchange and sym are held constant.    

table3 的 ref-time 列与 table2 的 ref-time 列不同,因为 asof join 是代码中的 (aj)。

【问题讨论】:

  • 请提供您在 Excel 文件中列出的示例数据和预期结果。
  • @tigeravatar 我刚刚添加了一个示例

标签: excel kdb


【解决方案1】:

看起来您只是复制了表 1,然后根据 Exc 和 sym 从表 2 中查找了相关的 ref-time 和 refprice。如果是这种情况,并假设这样的数据集(请注意,表 1 和表 2 按 Exc 然后 sym 然后 Time 排序):

我最初复制了表 1 并按原样粘贴到 K2 中。然后我为 ref-time 和 refprice 插入了新列。

  • 单元格 L2 中的公式并复制下来以获得参考时间:=MAX(INDEX($I$3:$I$7*($F$3:$F$7=M3)*($G$3:$G$7=N3)*($I$3:$I$7<=K3),))
  • 单元格 P2 中的公式并复制下来以获得参考价格:=INDEX($H$3:$H$7,MATCH(1,INDEX(($F$3:$F$7=M3)*($G$3:$G$7=N3)*($I$3:$I$7=L3),),0))

调整范围以适合您的实际数据集。

【讨论】:

  • 表3的ref-time列与表2的ref-time列不同。这是由于“asof join”的概念
  • @kevbuntu 在表 3 中,我的结果与您发布的结果表相同。你能澄清一下有什么不同吗?
  • 参考时间永远不会大于时间。在您的回答记录中,3,5 参考时间大于时间,但在我们的表 3 中并非如此。
  • @kevbuntu 谢谢,我现在明白了。然后需要为此添加检查。只需一分钟。
  • @kevbuntu 更新了答案。奖励是这次不需要输入数组公式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
  • 2020-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多