KX Community

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

Home Forums kdb+ What is the difference between wj and wj1?

  • What is the difference between wj and wj1?

    Posted by vivo on August 19, 2022 at 12:00 am

    I have the below code, in which the result of wj and wj1 are exactly the same. Is there an example that wj and wj1 would give different output? From the documentation I can see that the 2 functions are different, but I’m not sure how to create an example to get different outputs. Thanks!

     

    t1:([]sym:3#`ibm;time:07:01:01 07:01:03 07:01:05;price:100 101 105);
    a:101 103 103 104 104 107 108 107 108;
    b:98 99 102 103 103 104 106 106 107;
    t2:([]sym:`ibm; time:07:01:01+til 9; ask:a; bid:b);

    c:`sym`time;
    w:-2 1+:t1.time;

    o1:wj[w;c;t1;(t2;(max;`ask);(min;`bid))];
    o2:wj1[w;c;t1;(t2;(max;`ask);(min;`bid))];
    o1~o2; // 1p;

     

    vivo replied 2 weeks ago 2 Members · 1 Reply
  • 1 Reply
  • rocuinneagain

    Member
    August 19, 2022 at 12:00 am

    You are seeing the same results as your t2 has an entry for every second

    If we swap til 9 for 2*til 9 we can create gaps and then you can see the differences where wj will bring in prevailing values but wj1 will not.

     

    t1:([]sym:3#`ibm;time:07:01:01 07:01:03 07:01:05;price:100 101 105); 
    a:101 103 103 104 104 107 108 107 108; 
    b:98 99 102 103 103 104 106 106 107; 
    t2:([]sym:`ibm; time:07:00:58+2*til 9; ask:a; bid:b); 
    c:`sym`time; w:-2 1+:t1.time; 
    o1:wj[w;c;t1;(t2;(max;`ask);(min;`bid))]; 
    o2:wj1[w;c;t1;(t2;(max;`ask);(min;`bid))]; 
    o1~o2; 
    // 0b; 
    
    q)wj[w;c;t1;(t2;(::;`ask);(::;`bid))] 
    sym time price ask bid 
    ------------------------------------------ 
    ibm 07:01:01 100 101 103 103 98 99 102 
    ibm 07:01:03 101 103 103 104 99 102 103 
    ibm 07:01:05 105 103 104 104 102 103 103 
    
    q)wj1[w;c;t1;(t2;(::;`ask);(::;`bid))] 
    sym time price ask bid 
    ---------------------------------- 
    ibm 07:01:01 100 103 103 99 102 
    ibm 07:01:03 101 103 104 102 103 
    ibm 07:01:05 105 104 104 103 103

     

Log in to reply.