depth
Problems / q / kdb+ / Medium

Time buckets

Round each time (in minutes) down to the start of its 5-minute bucket.

f 3 7 12 14 20

should return 0 5 10 10 20.

Hint

This operator is how you build OHLC bars in qSQL.

Solution

f:{5 xbar x}

xbar rounds down to the nearest multiple of the left argument. Group by it to build bars: select last price by 5 xbar time.minute from trade.

Answer

f:{5 xbar x}