Expand description
Databento-backed vol oracle for CME products (initially GC gold options).
This module holds everything Databento-specific behind a single file: the
CME symbology parser, expiry calendar, MBP-1 book cache, chain-to-IV
aggregator, a mockable feed trait, and the RiskVolOracle implementation
that publishes surfaces to the rest of the API. Nothing here is exposed
to consumers except the final DatabentoVolOracle struct.
The build-out follows a test-driven sequence; see the cycle markers in
the tests submodules.
StructsΒ§
- Bbo π
- A single top-of-book snapshot. Databento MBP-1 records carry exactly this shape (best bid/size + best ask/size + timestamp), so we just store what weβre given.
- Book
Cache π - Per-instrument top-of-book cache. Intentionally dumb: the Databento MBP-1 feed already collapses the full book to a single BBO per update, so thereβs no order book to maintain here β just the most-recent snapshot per instrument.
- Chain
Context π - Quality filters applied to raw option quotes before we even try to solve for IV. Tuned defaults aim to reject obvious garbage (one-sided markets, locked books, stale prints) without being so aggressive that we eat the thin wings of a real CME chain.
- CmeFuture
Symbol π - A parsed CME futures contract symbol.
- CmeOption
Symbol π - A parsed CME option-on-future symbol.
- Databento
Live Feed - Adapter that wraps Databento Live behind our
DatabentoFeedtrait. - Databento
Oracle πState - Databento
Orchestrator π - Stateful glue that turns a stream of
FeedRecords into a live vol surface. Holds the instrument registry, the BBO cache, and the most recent forward weβve seen for the underlying futures contract. - Databento
VolOracle - A
RiskVolOraclebacked by a Databento feed. Owns aDatabentoOrchestratorunder anRwLockand a cachedVolatilitySurfacethat is rebuilt on every ingested record. - Databento
VolOracle Config - Config for the Databento vol oracle.
- Fake
Feed π - Deterministic in-memory feed used exclusively in tests. Hand it a
Vec<FeedRecord>and it replays them in order, one pernext_recordcall, then returnsNoneforever. - Fitted
IvPoint π - A single (strike, expiry, iv) point fit from a quality quote. Ready to
insert into a
VolatilitySurface. - Option
Quote π - A raw option quote as we pull it off Databento. Normalised to the shape the aggregator wants: one strike, one expiry, one side, BBO, and the timestamp we received it at.
EnumsΒ§
- CmeOption
Side π - Which side of the option β call or put.
- Feed
Record π - Events we consume from a Databento feed, after the SDK-specific DBN records have been adapted to our internal representation.
- Instrument
Kind π - A product-type-agnostic view of a single Databento instrument definition, normalised to the fields we actually consume.
ConstantsΒ§
- DATABENTO_
DEFINITION_ πDRAIN_ IDLE_ SECS - How long to wait (idle seconds) before we consider the Definition
snapshot drained and shut that client down. Local reproduction shows
the full
GLBX.MDP3GC+OG directory (43 730 records) drains in ~5s β a 3s idle window is a comfortable cutoff. - DATABENTO_
MBP1_ πREPLAY_ MINUTES - How far back to replay MBP1 on connect. Only used to re-seed
book_cacheon pod restart β 5 minutes is plenty, the live tail does the rest. - RECONNECT_
BASE_ πDELAY - Initial delay before the first reconnect attempt.
- RECONNECT_
MAX_ πDELAY - Maximum delay between reconnect attempts (capped exponential backoff).
- SECONDS_
PER_ πYEAR - Seconds per year used to convert seconds-to-expiry into Black-76βs
time-to-expiry parameter (Ο). 365.0 matches the existing
calculate_implied_volatilitycallers in this repo.
TraitsΒ§
- Databento
Feed π - Abstraction over a Databento live-or-historical feed, narrowed to the two calls the provider needs: pull the next record, or stop.
FunctionsΒ§
- cme_
month_ πcode_ to_ number - CME Globex month codes. Standard across every listed product.
- compute_
iv_ πpoints - Fit an implied-vol point from each quote in the chain that survives quality checks. Filters silently β the count of dropped quotes is observable by comparing input/output lengths if a caller needs it.
- is_
weekday π - last_
day_ πof_ month - og_
monthly_ πexpiry - Compute the nominal expiry for a CME OG (gold-on-futures) monthly option contract in the requested option-contract month.
- spawn_
databento_ live_ feed_ task - Spawns a detached tokio task that connects to Databento, drives the
oracleβs
runloop, and automatically reconnects with exponential backoff when the feed drops or fails to connect.
Type AliasesΒ§
- Instrument
Id π - Databentoβs canonical 64-bit instrument identifier.