An open API service indexing awesome lists of open source software.

https://github.com/krish567366/submicro-execution-engine

Sub-microsecond bare-metal execution engine with deterministic replay, lock-free order path, and hardware-timestamped latency measurement.
https://github.com/krish567366/submicro-execution-engine

algorithmic-trading backtesting-engine cpp17 deterministic educational hawkes-process hft hft-trading high-frequency-trading kernal-driver lock-free market-making market-microstructure market-microstructure-theory order-book quantitative-finance research simd ultra-low-latency zero-copy

Last synced: about 2 months ago
JSON representation

Sub-microsecond bare-metal execution engine with deterministic replay, lock-free order path, and hardware-timestamped latency measurement.

Awesome Lists containing this project

README

          

```
╔═══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ███████╗██╗ ██╗██████╗ ███╗ ███╗██╗ ██████╗██████╗ ██████╗ ║
║ ██╔════╝██║ ██║██╔══██╗████╗ ████║██║██╔════╝██╔══██╗██╔═══██╗ ║
║ ███████╗██║ ██║██████╔╝██╔████╔██║██║██║ ██████╔╝██║ ██║ ║
║ ╚════██║██║ ██║██╔══██╗██║╚██╔╝██║██║██║ ██╔══██╗██║ ██║ ║
║ ███████║╚██████╔╝██████╔╝██║ ╚═╝ ██║██║╚██████╗██║ ██║╚██████╔╝ ║
║ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ║
║ ║
║ Sub-Microsecond Execution Engine for Algorithmic Trading ║
╚═══════════════════════════════════════════════════════════════════════════════╝
```

🚀 Ultra-Low Latency Trading System


Deterministic, nanosecond-precise execution engine for quantitative trading research

