KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy MAX , MIN query

  • MAX , MIN query

    Posted by Akash on April 21, 2025 at 11:33 am

    Hello all,

    I am working on a problem with HDB where I have t+1 intraday data , and I want the  MAX,MIN of each Symbol each mentioned by time shown in image , I can get data with interval using XBAR .But i want as per data logged in system.

    I attached image for reference

    EX.
    SYM   Price   time
    A         53.4     00:00:12.123
    A         42.4     00:00:13.465
    B         78.2      00:00:15.123
    B         45.2      00:00:16.123

    OUT

    SYM  Price  time
    A        53.4    00:00:12.123
    A        53.4    00:00:13.465
    B        78.2     00:00:15.123
    B        78.2      00:00:16.123

    Data is mixed and I have approach where I can use different variables and combine it,

    but can we solve it in 1 query

     

    mwoods replied 7 minutes ago 2 Members · 1 Reply
  • 1 Reply
  • mwoods

    Administrator
    April 22, 2025 at 10:51 am

    You can use maxs and mins to compute the running maximum/minimum by sym.

    q)t1:([]sym:`A`A`B`B;price:53.4 42.4 78.2 45.2;time:00:00:12.123 00:00:13.465 00:00:15.123 00:00:16.123)
    q)t1
    sym price time        
    ----------------------
    A   53.4  00:00:12.123
    A   42.4  00:00:13.465
    B   78.2  00:00:15.123
    B   45.2  00:00:16.123

    q)update maxPrice:max maxs price,minPrice:min mins price by sym from t1
    sym price time maxPrice minPrice
    ----------------------------------------
    A 53.4 00:00:12.123 53.4 42.4
    A 42.4 00:00:13.465 53.4 42.4
    B 78.2 00:00:15.123 78.2 45.2
    B 45.2 00:00:16.123 78.2 45.2   
    • This reply was modified 6 minutes ago by  mwoods.

Log in to reply.