I'm currently working on calculating markouts for some post trade analysis. In short, a markout is the change between prices over a time interval.
I have two tables, FILLORDERACK
and NBBO_20181001
.
FILLORDERACK
contains the following columns:
BIDPX, OFFERPX, TRANSACTTIME, TRADEDATE, SYMBOL
NBBO_20181001
contains the following columns:
BID, ASK, SYMBOL, TS
The data in NBBO_20181001
is a few million records of bid and offer prices for stocks in millisecond intervals.
What my query currently does it take a symbol and calculate the price markout at 1000 milliseconds after the trade:
i.e: Get the midpoint of the prices from FILLORDERACK
, divide it by the midpoint of the prices at the closest TS
from NBBO_20181001
, and subtract 1 from the value.
I currently have it working but for only 1 specific occurrence where t2.symbol = 'F'
.
I'm unsure how to append my query to work for all occurrences of a given symbol in the F
from FILLORDERACK
. If I have 200 rows in this table for that symbol, I should have 200 markouts calculated in the results.
select (((t2.BIDPX + t2.OFFERPX) / 2) / ((t1.BID + t1.ASK) / 2)) - 1, t2.TRANSACTTIME
from NBBO_20181001 t1, FILLORDERACK t2
where t2.symbol = 'F' and t1.symbol = t2.symbol and t2.TRADEDATE = '20181001'
and t1.TS between t2.TRANSACTTIME and TIMESTAMPADD(SQL_TSI_ms, 1000, (t2.TRANSACTTIME))
order by t1.TS desc limit 1