Skip to content

Leakage Safety

Microalpha enforces a strict "no-peek" discipline at every layer of the simulation stack.

Engine invariants

  • Monotonic clocks – the Engine raises LookaheadError if market events arrive out of order. See tests/test_time_ordering.py.
  • t+1 execution – strategies submit intents at time t and executions occur no earlier than the next event. Verified in tests/test_tplus1_execution.py.
  • Fill ordering – brokers acknowledge fills only after the active market event has been processed.

Portfolio guards

Limit order book sequencing

The LimitOrderBook keeps per-level FIFO queues to ensure first-in-first-out fill priority. tests/test_lob_fifo.py and tests/test_lob_cancel_latency.py cover partial fills, cancel acknowledgements, and latency offsets, guaranteeing orders are matched in arrival order without leaking future liquidity.

LOB t+1 semantics

By default, LOB execution enforces t+1 semantics by shifting the reported FillEvent.timestamp to the next available market timestamp while retaining measured latency fields. This preserves the global no-peek invariant. You can disable this behavior per config with:

exec:
  type: lob
  lob_tplus1: false

Walk-forward orchestration

During walk-forward validation, the optimizer only uses in-sample data to select parameters. Each fold records train/test windows in the JSON fold summary, providing an audit trail that the optimizer never touches out-of-sample data (tests/test_walkforward.py).

Statistical inference invariants

  • Sharpe statistics use the same deterministic return stream as performance metrics, with optional HAC adjustments (METRICS_HAC_LAGS) that never peek beyond the evaluated window. tests/test_risk_stats.py asserts IID vs HAC behaviour on synthetic AR(1) data and validates block bootstrap coverage.
  • Reality check bootstraps in walk-forward mode rely on stationary/circular block resampling, seeded from the configuration manifest so repeated runs reproduce identical reality_check_pvalue results.

Together, these invariants provide strong protection against accidentally leaking future information into historical tests.