user1056903
user1056903

Reputation: 941

Aggregation of data in microsecond bars in kdb+

How can I use the xbar function to aggregate rows in a table in 10 microsecond bars. The table consists of the columns timestamp and val. For aggregating in millisecond bars instead I already know that I can simply use timestamp.datetime in the xbar query.

A possible result table should look as follows:

timestamp                 | val
--------------------------| ---
2015.12.02D12:19:44.434430| 2
2015.12.02D12:19:44.434440| 8
2015.12.02D12:19:44.434450| 5

Any help is appreciated.

Upvotes: 5

Views: 1366

Answers (1)

jgleeson
jgleeson

Reputation: 955

The below should work:

d:([]t:asc .z.P+100*10?100;v:10?10)
select avg v by (10*1000) xbar t from d

Note that the output time column is still a 'timestamp' ("p") type, however the values are barred in microseconds.

I wrote the first xbar argument as (10*1000) for clarity. To change to 5 microseconds you can do (5*1000) etc.

Upvotes: 3

Related Questions