Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KDB reverse asof join (aj) ie on next quote instead of previous one

Tags:

join

k

kdb

aj[`time`sym;trade;quote] is joining each trade with the previous value of quote.

I'd like to do the same join, but on the next value of quote instead of the previous one.

How can I achieve this?

like image 971
MarinD Avatar asked Feb 24 '17 10:02

MarinD


1 Answers

Define the following function:

k)ajr: {.Q.ft[{d:x_z;$[&/j:-1<i:(x#z)binr x#y;y,'d i;+.[+.Q.ff[y]d;(!+d;j);:;.+d i j:&j]]}[x,();;0!z]]y}

which is just the definition of aj in k, with binr instead of bin.

Then it can be used exactly like aj, but it will return the next quote instead of the previous one.

Source: https://groups.google.com/d/topic/personal-kdbplus/F-5zVzkvc6c

like image 64
MarinD Avatar answered Sep 17 '22 16:09

MarinD