ratios¶
Ratios between items
ratios y ratios[y]
Where y is a non-symbolic sortable list, returns the ratios of the underlying values of consecutive pairs of items of y.
ratios is an aggregate function.
Examples: queries to get returns on prices:
In a query to get price movements:
With signum to count the number of up/down/same ticks:
Implicit iteration¶
ratios applies to dictionaries and tables.
q)k:`k xkey update k:`abc`def`ghi from t:flip d:`a`b!(10 21 3;4 5 6)
q)ratios d
a| 10 21 3
b| 0.4 0.2380952 2
q)ratios t
a b
--------------
10 4
2.1 1.25
0.1428571 1.2
q)ratios k
k | a b
---| --------------
abc| 10 4
def| 2.1 1.25
ghi| 0.1428571 1.2
First predecessor¶
The predecessor of the first item is 1.
It may be more convenient to have 1 as the first item of the result.
Subtract Each Divide
The derived function %': (Divide Each Prior) used to define ratios is variadic and can be applied as either a unary or a binary.
However, ratios is supported only as a unary function.
For binary application, use the derived function.