kdb - KDB+/Q:从历史水平/价格更新重建订单的最佳方式?
问题描述
给定以下数据规范:
q) ob
src sym price size side time
----------------------------------------------------------
1 2 930700 439 -1 2020.06.20D00:00:00.053000000
1 2 930708 444 -1 2020.06.20D00:00:00.054000000
1 2 930739 817 1 2020.06.20D00:00:00.055000000
1 2 930739 0 1 2020.06.20D00:00:00.056000000
...
其中 src 代表交易所,sym 代表符号等,其中每一行代表每个价格的大小的即时状态(未完成的订单数量)。
在给定窗口内重建历史订单簿的最佳机制是什么,例如 1000 个分时(每边),分时大小为 1?(最低买入价=最高买入价-1000;最低卖出价=最高卖出价+1000)等。
我曾想过做以下事情,但对应该有一个更正式/更有效的机制来实现这一点的先驱有所妥协,我希望从你的建议中获得。更新不需要实时聚合,即每个事件,以下示例假设聚合窗口为 10 秒。
// doesn't account for deleted levels (where size = 0) inefficient?
x:select last size by `src`sym`side`price 10 xbar `second$time from ob; // window by time
x:update fills size by `src`sym`side`price from x; // forward fill the sizes
x:delete from x where size=0;
x:delete from (select last size, last price, mnp:min price, mxp:max price by `src`sym`side`time) where $[side>0;price<(mxp-1000);price>(mnp+1000)]; // delete out of bounds asks and bids
这种多步骤方法似乎效率低下,因此我希望从您那里获得有关如何更有效地做到这一点的见解。我期待着您的回复。提前致谢。
解决方案
我希望我对您的理解正确,但这是您所追求的吗?
select last fills size by src,sym,side,price,10 xbar `second$time from tab where size<>0,?[side=-1;price<(min price)+1000;price>(max price)-1000]
在这里,我们只是使用 where 子句来删除不需要的行,而不是单独的 delete 语句。
推荐阅读
- cucumber - 页面对象上的 Serenity Cucumber4 环境 URL 不起作用
- react-360 - npm 配置问题中的问题,卡在加载阶段
- python - 无法为两个耦合序列的给定递归关系解压缩不可迭代的 int 对象?
- vim - 如何在 Windows Terminal Preview 中运行的 vim 中重新绑定 ctrl-space?
- java - 如何使用 Bazel 指定 Java 版本
- python - 有没有办法将矢量拉伸到相同的长度?
- elasticsearch - 查找最近的时间戳
- reactjs - redux 表单样式与子样式冲突
- c# - 使用 PUB-SUB 使用 zmq 从 python 发送数据到 Unity3d (C#)
- python - 使用openpyxl python模块访问路径中的文件时出错