Skip to content

About

Institutional CME futures trading framework for ES, NQ, MES, MNQ, CL & GC. Features continuous contract rollover management, real-time order flow footprint (CVD), Anchored VWAP standard deviation bands, and IBKR bracket order execution.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

⚡ QuantFutures Engine — Institutional CME Futures Execution Framework

Python 3.11+ Market Analytics VWAP Broker License: MIT

A high-performance algorithmic trading and execution framework engineered for CME equities and commodity futures (ES, MES, NQ, MNQ, CL, GC, YM). Features automated continuous contract rollover management, real-time order flow footprint analytics (CVD), multi-timeframe Anchored VWAP standard deviation bands, and institutional bracket order execution via Interactive Brokers (IBKR).

┌────────────────────────────────────────────────────────────────────────────────┐
│  ⚡ QuantFutures Terminal — Real-Time CME Institutional Order Router           │
│  Active Contracts: ES, NQ, MES, MNQ, CL, GC, YM | Gateway: Port 7497 / 7496    │
├────────────────────────────────────────────────────────────────────────────────┤
│  📅 Continuous Contract: Front Month Active (ESZ6 | Rollover Protocol: ARMED) │
│  🔬 Order Flow: Net CVD +2,400 contracts (BULLISH_AGGRESSION | VPOC: $5862.50) │
│  📊 Anchored VWAP: $5860.49 (+2 Sigma: $5868.93 | -2 Sigma: $5852.05)          │
│  🛡️  Bracket Execution: 2x ES BUY @ $5865.00 (Risk: $400.00 | Target: $800.00)│
└────────────────────────────────────────────────────────────────────────────────┘

💼 Need Custom Futures Algorithms, Order Flow Terminals, or Broker Adapters?

I build low-latency futures trading software, multi-timeframe VWAP engines, CME execution routers, and institutional risk systems.


📑 Table of Contents

  1. Key Architectural Highlights
  2. End-to-End Futures Execution Workflow
  3. Supported CME & NYMEX Contracts
  4. Continuous Contract & Rollover Management
  5. Order Flow Footprint & Cumulative Volume Delta
  6. Anchored VWAP & Volatility Bands
  7. Institutional Bracket Orders & Margin Guardian
  8. Interactive Brokers TWS / Gateway Configuration
  9. Installation & Quickstart
  10. Explore Connected Quantitative Projects
  11. Disclaimer

🚀 Key Architectural Highlights

  • Automated Continuous Contract Stitching: Automatically detects delivery cycle transitions (HMUZ quarterly codes) and switches active quotes to the highest-volume front-month contract.
  • Order Flow Footprint Engine: Tracks second-by-second diagonal bid/ask imbalances ($\ge 300%$), identifies institutional absorption, and computes real-time Cumulative Volume Delta (CVD).
  • Anchored VWAP Variance Bands: Calculates rolling and session-anchored Volume-Weighted Average Price with dynamic $\pm 1\sigma$ and $\pm 2\sigma$ standard deviation volatility bands.
  • Synchronized Bracket Order Router: Generates native 3-way parent/child bracket orders (Entry Limit, Stop-Loss Market, and Take-Profit Limit) with automatic OCO cancellation.
  • Futures Margin & Circuit Breaker Guardian: Enforces pre-trade initial margin cushion checks, daily loss limits, and emergency news volatility pauses.

🏛️ End-to-End Futures Execution Workflow

flowchart TD
    subgraph Market Ingestion
        A["Interactive Brokers TWS / CME Globex"] --> B["Continuous Contract Manager (Front-Month Detection)"]
    end

    subgraph Quantitative Analytics Core
        B --> C["Order Flow Engine (CVD & Footprint Imbalances)"]
        B --> D["Anchored VWAP & Standard Deviation Bands"]
        B --> E["Volume Profile Point of Control (VPOC)"]
    end

    subgraph Signal & Strategy Synthesis
        C --> F{"Delta Divergence & Absorption Detected?"}
        D --> G{"Price at VWAP Mean Reversion or Breakout Band?"}
        F -- Yes --> H["Construct Long / Short Tactical Entry Signal"]
        G -- Yes --> H
    end

    subgraph Risk & Execution Gate
        H --> I["Futures Margin Guardian (Utilization Check & Daily Loss Limit)"]
        I -->|Approved| J["Bracket Order Router (Entry + OCO Stop/TP)"]
        I -->|Breach| K["[REJECT ORDER] Halt Outbound Submission"]
        J --> L["IBKR Native Bracket Order Routing (Port 7497/7496)"]
        L --> M["Real-Time Fill Reconciliation & Position Ledger"]
    end
Loading

📊 Supported CME & NYMEX Contracts

