timestamp of max and min value when using xbar for OHLC?

123 views
Skip to first unread message

William Mayott

unread,
Jul 27, 2018, 1:25:15 AM7/27/18
to Kdb+ Personal Developers

Hi,

 

I’m looking for an efficient way to easily grab the exact timestamps 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 by 0D00:10:00.000000000 xbar time from trade where sym=`XXXXXX, exg=` XXXXXX

 

As shown above, it’s easy enough to grab the times of the first and the last values (open_timestamp and last_timestamp), but indexing in and getting the timestamp for the max and min values is less straight forward ..

 

I came up with  messy and verbose way to do this, but I’m sure there is a better way to do this .. via search & comparison (?) or similar which is eluding me at the moment.

 

Any ideas?

 

Thanks,

Bill

JW Buitenhuis

unread,
Jul 27, 2018, 3:01:22 AM7/27/18
to personal...@googlegroups.com

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




--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at https://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

hzad...@gmail.com

unread,
Jul 31, 2018, 2:47:24 AM7/31/18
to Kdb+ Personal Developers
Yes, this is very helpful.


On Friday, 27 July 2018 15:01:22 UTC+8, JW Buitenhuis wrote:

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



On 27 July 2018 at 02:05, William Mayott <wma...@gmail.com> wrote:

Hi,

 

I’m looking for an efficient way to easily grab the exact timestamps 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 by 0D00:10:00.000000000 xbar time from trade where sym=`XXXXXX, exg=` XXXXXX

 

As shown above, it’s easy enough to grab the times of the first and the last values (open_timestamp and last_timestamp), but indexing in and getting the timestamp for the max and min values is less straight forward ..

 

I came up with  messy and verbose way to do this, but I’m sure there is a better way to do this .. via search & comparison (?) or similar which is eluding me at the moment.

 

Any ideas?

 

Thanks,

Bill

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbpl...@googlegroups.com.
To post to this group, send email to personal...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages