KDB计算行之间的变化百分比
我以这种方式在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新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