Skip to content

deltas

Differences between list items

Syntax: deltas y, deltas[y], deltas[x;y]

Where

  • y is a numeric or temporal vector
  • x is a numeric or temporal atom of the same type as y

returns differences between consecutive pairs of items of y. Note deltas is ambivalent: can be applied as unary or binary.

Where applied as

  • a binary function, the result is

    
    (-[y 0;x];-[y 1;y 0];-[y 2;y 1];…;-[y n-1;y n-2])
    
    
    q)deltas[0N;1 4 9 16]
    0N 3 5 7
    

  • a unary function, 0 replaces the x in the binary application.

    
    q)deltas 1 4 9 16
    1 3 5 7
    

In a query to get price movements:

q)update diff:deltas price by sym from trade

With signum to count the number of up/down/same ticks:

q)select count i by signum deltas price from trade
price| x
-----| ----
-1   | 247
0    | 3
1    | 252

Each-prior, differ, ratios