Skip to content

ratios

Ratios between items

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

Where

  • x is a numeric atom
  • y is a numeric list

returns the ratios of consecutive pairs of items of numeric list y.

ratios is an aggregate function.

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)ratios[5;1 2 4 6 7 10]
    0.2 2 2 1.5 1.166667 1.428571
    

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

    
    q)ratios 1 2 4 6 7 10
    1 2 2 1.5 1.166667 1.428571
    

Example

In a query to get returns on prices:


q)update ret:ratios price by sym from trade
q)select log ratios price from trade

Each Prior, differ, % Divide
Basics: Mathematics