Home › Forums › kdb+ › xbar & timestamp manipulation › Re: xbar & timestamp manipulation
-
I’m not sure what your complete data set looks like – but using a best guess, I get an expected result.
q)tt:([]DT:`timestamp$2012.12.31 2013.01.02 2013.01.03 2013.01.04 2013.01.07 2013.01.08 2013.01.09 2013.01.10 2013.01.11 2013.01.14;O:1405.22 1426.19 1462.42 1459.37 1466.47 1461.89 1457.15 1461.02 1472.12 1472.05;C:1425.69 1461.36 1459.07 1466.1 1461.77 1457.05 1461.04 1471.99 1471.71 1470.79) q)select first O,last C by DT:(2 xbar DT.date)+1D16:00 from tt DT | O C -----------------------------| --------------- 2013.01.01D16:00:00.000000000| 1405.22 1425.69 // open 31st, close 31st 2013.01.03D16:00:00.000000000| 1426.19 1459.07 // open 2nd, close 3rd 2013.01.05D16:00:00.000000000| 1459.37 1466.1 // open 4th, close 4th 2013.01.07D16:00:00.000000000| 1466.47 1461.77 // open 7th, close 7th 2013.01.09D16:00:00.000000000| 1461.89 1461.04 // open 8th, close 9th 2013.01.11D16:00:00.000000000| 1461.02 1471.71 // open 10th, close 11th 2013.01.15D16:00:00.000000000| 1472.05 1470.79 // open 14th, close 14th
I also don’t see how you can have 2012.12.31D16:00:00 in both results (1 day/2 day buckets), as it shouldn’t appear in the 2-day bucket query (unless you have some other row dated 2012.12.30 in your table you’re not showing us?)
q)(2 xbar 2012.12.31)+0D16:00 1D16:00 2012.12.31D16:00:00.000000000 2013.01.01D16:00:00.000000000
This looks like some data quality issue somewhere rather than issue with xbar – if you can provide a small stand alone sample of your data that replicates the problem, I can take a look using that.