04 / QuantForge

Python · Event-Driven Simulation · Quant Research

QuantForge

Backtests that can be replayed, hashed, and reproduced.

A deterministic Python event-driven research engine with causal execution rules, Decimal accounting, and reproducible synthetic scenarios, served through FastAPI to an interactive Next.js terminal.

01 — The Research Problem

The Research Problem

A chart of a backtest is not evidence unless the run can be replayed, the timing can be audited, and the ledger does not drift.

  • A signal

    against Information it was not allowed to see

  • One interesting run

    against A run someone else can rebuild

  • Floating-point cash

    against A ledger that stays on its quantum

  • A summary metric

    against The event that produced it

02 — Architecture

Architecture

The terminal never talks to an exchange. It asks a same-origin proxy for an allow-listed route, and FastAPI runs the engine.

  1. Next.js terminal
  2. Allow-listed API proxy
  3. FastAPI
  4. Backtest engine
  5. Analytics
  • GET/api/healthService status
  • GET/api/configBounds, scenarios, strategies
  • POST/api/backtestOne run, with its event trace
  • POST/api/compareStrategies across cost presets
  • GET/api/research-blockEmpirical-study gate

03 — Causal Event Loop

Causal Event Loop

Each timestamp is handled in a fixed phase order. A signal cannot trade on the bar that produced it.

  1. 01

    Bar open

    Only the open is revealed.

  2. 02

    Fill due

    Fill, or expire, at this open.

  3. 03

    Bar complete

    The prior bar's OHLCV is released.

  4. 04

    Signal

    The strategy decision becomes available.

  5. 05

    Submit

    Place, reject, or cancel one order.

  6. 06

    Valuation

    Mark equity at the observed price.

  • A signal is available one hour after its decision bar opens.
  • A submitted order is due one bar later, and fills at that bar's open.
  • If that open is missing, the order expires instead of sliding forward.
  • Strategies read only observations up to the decision bar.

04 — Deterministic Scenarios

Deterministic Scenarios

The terminal's prices are generated. The same seed rebuilds the same bars, and the run's identity does not depend on the wall clock.

uptrenddowntrendsidewaysshockgap

The seed is an integer offset into a fixed wave table. The generator does not draw random numbers.

  • Scenario

    Generator, seed, length, name, and clock.

  • Run

    Assumptions, signals, and the full bar series.

  • Order / fill

    Each order and fill has its own identity.

  • Experiment

    Binds the run identities for the terminal session.

Identities are SHA-256 hashes of canonical JSON.

05 — Decimal Ledger

Decimal Ledger

Cash, quantity, fees, and prices are Decimal values. Risk ratios are the exception: volatility, Sharpe, and Sortino are computed in binary floating point and can be left undefined when the hourly grid is incomplete.

  • Accounting context uses 50 digits of precision.
  • Cash and quantity sit on a 0.00000001 quantum.
  • Buy quantity rounds down. Buy debit and fees round up.
  • Sell proceeds round down after the fee is rounded up.
  • Cash and quantity cannot go negative.
  • Marked equity equals cash plus quantity times the mark price.
  • The ledger reconciles with fills at the end of the run.

The book is long or flat, and all-in. It does not short and it does not use leverage. The default starting cash is 10,000.

Total returnMaximum drawdownAnnualized volatilitySharpe ratioSortino ratio

These are metrics the engine can compute. This page does not report a result for any of them.

06 — Research Terminal

Research Terminal

Six workspaces sit on the same run. The screenshots are from the deployed terminal, on a synthetic uptrend scenario. The numbers in them belong to that generated path.

  • Market

    Candles, volume, and fill markers.

  • Lab

    Strategy, scenario, seed, and cost preset.

  • Performance

    Equity against cash and buy-and-hold, plus drawdown.

  • Replay

    Step through the engine's own events.

  • Compare

    Both strategies across cost presets. Nothing is ranked.

  • System

    Architecture, causal timing, and the research gate.

QuantForge Market workspace showing synthetic hourly candles, a buy marker, and a SYNTHETIC badge.
Market. Synthetic hourly candles for an uptrend scenario. The badge and the side panel say this is not BTCUSDT evidence.
QuantForge Replay workspace on the first bar-open event, with play controls and an event detail panel.
Replay. The stepper walks the engine event list. This frame is the first bar open.
QuantForge Performance workspace comparing strategy, cash, and buy-and-hold equity on a synthetic scenario, with a drawdown panel.
Performance. Equity and drawdown for that same synthetic path, against cash and buy-and-hold. Not a historical result.

07 — Engineering Proof

Engineering Proof

  • Causal timing

    Tests reject a fill that uses a future close, and a signal that acts before it is available.

  • Replay identity

    The same inputs rebuild the same run identity. Changing the fee changes it.

  • Byte-identical demo

    Continuous integration builds the wheel, runs the demo twice, and compares the outputs.

  • Terminal checks

    The web job typechecks, lints, tests, and builds the Next.js terminal.

A numeric pytest total is omitted. The repository's published totals do not currently agree, so this page does not pick one.

  • The deployed terminal runs synthetic scenarios. It is not a historical BTCUSDT study.
  • No return, Sharpe, or drawdown on this page is a market result.
  • The engine does not place live orders.
  • Archive-ingestion code exists and is held behind a research gate. No real-data validation is claimed.