[![Build Status](https://img.shields.io/badge/build-passing-brightgreen?style=for-the-badge)](.)
[![C++17](https://img.shields.io/badge/C%2B%2B-17-blue?style=for-the-badge&logo=cplusplus)](.)
[![Rust](https://img.shields.io/badge/Rust-1.70%2B-orange?style=for-the-badge&logo=rust)](.)
[![License](https://img.shields.io/badge/license-MIT-green?style=for-the-badge)](LICENSE)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen?style=for-the-badge)](.)


🌐 Live Demo
Features
Quick Start
Benchmarks
Architecture
Docs

---

### ⚡ **890ns median latency** | 🎯 **Deterministic replay** | 🔒 **Lock-free architecture** | 🧪 **Research-grade framework**

**[👉 View Interactive Documentation →](https://submicro.krishnabajpai.me/)**

---

## 🎯 What Makes This Special?

> **Built for researchers and systems engineers pushing the boundaries of low-latency execution.**

This isn't just another trading bot. It's a **complete infrastructure** for understanding, measuring, and optimizing execution latency at the **hardware level**.

### 💎 The Problem
Traditional trading systems are black boxes with unpredictable latency, non-deterministic behavior, and poor visibility into where microseconds are lost.

### 🎁 The Solution
A **transparent, deterministic execution engine** that:
- ✅ Achieves **sub-microsecond decision latency** (890ns median)
- ✅ Guarantees **bit-identical replay** for audit and debugging
- ✅ Provides **nanosecond-level instrumentation** at every stage
- ✅ Uses **zero-allocation hot paths** and lock-free data structures
- ✅ Simulates **kernel-bypass networking** (DPDK-style)
- ✅ Implements **institutional-grade logging** and monitoring

⚠️ **Research & Education Only** — Not production-ready. No exchange connectivity included.

## 📊 Performance Snapshot

| 🎯 **Component** | ⚡ **Median** | 📈 **p99** | 🔝 **p99.9** |
|------------------|--------------|-----------|--------------|
| Market Data Ingestion | **87 ns** | 124 ns | 201 ns |
| Signal Extraction (SIMD) | **40 ns** | 48 ns | 67 ns |
| Hawkes Update (Power-Law) | **150 ns** | 189 ns | 234 ns |
| **End-to-End Decision** | **890 ns** | **921 ns** | **1047 ns** |
| Order Serialization | **34 ns** | 41 ns | 58 ns |

**🔬 Measurement Precision:** ±5ns (TSC jitter) | ±17ns (PTP offset)
**🖥️ Test Hardware:** Intel Xeon Platinum 8280 @ 2.7GHz, isolated core, RT kernel

---

## 🔥 Key Features

### ⚡ **Performance**
- 🚀 Sub-microsecond decision latency
- 🔄 Zero-copy data paths
- 🧵 Lock-free SPSC/MPSC queues
- 💾 Cache-aligned data structures
- 🎯 SIMD-optimized computations (AVX-512)

### 🎯 **Determinism**
- 🔁 Bit-identical replay guarantees
- 📝 Event-driven scheduling
- 🎲 Fixed RNG seeds
- 🔒 Pre-allocated memory pools
- ⏱️ TSC-level timestamp precision

### 🏗️ **Architecture**
- 🌐 Kernel-bypass NIC simulation
- 🧠 Multivariate Hawkes process
- 📊 Avellaneda-Stoikov market making
- 🛡️ Adaptive risk management
- 🔌 C++/Rust FFI integration

### 📈 **Observability**
- 📊 Real-time metrics dashboard
- 📝 Multi-layer audit logging
- 🔍 SHA-256 replay verification
- ⏱️ Nanosecond-level tracing
- 📉 Latency breakdown analysis

---

## 🎬 Quick Start

**Get running in 60 seconds:**

```bash
# 1️⃣ Clone the repository
git clone https://github.com/krish567366/submicro-execution-engine.git
cd submicro-execution-engine

# 2️⃣ Build the system (automatic optimization flags)
./build_all.sh

# 3️⃣ Run deterministic backtest
./run_backtest.py

# 4️⃣ View results
python3 verify_latency.py
open dashboard/index.html # Interactive metrics dashboard
```

📺 Expected Output (click to expand)

```
=== Low-Latency Trading System ===
✓ Market data ingestion: 87ns median
✓ Signal extraction: 40ns median
✓ Hawkes update: 150ns median
✓ Decision latency: 890ns median

--- Cycle: 1000 ---
Mid Price: $100.05
Position: 250
Active Quotes: Bid=100.04 Ask=100.06 Spread=2.00 bps
Hawkes: Buy=12.456 Sell=11.234 Imbalance=0.052
Regime: NORMAL (multiplier=1.0)
Last Cycle Latency: 847 ns (0.847 µs)
✓ Determinism verified: SHA-256 match
```

---

## 🏛️ Architecture Overview

```
┌─────────────────────────────────────────────────────────────────────────────┐
│ 📡 Market Data Feed (Simulated) │
│ Kernel-Bypass NIC • Zero-Copy DMA Transfer │
└───────────────────────────────┬─────────────────────────────────────────────┘
│ 87ns median

┌─────────────────────────────────────────────────────────────────────────────┐
│ 🔄 Lock-Free Ring Buffer (SPSC) │
│ Power-of-2 Size • Cache-Line Aligned • No Allocations │
└───────────────────────────────┬─────────────────────────────────────────────┘
│ O(1) operations

┌─────────────────────────────────────────────────────────────────────────────┐
│ 📖 Order Book Reconstruction │
│ Price-Level Aggregation • L2 Depth Tracking │
└───────────────────────────────┬─────────────────────────────────────────────┘

┌───────────────┴───────────────┐
▼ ▼
┌─────────────────────────────┐ ┌─────────────────────────────────────────┐
│ 🔥 Hawkes Process Engine │ │ 📊 Microstructure Features │
│ • Self/Cross Excitation │ │ • Deep OFI (10 levels) │
│ • Power-Law Kernel │ │ • Order Book Imbalance │
│ • Buy/Sell Intensity │ │ • Flow Toxicity (Kyle λ) │
└──────────────┬────────────────┘ └──────────────┬──────────────────────────┘
│ 150ns median │ 40ns (SIMD)
└───────────────┬───────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│ 🧠 FPGA DNN Inference (Simulated) │
│ 12 Features → 8 Hidden → 3 Outputs • 400ns Fixed │
└───────────────────────────────┬─────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────────────────┐
│ 💰 Avellaneda-Stoikov Market Making Strategy │
│ HJB Equation • Inventory Skew • Latency-Aware Pricing │
└───────────────────────────────┬─────────────────────────────────────────────┘
│ 890ns E2E

┌─────────────────────────────────────────────────────────────────────────────┐
│ 🛡️ Risk Control (Pre-Trade + Kill-Switch) │
│ Position Limits • Regime Detection • Atomic Checks │
└───────────────────────────────┬─────────────────────────────────────────────┘
│ 34ns serialization

┌─────────────────────────────────────────────────────────────────────────────┐
│ 📤 Order Submission │
│ Pre-Serialized Orders • Zero Copy │
└─────────────────────────────────────────────────────────────────────────────┘
```

> **See [`ARCHITECTURE.md`](ARCHITECTURE.md) for detailed component documentation**

---

## 🎯 Determinism & Reproducibility

One of the system's **core guarantees** is bit-identical replay capability:

✅ **Fixed RNG seeds** — Deterministic random number generation
✅ **Event-driven scheduling** — No wall-clock dependencies
✅ **Pre-allocated memory** — No allocator non-determinism
✅ **Timestamp-ordered events** — Consistent processing order

### Verification

```bash
# Run backtest
./run_backtest.py

# Verify deterministic replay
cd logs
sha256sum -c MANIFEST.sha256
✓ strategy_trace.log: OK
✓ order_flow.log: OK
✓ latency_metrics.log: OK
```

**TSC-level reproducibility proof:** See `logs/strategy_trace.log`

---

## 📚 Complete Documentation

| 📄 Document | Description |
|------------|-------------|
| [`ARCHITECTURE.md`](ARCHITECTURE.md) | Order path, cache layout, thread model |
| [`BENCHMARK_GUIDE.md`](BENCHMARK_GUIDE.md) | Latency measurement methodology |
| [`LATENCY_BUDGET.md`](LATENCY_BUDGET.md) | Component-level breakdown |
| [`INSTITUTIONAL_LOGGING_COMPARISON.md`](INSTITUTIONAL_LOGGING_COMPARISON.md) | Audit-grade logging |
| [`PRODUCTION_READINESS.md`](PRODUCTION_READINESS.md) | Deployment considerations |
| `logs/README.md` | Multi-layer timestamp verification |

---

## 🤝 Contributing

We welcome contributions! Here's how to get started:

🐛 Report a Bug

Open an issue with:
- System configuration (CPU, OS, compiler)
- Reproducible example
- Expected vs actual behavior
- Relevant logs

💡 Propose a Feature

1. Check existing issues/PRs
2. Open an issue describing the feature
3. Discuss implementation approach
4. Submit a PR with tests

🔧 Submit a Pull Request

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes with tests
4. Ensure `ctest` and `cargo test` pass
5. Commit with clear messages
6. Push and open a PR

### Development Guidelines

- **Code style:** Follow existing patterns (run `clang-format`)
- **Tests:** Add tests for new features
- **Benchmarks:** Measure latency impact
- **Documentation:** Update relevant markdown files

---

## 🌟 Star History

[![Star History Chart](https://api.star-history.com/svg?repos=krish567366/submicro-execution-engine&type=Date)](https://star-history.com/#krish567366/submicro-execution-engine&Date)

---

## 📖 Academic References

Click to expand bibliography

### Hawkes Processes
1. **Hawkes, A. G. (1971).** "Specular Point Processes" *Biometrika*
2. **Bacry, E., et al. (2015).** "Hawkes Processes in Finance" *Market Microstructure and Liquidity*

### Market Making
3. **Avellaneda, M., & Stoikov, S. (2008).** "High-frequency trading in a limit order book" *Quantitative Finance*
4. **Guéant, O., et al. (2013).** "Dealing with the inventory risk" *Mathematics and Financial Economics*

### Market Microstructure
5. **Cartea, Á., et al. (2015).** "Algorithmic and High-Frequency Trading" *Cambridge University Press*
6. **Lehalle, C.-A., & Laruelle, S. (2018).** "Market Microstructure in Practice" *World Scientific*
7. **Easley, D., et al. (2012).** "Flow Toxicity and Liquidity in a High-Frequency World" *Review of Financial Studies*

### System Design
8. **Nygren, E. (2015).** "Linux Kernel Development for Real-Time Systems" *O'Reilly*
9. **Gregg, B. (2013).** "Systems Performance: Enterprise and the Cloud" *Prentice Hall*

---

## ⚠️ Important Disclaimers

### 🚨 **RESEARCH & EDUCATION ONLY** 🚨

This system is **NOT**:
- ❌ Production-ready trading software
- ❌ Connected to any exchanges
- ❌ Financial advice or recommendation
- ❌ Guaranteed to be profitable

This system **IS**:
- ✅ A research framework
- ✅ An educational tool
- ✅ A latency benchmarking platform
- ✅ A deterministic execution skeleton

**Real production HFT requires:**
- Hardware FPGA acceleration (Xilinx, Altera)
- True kernel-bypass (DPDK, Solarflare OpenOnload)
- Exchange connectivity (FIX, proprietary protocols)
- Compliance systems (kill-switches, position limits)
- Risk management infrastructure
- Extensive testing and regulatory approval

**⚖️ Legal:** No warranty. Use at your own risk. See LICENSE for details.

---

## 📧 Contact & Community

**Questions? Ideas? Collaboration?**

[![GitHub Issues](https://img.shields.io/badge/Issues-Open-blue?style=for-the-badge&logo=github)](https://github.com/krish567366/submicro-execution-engine/issues)
[![Discussions](https://img.shields.io/badge/Discussions-Join-green?style=for-the-badge&logo=github)](https://github.com/krish567366/submicro-execution-engine/discussions)
[![Email](https://img.shields.io/badge/Email-Contact-red?style=for-the-badge&logo=gmail)](mailto:your-email@example.com)

### Related Projects

- [DPDK](https://www.dpdk.org/) — Data Plane Development Kit
- [Solarflare OpenOnload](https://www.xilinx.com/products/design-tools/software-zone/openonload.html) — Kernel-bypass networking
- [Folly](https://github.com/facebook/folly) — Facebook's lock-free structures
- [QuantLib](https://www.quantlib.org/) — Quantitative finance library

---

## 🚀 **Built for Speed. Designed for Reliability. Optimized for Discovery.**

### If you find this useful, please ⭐ **star the repository** ⭐

Made with ❤️ by quantitative systems engineers

---

**📊 Trading • ⚡ Low-Latency • 🔬 Research • 💻 Open Source**

---

## 📝 License

MIT License - See [LICENSE](LICENSE) file for details

Copyright (c) 2025 [Your Name]

---