Data API¶
The lumina_lob.data package downloads and calibrates against real tick data.
lumina_lob.data.polygon
¶
Polygon.io downloader for end-of-day bars and tick/trade data.
Classes¶
PolygonClient
¶
Lightweight client for Polygon.io market data.
Parameters¶
api_key:
Polygon API key. If omitted, read from the POLYGON_API_KEY
environment variable.
base_url:
Polygon API base URL.
cache_dir:
Directory to cache raw JSON responses.
Source code in lumina_lob/data/polygon.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
Methods:¶
get_daily_bars(ticker, start_date, end_date)
¶
Fetch daily OHLCV bars for ticker between start_date and end_date.
Dates must be in YYYY-MM-DD format. Results are cached by ticker
and date range.
Returns¶
DataFrame with columns:
timestamp, open, high, low, close, volume,
vwap, transactions.
Source code in lumina_lob/data/polygon.py
get_trades(ticker, date)
¶
Fetch trades (ticks) for ticker on date.
Returns¶
DataFrame with columns:
timestamp, price, size, exchange, conditions.
Source code in lumina_lob/data/polygon.py
lumina_lob.data.databento
¶
Databento downloader for historical trades and quotes.
Classes¶
DatabentoClient
¶
Lightweight client for Databento historical market data.
Parameters¶
api_key:
Databento API key. If omitted, read from the DATABENTO_API_KEY
environment variable.
cache_dir:
Directory to cache raw DBN files.
Source code in lumina_lob/data/databento.py
Methods:¶
get_quotes(symbol, start, end, dataset='XNAS.ITCH', schema='bbo')
¶
Fetch quote records for symbol between start and end.
Default schema is bbo (best bid/offer). Use mbo for market-by-order.
Returns¶
DataFrame with the requested quote schema columns.
Source code in lumina_lob/data/databento.py
get_trades(symbol, start, end, dataset='XNAS.ITCH')
¶
Fetch trade records for symbol between start and end.
Returns¶
DataFrame with Databento trades schema columns.
Source code in lumina_lob/data/databento.py
lumina_lob.data.calibration
¶
Calibration utilities for fitting agent parameters to real market data.
Classes¶
CalibratedParams
dataclass
¶
Parameters estimated from real market data for simulation agents.
Attributes¶
arrival_rate:
Expected number of events per time_unit (e.g., per second).
size_dist_method:
Either "lognormal" or "empirical".
size_lognorm_mu:
Mean of log-sizes when size_dist_method == "lognormal".
size_lognorm_sigma:
Standard deviation of log-sizes when size_dist_method == "lognormal".
size_hist:
Normalized empirical size histogram when size_dist_method == "empirical".
mean_spread:
Average bid-ask spread in price units, if quote data was supplied.
tick_size:
Minimum price increment inferred from the spread / price grid.
time_unit:
Unit used for arrival_rate ("S" = seconds, "min" = minutes, etc.).
permanent_impact:
Permanent price-impact coefficient per unit signed volume, if price data
was supplied.
temporary_impact:
Temporary price-impact coefficient per unit signed volume, if price data
was supplied.
impact_decay:
Decay factor for the propagator-style temporary impact residual.
Source code in lumina_lob/data/calibration.py
Functions:¶
calibrate(trades, quotes=None, size_method='lognormal', time_unit='S', bid_col='bid_px_00', ask_col='ask_px_00', price_col='price', side_col='side')
¶
Estimate agent parameters from a trades DataFrame and optional quotes.
Parameters¶
trades:
DataFrame with at least timestamp and size columns. If price_col
and side_col are present, propagator-style impact coefficients are also
estimated.
quotes:
Optional DataFrame with at least timestamp, bid_col and ask_col.
size_method:
"lognormal" fits log(size); "empirical" returns a normalized
histogram.
time_unit:
Unit for arrival_rate. Pandas frequency string, e.g. "S",
"min", "H".
bid_col, ask_col:
Column names for best bid and ask in quotes.
price_col:
Column name for trade prices in trades.
side_col:
Column name for trade side in trades.
Returns¶
CalibratedParams
Source code in lumina_lob/data/calibration.py
lumina_lob.data.replay
¶
Replay historical tick events through the matching engine.
Classes¶
ReplayEngine
¶
Replay a merged stream of quote updates and trades through the engine.
For every quote event, the previous synthetic best-bid/best-ask limit orders are cancelled and replaced by fresh ones at the new quoted prices. For every trade event, a market order in the trade direction is submitted with the traded quantity. After each event the current best spread is recorded, allowing a comparison between the real quote spread distribution and the spread distribution produced by the engine.
Source code in lumina_lob/data/replay.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
Methods:¶
replay(events, event_col='event_type', bid_col='bid_px', ask_col='ask_px', side_col='side', size_col='size')
¶
Process events in row order and return a metrics DataFrame.
Parameters¶
events:
DataFrame with at least timestamp and event_type columns.
event_type values must be "quote" or "trade". Quote rows
must contain bid_col and ask_col. Trade rows must contain
side_col and size_col.
event_col:
Name of the column that distinguishes quote and trade events.
bid_col, ask_col:
Column names for quoted bid/ask prices.
side_col, size_col:
Column names for trade side and trade size.
Returns¶
pandas.DataFrame
One row per event with columns timestamp, spread,
best_bid, and best_ask.
Source code in lumina_lob/data/replay.py
Functions:¶
validate_spread_distribution(real_spreads, simulated_spreads, bins=None)
¶
Return a histogram-overlap similarity score between two spread distributions.
The score is in [0, 1] where 1 means identical normalized histograms and
0 means no overlap.