An Open Quantum Systems & Microstructure Dynamics Framework for High-Frequency Quantitative Finance.
Developed by anthra123x.
Entropiq is a high-performance quantitative framework implemented in Rust. It formulates financial market microstructure as an open quantum system, evaluating continuous state dynamics at the single-tick resolution. By mapping limit order book observables into density matrices and solving the Lindblad Master Equation via fourth-order Runge-Kutta numerical integration, the system extracts non-commutative probability metrics including exact von Neumann entropy, quantum coherence, continuous-time quantum walk (CTQW) depth dispersion, and liquidity hydrodynamic shock waves.
The computational core executes with zero dynamic heap allocations on the critical hot path, achieving an average latency of 1.09 microseconds per tick on commodity CPU hardware.
| Módulo | Ruta | Responsabilidad | README |
|---|---|---|---|
quantum-core |
crates/quantum-core |
Núcleo matemático, álgebra de matrices complejas, Lindblad RK4, CTQW y efecto túnel | README |
market-microstructure |
crates/market-microstructure |
L1/L2 Order Book, Order Flow Imbalance (OFI), VPIN e hidrodinámica de liquidez | README |
quantum-engine |
crates/quantum-engine |
Motor unificado de análisis cuántico, clasificador de fases, SOR y auditor Half-Kelly | README |
market-simulator |
crates/market-simulator |
Simulación estocástica por regímenes, cola FIFO y serialización binaria ultrarrápida | README |
alpaca-streamer |
crates/alpaca-streamer |
Conectividad WebSocket Alpaca v2, supervisor de producción, afinidad HFT y dashboard | README |
The framework is organized as a decoupled Cargo workspace:
Entropiq/
├── Cargo.toml # Workspace manifest
├── LICENSE # MIT License (anthra123x)
├── README.md # Technical documentation
├── crates/
│ ├── quantum-core/ # Mathematical kernel and physical operators
│ │ ├── complex.rs # Stack-allocated Complex64 arithmetic
│ │ ├── matrix.rs # CMatrix<N> hermitian matrix operations
│ │ ├── density.rs # Density Matrix ρ and von Neumann entropy
│ │ ├── lindblad.rs # Runge-Kutta 4 (RK4) Open Quantum System solver
│ │ ├── quantum_walk.rs # 8-level Continuous-Time Quantum Walk (CTQW)
│ │ └── potential.rs # Quantum tunneling and barrier transmission
│ ├── market-microstructure/ # Microstructure metrics and fluid dynamics
│ │ ├── types.rs # Level-1 NBBO Quotes and Trade executions
│ │ ├── book_l2.rs # Stack-allocated Level-2 Depth Book & Deep OFI
│ │ ├── state.rs # Order Flow Imbalance (OFI) tracker with time decay
│ │ └── fluid.rs # Liquidity hydrodynamics (Sound Speed & Mach)
│ ├── quantum-engine/ # Unified state engine, phase transitions & audit
│ │ ├── hamiltonian.rs # Market Hamiltonian builder (with macro Lead-Lag)
│ │ ├── phase.rs # 4-Phase Econophysical transition classifier
│ │ ├── engine.rs # Sub-microsecond tick analysis & L2 pipeline
│ │ ├── sor.rs # Smart Order Router (SOR) & execution policy
│ │ └── audit.rs # O(1) Quantitative Auditor (E[R], Sharpe, Calmar)
│ ├── market-simulator/ # Deterministic feed generation and persistence
│ │ ├── rng.rs # XorShift64 and Box-Muller PRNG
│ │ ├── regimes.rs # Microstructural regime generator
│ │ ├── queue_tracker.rs # High-fidelity FIFO queue position tracker
│ │ ├── binary_feed.rs # 32-byte cache-aligned binary records
│ │ └── binary_disk.rs # Page-aligned binary disk recorder (1.4 GB/s)
│ └── alpaca-streamer/ # Asynchronous real-time market data ingestion
│ ├── affinity.rs # Institutional Linux CPU core pinning & thread isolation
│ ├── config.rs # Defensive credential & environment loader (quote strip, safe fallback)
│ ├── model.rs # Alpaca Market Data v2 models (nanosecond RFC3339 parser)
│ ├── client.rs # Resilient WebSocket client with backoff & O(1) Lead-Lag pull
│ └── bin/supervisor.rs # Production supervisor with HFT core pinning & O(1) telemetry
The Limit Order Book is modeled as an open quantum system coupled to an external stochastic reservoir (retail noise, latency jitter, and macro news). The time evolution of the market density matrix
Where:
-
$\hat{H}$ : Hermitian Hamiltonian representing the internal energetic balance between Bid and Ask potential barriers, modulated by kinetic order flow impulse. - $\hat{L}{\text{dephase}}$: Thermal dephasing jump operator modeling environmental entropy injection ($S{\text{norm}} \to 1.0$).
- $\hat{L}{\text{buy}}, \hat{L}{\text{sell}}$: Dissipative jump operators modeling directional state population shifts upon aggressive trade execution.
- Numerical Integration: Fourth-Order Runge-Kutta (RK4) with trace normalization (
$\text{Tr}(\rho) = 1$ ) and Cauchy-Schwarz positivity preservation ($|\rho_{01}|^2 \le \rho_{00}\rho_{11}$ ).
The degree of informational mixedness and directional order flow toxicity is measured via the exact von Neumann entropy:
Normalized entropy
-
$S_{\text{norm}} \to 1.0$ : Pure thermal noise (isotropic Brownian diffusion). -
$S_{\text{norm}} \ll 0.60$ : Entropy collapse indicating stealth institutional absorption (iceberg execution).
Off-diagonal elements define quantum coherence, measuring cross-spread intent prior to state measurement collapse:
The resting volume depth across the spread functions as a potential barrier
Where
-
$T < 0.70$ : Elastic reflection (rebound from support/resistance). -
$T \ge 0.80$ : Barrier tunneling (breakout through resting liquidity).
The order book is modeled as a compressible fluid medium:
- Liquidity Density:
$\rho_{\text{liq}} = \frac{\text{Total Depth}}{\text{Spread}}$ - Speed of Sound:
$c_s = \sqrt{\frac{K}{\rho_{\text{liq}}}}$ - Mach Number:
$M = \frac{v_{\text{price}}}{c_s}$ - Cavitation Criterion (
$M \ge 1.0$ ): Supersonic flow exceeds the replenishment speed of passive limit orders, triggering fluid cavitation (predicting flash crashes and extreme slippage).
Beyond Top-of-Book quotes, the framework computes Deep Order Flow Imbalance across
The Smart Order Router (SOR) routes execution dynamically across three policy regimes:
-
Superconducting Breakout (
$T \ge 0.75, \text{Bias} > 0.15$ ): Aggressive Taker routing to capture institutional breakouts before spread widening. - Coherent Condensate (Stealth Iceberg Accumulation): Passive Maker posting at BBO to capture the spread with zero taker fees.
-
Fluid Cavitation (
$M \ge 1.0$ ) or Toxic Flow ($\text{VPIN} > 0.70$ ): Immediate emergency cancellation of all resting orders.
Evaluated across 1,000,000 ticks in release mode on Linux x86_64:
| Component / Pipeline | Latency (p50 / p99) | Throughput | Allocation Profile |
|---|---|---|---|
| Core Analytics Pipeline | 181 ns / 280 ns | 5.52M ops/sec | Zero heap allocation |
| Full Physics (Lindblad RK4 + CTQW) | 977 ns / 1.35 µs | 1.02M ops/sec | Zero heap allocation |
| Complete 1M-Tick Pipeline (End-to-End) | 2.80 µs (p50) / 5.17 µs (p99) | 341k - 580k ticks/sec | Zero heap allocation (3.09 MB RSS) |
| Production Supervisor (Live Stream + HFT Pinning) | 5.50 µs (p50) / 9.68 µs (p99) | 50k ticks/sec | 7.84 MB RSS, Cores 0 & 2 Pinned |
| Binary Disk Persistence Write (SSD) | 29.5 ns / rec | 33.9M IOPS (1,035 MB/s) | OS Page-aligned (64 KB) |
| Binary Disk Persistence Read (SSD) | 12.3 ns / rec | 80.9M IOPS (2,471 MB/s) | OS Page-aligned (64 KB) |
Results from a 1,000,000 tick continuous execution backtest across cyclic microstructural regimes:
==========================================================================================
INSTITUTIONAL QUANTITATIVE AUDIT REPORT (1,000,000 TICKS)
==========================================================================================
Initial Capital: $100,000.00 USD
Final Capital: $100,158.83 USD
Total Executions: 7 full market cycles
Win Rate: 100.00% (7/7)
Loss Rate: 0.00%
----------------------------------------------------------------------------------------
R_bar Win: 1.6531%
R_bar Loss: 0.0000%
Mathematical Expectancy: E[R] = 0.016531 (Positive Statistical Edge)
Profit Factor: 99.99
Maximum Drawdown: 0.00%
Sharpe Ratio (Annualized): > 5,000
Calmar Ratio: 99.99
==========================================================================================
Compile and execute test suites and benchmarks:
# Execute full workspace unit test suite (25/25 passing)
cargo test --workspace
# Benchmark Suite: Institutional 4-Layer Performance & Latency Audit (1,000,000 Ticks)
cargo run --release --example benchmark_suite -p quantum-engine
# Benchmark 1: 4-Regime Microstructure Dynamics
cargo run --release --example regime_evaluator -p quantum-engine
# Benchmark 2: Zero-Copy Binary Replay (1,000,000 ticks)
cargo run --release --example binary_replay_benchmark -p quantum-engine
# Benchmark 3: Full Quantitative Audit & Expectancy Backtest
cargo run --release --example quantum_backtest_audit -p quantum-engine
# Benchmark 4: Disk Persistence and Streaming I/O
cargo run --release --example disk_persistence_benchmark -p quantum-engine
# Live Stream Demo (requires ALPACA_ACCESS_TOKEN or API Keys in .env)
cargo run --release --example live_stream_demo -p alpaca-streamer
# Production Real-Time Performance Supervisor (Telemetry, O(1) Memory & Dynamic Kelly)
cargo run --release --bin supervisor -p alpaca-streamerEntropiq includes native containerization and a zero-dependency HTTP server (web.rs) designed for continuous 24/7 cloud deployment on Render:
- Deploy on Render:
- Create a New Web Service connected to your GitHub repository (
anthra123x/Entropiq). - Select Docker runtime (uses the optimized multi-stage
Dockerfile). - Configure Environment Variables in Render:
ALPACA_ACCESS_TOKENorALPACA_API_KEY/ALPACA_API_SECRETALPACA_FEED=equitiesPORT=10000
- Create a New Web Service connected to your GitHub repository (
- 24/7 Keep-Alive (Free Tier):
- Render free tier instances spin down after 15 minutes of inactivity.
- Set up a free monitor (e.g., UptimeRobot or cron-job.org) to ping
https://your-app.onrender.com/healthevery 10 minutes. - This keeps the instance running continuously throughout market hours with zero cost.
- Mobile Terminal Dashboard:
- Access
https://your-app.onrender.com/directly on any mobile or desktop browser to inspect real-time PnL, quantum coherence, entropy, and live risk metrics.
- Access
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2026 anthra123x.