Contract Underlying Asset Exchange Tick Size Tick Value Initial Margin (Est.) Roll Cycle
ES E-mini S&P 500 CME 0.25 pt $12.50 $12,650 HMUZ (Mar, Jun, Sep, Dec)
MES Micro E-mini S&P 500 CME 0.25 pt $1.25 $1,265 HMUZ (Mar, Jun, Sep, Dec)
NQ E-mini Nasdaq 100 CME 0.25 pt $5.00 $17,600 HMUZ (Mar, Jun, Sep, Dec)
MNQ Micro E-mini Nasdaq 100 CME 0.25 pt $0.50 $1,760 HMUZ (Mar, Jun, Sep, Dec)
CL Light Sweet Crude Oil NYMEX $0.01 $10.00 $6,710 Monthly (FGHJKMNQUVXZ)
GC Gold COMEX COMEX $0.10 $10.00 $9,350 GJMQVZ
YM E-mini Dow Jones ($5) CBOT 1.00 pt $5.00 $9,900 HMUZ (Mar, Jun, Sep, Dec)

📅 Continuous Contract & Rollover Management

Futures contracts expire periodically. Holding past expiration risks forced cash settlement or physical delivery notices.

Automated Rollover Logic:

  • Calendar Inspection: Triggers evaluation 8 calendar days prior to contract expiration.
  • Volume Crossover Protocol: Initiates calendar roll when secondary contract volume exceeds the current front-month volume: $$\text{Volume}{\text{Next}} > \text{Volume}{\text{Front}}$$
  • Automated Stitching: Normalizes historical backtesting bars to eliminate artificial price gaps across rollover events.

🔬 Order Flow Footprint & Cumulative Volume Delta

Tracks aggressive buying and selling pressure inside each price bar:

$$\text{Delta}_t = \text{Volume}_{\text{Ask}} - \text{Volume}_{\text{Bid}}$$ $$\text{CVD}_T = \sum_{t=1}^T \text{Delta}_t$$
  • Diagonal Bid/Ask Imbalance: Flags levels where aggressive market orders exceed limit absorption by $\ge 300%$ ($3.0\times$).
  • Institutional Absorption: Detects high volume clusters ($>5,000$ contracts) with minimal price slippage, signaling passive institutional accumulation or distribution.

📈 Anchored VWAP & Volatility Bands

$$\text{VWAP} = \frac{\sum (P_{\text{typical}} \times V)}{\sum V}$$ $$\sigma = \sqrt{\frac{\sum V \times (P_{\text{typical}} - \text{VWAP})^2}{\sum V}}$$
  • Band 1 ($\text{VWAP} \pm 1\sigma$): Represents $68.2%$ of standard volume-weighted distribution.
  • Band 2 ($\text{VWAP} \pm 2\sigma$): Represents $95.4%$ distribution — statistical extreme overbought/oversold boundaries.

🛡️ Institutional Bracket Orders & Margin Guardian

Every futures order is submitted as a synchronized 3-legged structure:

  1. Parent Order: Limit or Market Entry.
  2. Stop Loss (Child 1): Stop-market order with defined tick risk.
  3. Profit Target (Child 2): Limit order tied to Stop Loss via OCO (One-Cancels-Other) logic.

Pre-Trade Margin Guardian:

  • Enforces maximum margin utilization ceiling (default $65%$).
  • Enforces daily realized loss limit (default $-$1,500.00$).
  • Rejects oversized orders prior to broker submission.

⚙️ Interactive Brokers TWS / Gateway Configuration

  1. Open TWS and log in to Paper or Live mode.
  2. Navigate to File $\rightarrow$ Global Configuration $\rightarrow$ API $\rightarrow$ Settings.
  3. Verify the following parameters:
    • ✅ Enable ActiveX and Socket Clients
    • Socket Port: 7497 (Paper Trading) or 7496 (Live Trading)
    • Uncheck ❌ Read-Only API
    • Check ✅ Allow connections from localhost only (or add 127.0.0.1 to Trusted IPs)
  4. Click Apply and OK.

Interactive Brokers TWS API Settings Configuration


🛠️ Installation & Quickstart

  1. Clone repository:

    git clone https://github.com/jahanzaib-codes/QuantFutures-Engine.git
    cd QuantFutures-Engine
  2. Setup virtual environment & install requirements:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    pip install -r requirements.txt
  3. Configure Environment:

    cp .env.example .env
  4. Launch Automated Diagnostic Suite:

    python main.py --mode demo

⭐ Explore Connected Quantitative Projects


⚠️ Disclaimer

QuantFutures Engine is an open-source software platform developed for quantitative research, algorithmic strategy development, and educational purposes. Futures trading involves substantial financial leverage and high risk of capital loss. Thoroughly paper-trade strategies before committing live capital.


Maintained by Jahanzaib (@jahanzaib-codes)

About

Institutional CME futures trading framework for ES, NQ, MES, MNQ, CL & GC. Features continuous contract rollover management, real-time order flow footprint (CVD), Anchored VWAP standard deviation bands, and IBKR bracket order execution.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages