KDB计算行之间的变化百分比

发布于 2025-01-21 17:42:34 字数 687 浏览 0 评论 0原文

我以这种方式在24小时内计算百分比变化,您可以在下面看到。

有什么方法可以通过查询直接从KDB获取百分比? DF应将百分比作为最终值返回。

df = q.sendSync('{[x;y]value select by x xbar DateTime.minute from trades where DateTime > .z.p-0D01, symbol=y }',30,np.string_(symbol))

start  = df.iloc[0].price
end = df.iloc[-1].price

return ((end-start)/start) * 100 ##### return -0.01152

KDB查询结果:

                 DateTime    side       symbol  amount     price   
0 2022-04-15 14:59:59.975  b'buy'  b'ETH-USDT'  0.0033     3035.75  
1 2022-04-15 15:29:58.889  b'buy'  b'ETH-USDT'   0.079     3035.2100
2 2022-04-15 15:32:09.050  b'buy'  b'ETH-USDT'  0.0165     3034.1599

i calculate percent change in 24 hour by this way that you can see below.

is there any way to get calculated percent directly from kdb by query?
df should return the percent as final value.

df = q.sendSync('{[x;y]value select by x xbar DateTime.minute from trades where DateTime > .z.p-0D01, symbol=y }',30,np.string_(symbol))

start  = df.iloc[0].price
end = df.iloc[-1].price

return ((end-start)/start) * 100 ##### return -0.01152

kdb query result:

                 DateTime    side       symbol  amount     price   
0 2022-04-15 14:59:59.975  b'buy'  b'ETH-USDT'  0.0033     3035.75  
1 2022-04-15 15:29:58.889  b'buy'  b'ETH-USDT'   0.079     3035.2100
2 2022-04-15 15:32:09.050  b'buy'  b'ETH-USDT'  0.0165     3034.1599

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青柠芒果 2025-01-28 17:42:34
first exec 100*(last[price]-price[0])%price[0] from trades where DateTime > .z.p-0D01, symbol=y
first exec 100*(last[price]-price[0])%price[0] from trades where DateTime > .z.p-0D01, symbol=y
多像笑话 2025-01-28 17:42:34

更新PCTDIFF: - [价格%首价; 1]从交易中

此查询创建了额外的列“从头开始到现在的百分比更改”,当然您需要先按时间对表进行排序。

如果表格中有多个符号,并且要计算每个符号:

更新pctdiff: - [价格%first Price; 1] sym sym sym sym也可以帮助此查询。

update PctDiff:-[price%first price;1] from trades

This query creates additional column of "percent change from start to now", and of course you need to sort the table by time first.

This query can also help if you have multiple symbols in the table and want to calculate for each sym:

update PctDiff:-[price%first price;1] by sym from trades

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文