如何匹配2个列表(KDB)中的日期和字符串? [英] How to match date and string from 2 lists (KDB)?

查看:94
本文介绍了如何匹配2个列表(KDB)中的日期和字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表:

data:
dt                             sym    bid    ask
2017.01.01D05:00:09.140745000  AAPL   101.20 101.30
2017.01.01D05:00:09.284281800  GOOG   801.00 802.00
2017.01.02D05:00:09.824847299  AAPL   101.30 101.40

info:
date          sym    shares    divisor
2017.01.01    AAPL   500       2
2017.01.01    GOOG   100       1
2017.01.02    AAPL   200       2

我需要从信息"中添加基于日期的每个股票报价的份额和除数值.我怎样才能做到这一点?下面是一个示例:

I need to append from "info" the shares and divisor values for each ticker based on the date. How can I achieve this? Below is an example:

result:
dt                             sym    bid    ask     shares   divisor
2017.01.01D05:00:09.140745000  AAPL   101.20 101.30  500      2
2017.01.01D05:00:09.284281800  GOOG   801.00 802.00  100      1
2017.01.02D05:00:09.824847299  AAPL   101.30 101.40  200      2

推荐答案

如果基于精确的日期匹配进行匹配,则可以使用

If matching based on an exact date match then you can use lj. For this to work you will need to create a date column in the data table and key info by date and sym. Like so:

(update date:`date$dt from data)lj 2!info
dt                            sym  price    date       shares divisor
---------------------------------------------------------------------
2018.02.04D17:25:06.658216000 AAPL 103.9275 2018.02.04 500    2
2018.02.04D17:25:06.658216000 GOOG 105.1709 2018.02.04 100    1
2018.02.05D17:25:06.658217000 AAPL 105.1598 2018.02.05 200    2
2018.02.05D17:25:06.658217000 GOOG 104.0666 2018.02.05

然后您可以从此输出中删除date列.

You can then delete the date column from this output.

这篇关于如何匹配2个列表(KDB)中的日期和字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