depth

As-of join

You have a trade table and a quote table, both with sym and time. Attach to each trade the latest quote at or before the trade time.

Hint

This is the classic time-series join in q.

Solution

aj[`sym`time; trade; quote]

The last column in the key list is the time column and is matched as-of. Preceding columns are matched exactly. quote needs to be sorted by time within each sym, and on large tables an attribute such as `g# on sym speeds up the lookup.

Answer

aj[`sym`time; trade; quote]