2018.07.26 06:05 PM
Hi,
I’m looking for an efficient way to easily grab the exacttimestamps associated with the highs and the lows within a OHLC (open, high,low, close) aggregation via xbar
For example:
select open_timestamp: first time, open:first price,high:max price, low:min price, close:last price, last_timestamp: last time by0D00:10:00.000000000 xbar time from trade where sym=`XXXXXX, exg=` XXXXXX
As shown above, it’s easy enough to grab the times of thefirst and the last values (open_timestamp and last_timestamp), but indexing inand getting the timestamp for the max and min values is less straight forward..
I came up with messy and verbose way to do this, butI’m sure there is a better way to do this .. via search & comparison (?) orsimilar which is eluding me at the moment.
Any ideas?
Thanks,
Bill
2018.07.26 11:57 PM
Something like the below might work for your case - A callback function that will be executed for each time slice, and which finds the index of the min/max price within that slice and uses that index to extract the relevant time value.
(I imagine this will be covered in Q Tips by Nick Psaris - I don't have my copy handy)
q)t:([]time:asc n?23:59;price:(n:10000)?100.0)
q)ohlc:{[t;p](t p?a;t p?b;a:min p;b:max p)}
q)select ohlc[time;price] by 10 xbar time.minute from t
2018.07.30 11:29 PM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.