Given a set of price buckets (of varying sizes) as follows:
buckets:(
1000.0 1000.4 1000.9 1001.6 1002.5 1003.6 1004.9 1006.4 1008.1 1010; // min bucket price
1000.4 1000.9 1001.6 1002.5 1003.6 1004.9 1006.4 1008.1 1010 1012.1 // max bucket price
);
specifying the maximum and minimum prices for a given bucket respectively. How might I group a trades table by these buckets and conduct aggregations on them thereafter. i.e.
q) trades
tid time | size price side
---------------------------| ---------------
0 2020.10.18T19:55:41.554| 40 1000.0 0 // first bucket
1 2020.10.18T20:07:41.554| 83 1000.1 0 // first bucket
2 2020.10.18T18:43:41.554| 30 1000.5 0 // second bucket
3 2020.10.18T19:35:41.554| 102 1000.6 0 // second bucket
4 2020.10.18T19:11:41.554| 16 1000.6 0 // second bucket
5 2020.10.18T21:17:41.554| 29 1000.9 0 // third bucket
6 2020.10.18T22:24:41.554| 67 1001.9 0 // fourth bucket
...
for simplicity's sake I have only shown the aggregation for one side
q) fn[trades;buckets]
bid | tid
---------------
0 | 0 1
1 | 2 3 4
2 | 5
3 | 6
Is there a canonical (efficient) way of achieving this functionality in kdb+/q?
Thanks for your guidance