Skip to content

HFT Trade Analysis

Data: Orderbook + Trades. Orders are not included.

Key Functions

merge_asof() - merge two dataframes based on nearest key rather than exact matches. Useful for time series data. e.g. matching trades to the most recent mid price. merge_asof(trades, orderbook, on="timestamp", by="symbol", direction="backward")

resample('1min') - resample time series data into 1 minute intervals. closed='left' means left bin edge is included in interval. i.e. [00:00, 00:01). label='left' means the label for the interval is the left bin edge. i.e. 00:00. OHLC/stocks commonly use closed='right' and label='right'.

Metrics

Pricing Benchmarks

vwap twap quoted_spread effective_spread realized_spread

Orderflow

Orderbook Dynamics

Price impact and markouts

Risk

position + open_bid - open_ask - theoretical max value of position if all open orders are filled.

max(position + open_bid, | position - open_ask |) - theoretical max value of position if all open orders are filled, taking into account the direction of the position.