This repository bridges high-throughput data engineering with advanced Econophysics to model the hidden dynamics of financial market microstructure. By treating market participants as interacting particles within a fluid system, this engine reconstructs the limit order book (LOB) to extract predictive alpha and mathematically model liquidity consumption.
- Order Flow Imbalance (OFI): Maps the net directional pressure exerted by aggressive market orders against resting limit orders. By tracking volume fluxes at the Bid and Ask boundaries, the model isolates structural imbalances that empirically precede short-term price drift.
- Hawkes Process Modeling: Quantifies market "FOMO" by framing order executions as self-exciting point processes. It measures how a single aggressive liquidity-taking event temporarily spikes the probability of subsequent algorithmic chain reactions.
- Dynamic State Calibration: Utilizes Maximum Likelihood Estimation (MLE) via SciPy's SLSQP algorithm to computationally fit the Hawkes parameters (baseline noise, excitation, and exponential decay), strictly bounding the branching ratio to ensure mathematical stationarity.
The pipeline is designed to process Level-2 tick data. The demonstrations in this repository utilize Google (GOOG) order book data sourced from LOBSTER.
Note: Due to LOBSTER's academic licensing restrictions, the raw sample_data.csv is not included in this repository. To replicate this environment, you must download a sample dataset directly from LOBSTER and place it in the root directory.
To replicate this research environment, you must initialize a cloud database to act as the high-frequency data sink.
- Environment Setup: Create a free project at Supabase. Create a
.envfile in your root directory containing your specificSUPABASE_URLandSUPABASE_ANON_KEY. Ensure.envis listed in your.gitignore. - High-Frequency Ingestion: Execute
node ingest.mjsto stream the asynchronous LOBSTER events into the cloud database via a backpressure-aware Node.js pipeline. - State Reconstruction: Run
python research/lob_reconstruction.pyto recursively rebuild the Bid-Ask spread mechanics and calculate cumulative OFI pressure. - MLE Optimization: Execute
python research/hawkes_mle.pyto computationally solve for the continuous-time physical constants governing the asset's microstructure.
The foundational engine reconstructs the continuous-time Bid-Ask spread mechanics from microsecond-level order book events.

Demonstrating the 0.45 Pearson correlation between cumulative net directional pressure and underlying mid-price drift.

The dynamically calibrated structural FOMO model, constrained via SLSQP to maintain mathematical stationarity.
