feat: Phase 2 — microstructure analytics + 81 tests
New microstructure/ module with pure-function analytics: microstructure/book.py: microprice() — depth-weighted mid price mid_price() — simple bid/ask midpoint order_book_imbalance() — ranged [-1, 1] volume skew depth_imbalance() — imbalance at fixed price distance spread_stats() — spread, spread_bps, mid, bid, ask depth_resiliency() — bid/ask volume within impact radius queue_depletion_prob() — Poisson fill probability at level batch_book_stats() — aggregate stats across snapshots microstructure/trades.py: classify_lee_ready() — Lee-Ready aggressor classification classify_bulk_lee_ready() — batch classification with mids/bids/asks compute_markouts() — forward mid-price change at configurable horizons markout_summary() — mean/std/t-stat per side per horizon trade_volume_profile() — size bucket distribution trade_arrival_rate() — rolling trades/sec with burst detection microstructure/toxicity.py: compute_vpin() — volume-synchronized informed trading probability compute_vpin_time_series() — rolling VPIN with alarm threshold fill_toxicity() — adverse price movement post-trade adverse_selection_ratio() — per-side adverse selection liquidation_clustering() — cluster detection in liquidation events microstructure/funding.py: funding_regime() — classify regime (neutral/positive/negative/high) funding_predictability() — AR(1) autocorrelation analysis funding_carry_pnl() — cumulative carry PnL estimation basis_spread() — perp premium over spot (bps) basis_convergence_speed() — mean-reversion half-life via AR(1) microstructure/signals.py: composite_signal() — weighted OBI + trade + VPIN + funding signal SignalPipeline — stateful pipeline accumulating book/trade updates detect_hft_regime() — regime classifier for HFT strategy selection Bug fixes in Phase 1: - data/latency.py: proper linear-interpolation percentiles - data/normalizer.py: UTC timezone for naive datetimes - data/normalizer.py: detect_sequence_gap returns gap-1 (missing count) - microstructure/toxicity.py: consistent vpin_value key in compute_vpin 81 tests across 4 test files (store, normalizer, latency, microstructure)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
Microstructure analytics — book, trade, toxicity, funding, and signal composition.
|
||||
|
||||
Pure functions that take market data arrays and return computed metrics.
|
||||
"""
|
||||
|
||||
from microstructure.book import (
|
||||
microprice,
|
||||
mid_price,
|
||||
order_book_imbalance,
|
||||
depth_imbalance,
|
||||
spread_stats,
|
||||
depth_resiliency,
|
||||
queue_depletion_prob,
|
||||
batch_book_stats,
|
||||
)
|
||||
|
||||
from microstructure.trades import (
|
||||
classify_lee_ready,
|
||||
classify_bulk_lee_ready,
|
||||
compute_markouts,
|
||||
markout_summary,
|
||||
trade_volume_profile,
|
||||
trade_arrival_rate,
|
||||
)
|
||||
|
||||
from microstructure.toxicity import (
|
||||
compute_vpin,
|
||||
compute_vpin_time_series,
|
||||
fill_toxicity,
|
||||
adverse_selection_ratio,
|
||||
liquidation_clustering,
|
||||
)
|
||||
|
||||
from microstructure.funding import (
|
||||
funding_regime,
|
||||
funding_predictability,
|
||||
funding_carry_pnl,
|
||||
basis_spread,
|
||||
basis_convergence_speed,
|
||||
)
|
||||
|
||||
from microstructure.signals import (
|
||||
composite_signal,
|
||||
SignalPipeline,
|
||||
detect_hft_regime,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"microprice", "mid_price", "order_book_imbalance", "depth_imbalance",
|
||||
"spread_stats", "depth_resiliency", "queue_depletion_prob", "batch_book_stats",
|
||||
"classify_lee_ready", "classify_bulk_lee_ready", "compute_markouts",
|
||||
"markout_summary", "trade_volume_profile", "trade_arrival_rate",
|
||||
"compute_vpin", "compute_vpin_time_series", "fill_toxicity",
|
||||
"adverse_selection_ratio", "liquidation_clustering",
|
||||
"funding_regime", "funding_predictability", "funding_carry_pnl",
|
||||
"basis_spread", "basis_convergence_speed",
|
||||
"composite_signal", "SignalPipeline", "detect_hft_regime",
|
||||
]
|
||||
Reference in New Issue
Block a user