Reference/wj

From Kx Wiki
(Difference between revisions)
Jump to: navigation, search
Line 11: Line 11:
 
where:
 
where:
  
*<tt>t</tt> and <tt>q</tt> are the tables to be joined. <tt>q</tt> should be sorted <tt>sym</tt>time with <tt>`p#on</tt> sym
+
*<tt>t</tt> and <tt>q</tt> are the tables to be joined. <tt>q</tt> should be sorted <tt>`sym`time</tt> with <tt>`p#</tt> on sym
 
*<tt>w</tt> is a pair of lists of times, begin and end
 
*<tt>w</tt> is a pair of lists of times, begin and end
 
*<tt>c</tt> are the common column names, for syms and times
 
*<tt>c</tt> are the common column names, for syms and times

Revision as of 14:30, 17 June 2010

Contents

wj (window join function)

Window join is a generalization of asof join, and is available from kdb+ 2.6. asof join takes a snapshot of the current state, while window join aggregates all values of specified columns within intervals.

Syntax

  wj[w;c;t;(q;(f0;c0);(f1;c1))]

where:

Typically. this might be:

  wj[w;`sym`time;trade;(quote;(max;`ask);(min;`bid))]

For each record in t, the result has a record with additional columns c0 and c1, which are the results of the aggregation functions applied to values over the matching intervals in w.

Example

q)t
sym time     price
------------------
ibm 10:01:01 100
ibm 10:01:04 101
ibm 10:01:08 105

q)q
sym time     ask bid
--------------------
ibm 10:01:01 101 98
ibm 10:01:02 103 99
ibm 10:01:03 103 102
ibm 10:01:04 104 103
ibm 10:01:05 104 103
ibm 10:01:06 107 104
ibm 10:01:07 108 106
ibm 10:01:08 107 106
ibm 10:01:09 108 107

q)f:`sym`time
q)w:-2 1+\:t.time

q)wj[w;f;t;(q;(max;`ask);(min;`bid))]
sym time     price ask bid
--------------------------
ibm 10:01:01 100   103 98
ibm 10:01:04 101   104 99
ibm 10:01:08 105   108 104

The interval values may be seen as:

q)wj[w;f;t;(q;(::;`ask);(::;`bid))]
sym time     price ask             bid
--------------------------------------------------
ibm 10:01:01 100   101 103         98 99
ibm 10:01:04 101   103 103 104 104 99 102 103 103
ibm 10:01:08 105   107 108 107 108 104 106 106 107

See also


For a complete list of functions, see the kdb+ Function Reference.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox