Analytics¶
Format-agnostic analytics on a run's frames. These functions work with the output of any format's pipeline run (Bitstamp, LOBSTER, or custom). The book and lifecycle frames are on the Order book page, and the data-quality checks are on the Data quality page.
Trade Analysis¶
order_aggressiveness ¶
Calculate order aggressiveness with respect to the best bid or ask in BPS.
Each new limit order is measured against the best price on its own side of
the book as it stood just before the order arrived: the last
row of quotes strictly earlier in the canonical event order
(:func:~ob_analytics.schemas.time_order_keys -- timestamp, then
event_id between rows at the same instant), found by
:func:~ob_analytics.trade_sign.quote_before. A positive value means the
order improved on that price, a negative one sat behind it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The events DataFrame (must contain |
required |
quotes
|
DataFrame
|
The best bid and ask over time, such as the run's depth summary. It
must have |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The events DataFrame with an added |
trade_impacts ¶
Generate a DataFrame containing order book impact summaries.
Aggregates trade records by taker order ID to summarise how each aggressive order swept through the book (price range, number of fills, total volume, VWAP, duration).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trades
|
DataFrame
|
The trades DataFrame (must contain |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per taker order, with columns |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If a required column is missing, or the prices or sizes are integers
and the frame carries no |
maker_resting_times ¶
Return how long the maker order behind each trade had rested in the book.
Each trade is matched to its maker order through maker_event_id, and
the maker's placement time is the earliest created row of that order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
Events with |
required |
trades
|
DataFrame
|
Trades with |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per trade, in the order of trades, with columns
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
If a required column is missing, events has no rows (an L2 run has
no per-order events), or the prices or sizes are integers and trades
carries no |
Cancelled Orders¶
cancelled_orders ¶
Return each cancelled order's age and distance from the touch.
A cancelled order here is a cancelled-limit order (see
:func:set_order_types): placed, then deleted with the size it came with,
with no fill or change in between. Its placement and its end are read
from :func:~ob_analytics.book.order_lifecycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
Events with the columns :func: |
required |
lifecycles
|
DataFrame
|
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
One row per cancelled order, in placement order, with columns |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If a required column is missing, or the prices or sizes are integers
and events carries no |
Order Type Classification¶
set_order_types ¶
Determine limit order types.
Classifies each order as one of: market, resting-limit, cancelled-limit, or market-limit, based on how the order interacts with the book over its lifetime.
market and market-limit mark takers, so they need the trades' taker
ids. A feed that shows resting orders only (see
:class:~ob_analytics.protocols.TradeAttribution) has none, and no order
is labelled either; that is the feed, not a session without market orders.
LOBSTER fills its taker ids with a guess, so its labels are only as good
as the guess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
DataFrame
|
The limit order events DataFrame. |
required |
trades
|
DataFrame
|
The executions DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
The events DataFrame with an updated 'type' column indicating order types. |