Verace Parity
A statistical-arbitrage pairs-trading engine combining cointegration, Ornstein-Uhlenbeck z-score barriers and drawdown-constrained position sizing.
- Cointegrated spread: Hedged combination of two prices that reverts to its mean
- Spread z-score: Spread standardised by its OU mean and volatility
- Spread entry: Opens a long or short spread position
- Entry barrier at 2.5: Symmetric barrier the z-score must cross
Overview
Verace Parity is the lab's statistical-arbitrage system for pairs and basket trading under hard drawdown rules. It asks whether a portfolio of cointegrated instruments can be traded inside a fixed loss envelope: a daily-loss cap, a trailing-drawdown cap near 4 to 5%, and a profit target of 8%. Two assets are cointegrated when a linear combination of their prices is stationary even though each price wanders. Verace Parity takes that combination, called the spread, and acts on it only when it sits far from its long-run mean.
Every part of the system follows one pipeline. A hedge ratio is estimated to form the spread. The spread is fitted as an Ornstein-Uhlenbeck (OU) process , a continuous-time mean-reverting model. The spread is then standardised to a z-score, and symmetric barriers turn it into entry, take-profit and stop decisions. A risk layer sizes each position and halts on drawdown. Two parts implement this pipeline. The first is a pairwise research implementation. The second extends it with Johansen basket cointegration, an order-flow shock filter, a drawdown-barrier sizer and a C++ multi-account mirror.
Both parts are Python packages with a web API, a WebSocket telemetry stream, a browser dashboard and a command-line tool. The second part adds C++ headers. The lab's records report a walk-forward backtest over 500 bars with a return of +9.92%, maximum drawdown of -1.34%, Sharpe ratio 3.84 and Sortino ratio 6.12. In the first part, the backtest entry points run on synthetic preset pairs. The technical reference states a 92.4% win rate and a 0.24 ms mirror latency. Several records do not support those figures, as the findings explain.
Status: the strategy pipeline, risk layer, backtesters and dashboards are implemented, and the documentation reports test suites passing 6 of 6 and 5 of 5. Order execution is implemented as broker connectors that fall back to simulated results when no terminal is present. The system is configured for 15 accounts, and nothing shows that any such accounts exist. Nothing shows whether any connector reached a live or test account. The only recorded performance figures come from backtests, mostly on synthetic data. Out-of-sample evaluation on real data, with costs, is not recorded.
Status
Prototype. Both parts contain working code with unit tests and backtesters, but the only recorded results are a single walk-forward figure set and documentation claims, mostly on synthetic data.
Simulator
A made-up series, and a rule that fires when a point lies far from the average of the points before it. Set how far, and how many points it looks back over.
- synthetic data: not a record of any market
- score: distance from the average, in units of the spread
- Times the rule fired
- 21
- Points outside the band
- 27%
- Longest stretch without firing
- 43 points
- The series
- Synthetic
Narrow the band and the rule fires on noise; widen it and it misses moves. A longer window makes the band slower to follow.
This simulator is an illustration of the principle, with made-up numbers. It does not run the lab's code or show the lab's data, and nothing in it is a measurement.
Architecture
Cointegration engine
Estimates the OLS hedge ratio between two instruments, forms the residual spread and runs a simplified Dickey-Fuller stationarity test to decide whether a pair is tradeable.
Ornstein-Uhlenbeck engine
Fits the OU process to a spread series and returns its mean, reversion speed, equilibrium volatility and half-life. It also gives a verdict on whether the spread reverts fast enough to trade.
Barrier filter
Maps the spread z-score and the current position to one action: long spread, short spread, close for profit, close at stop, or hold. It also returns a confidence value and a reason.
Risk guardian
Tracks equity and peak equity, sizes lots by fixed risk percentage, and enforces hard daily-loss and trailing-drawdown halts. It also tracks a two-phase evaluation status.
Walk-forward backtester
Re-estimates the hedge ratio and OU parameters on a rolling window at every bar, applies the barrier rules, and reports PnL, drawdown, Sharpe, Sortino and a pass flag.
Johansen VECM engine
In the second part, solves the Johansen reduced-rank problem across a basket of up to five instruments and returns stationary basket weights. VECM stands for vector error-correction model.
Order-flow shock blocker
Computes a standardised order-flow imbalance from the top of the order book. It freezes new entries when that imbalance signals an abrupt move.
Drawdown barrier sizer
Scales a Merton-style allocation fraction toward zero as trailing drawdown approaches its hard cap. The Python and C++ versions of this sizer differ in detail.
Multi-account mirror
Replicates one signal across a configured list of accounts, sizes each by its own drawdown state, and skips accounts whose breakers have tripped. It is implemented in Python and as a C++ header with an OpenMP parallel loop.
Real-data backtester
In the second part, runs paired and basket backtests on downloaded market data, which is cached as CSV, with transaction costs and leverage.
Broker connectors
Execution bridges for a broker terminal package and a cloud order-routing service. Each returns simulated balances and order tickets when no terminal or token is available.
API, dashboard and CLI
A FastAPI service exposes health, telemetry, toggle, backtest and order endpoints, plus a WebSocket stream. A browser dashboard charts the z-score against its barrier bands, and a command-line tool exposes scan, backtest and trading-loop commands.
Implementation
Mechanisms as they are implemented in the source code, with the constants the code uses.
- Rolling hedge ratio and spread z-score
- At each bar the first part's backtester fits and by OLS on the window . It then fits the OU parameters on the resulting spread and sets . The second part's real-data backtester instead uses over a 150-bar window and standardises by the window mean and standard deviation.
- Simplified Dickey-Fuller test
- After the OLS step , the residual spread is regressed as with a single lag. The t-statistic is compared with fixed critical values of -3.46, -2.88 and -2.57 at the 1%, 5% and 10% levels, set for samples of about 200, and p-values follow a step function. The technical reference calls this an augmented Dickey-Fuller test, but the code uses no augmentation lags.
- OU exact-discretisation calibration
- The spread is regressed as by OLS, with residual variance clamped at 1e-12 or higher. The code then sets , , , and . It needs at least 10 observations; the degenerate fallback sets and a half-life of 69.3.
- Mean-reversion gate
- The OU engine labels a spread tradeable when its half-life lies between 1 and 120 bars and . The configuration applies a stricter screen: lookback of 200 bars, rejection of pairs with half-life above 80 bars, and a Dickey-Fuller p-value of at most 0.01.
- Three-barrier z-score state machine
- The system opens a long spread position when and a short spread position when . It takes profit when and stops out when in the adverse direction. Long-spread PnL is . The same constants appear in both Python parts, in the C++ filter header and in the API request schema defaults.
- Fixed-fractional lot sizing
- Risk capital is the balance times
max_risk_per_trade_pctdivided by 100, with 0.5% as the example value. This is divided by stop distance times point value (default 10) to give lots, which are clamped to the range 0.01 to 20. In the backtester the stop distance is with a minimum of 5e-4. The technical reference describes ATR-based sizing, which the code does not implement. - Drawdown circuit breaker
- Trading halts when reaches the daily-loss limit or reaches the total-loss limit, with example limits of 3.5% and 4.5%. A daily halt clears at day rollover, while a trailing-drawdown halt stays in place.
- Walk-forward PnL and pass rule
- Per bar, position PnL is . In the first part a run passes when profit is at least 8% and maximum drawdown is at most 4.5%. The second part's real-data backtester uses 8% and 4.2%.
- Synthetic cointegrated pair generator
- Leg B follows a geometric random walk. The spread is a discrete OU step with defaults and , and leg A is (with ) plus the spread plus noise. Presets set , and per pair, and the trading-loop simulator uses with leg B returns drawn from .
- Johansen reduced-rank cointegration
- and are the residuals of and on lagged differences, used raw when there is one lag, and . The generalised eigenproblem is solved with
scipy.linalg.eigand the eigenvalues are sorted in descending order. The top eigenvector, normalised to the first asset, gives the stationary basket weights. - Moment-based OU speed estimate
- The second part estimates , clipped to , with half-life in bars. The code labels the half-life in minutes, but its true unit depends on the bar size.
- Order-flow imbalance blocker
- Following the Cont-Kukanov-Stoikov definition, is the bid term minus the ask term. The bid term contributes the new size if the bid rose, the size change if it was unchanged, and minus the previous size if it fell; the ask term mirrors this. The series is standardised, and new entries are frozen when and no position is open.
- Drawdown-barrier allocation fraction
- The fraction is with , where the slack is a fraction, is 4.2%, , and . The C++ header multiplies the fractional slack by 100 inside the exponent and clamps the result to . The Python sizer scales the Merton fraction by 0.005, caps it at 12% and uses the slack expressed in percent, which applies the same factor of 100. The code calls this an HJB (Hamilton-Jacobi-Bellman) controller, but it solves no partial differential equation.
- Per-account mirror fan-out
- One signal is replicated over all configured accounts. Each account is sized by its own drawdown-dependent fraction and skipped when its drawdown or daily-loss breaker has tripped, with a 4.20% drawdown halt. The asynchronous version uses
asyncio.gatherover non-halted accounts, and each dispatch is simulated as a 1 ms sleep returning FILLED with a fixed 1.2 ms latency. - C++ fan-out benchmark
master_bot.cpppasses a fixed signal of throughOUJumpFilterand the configured account mirror 1000 times and prints the mean fan-out latency. The mirror loops over accounts with an OpenMP parallel-for.- Real-data backtest settings
- Paired backtests on downloaded 15-minute and daily data use rolling OLS spread z-scores with drawdown-barrier sizing, a cost of 1 basis point and 10x leverage. The macro basket backtest applies a fixed per-trade gain instead of simulating price moves.
- Correlated synthetic order-book feed
- Independent shocks are multiplied by the transposed Cholesky factor of a fixed correlation matrix, with equity-index correlations of 0.84 to 0.94 and yield correlations of -0.5 to -0.65. Prices compound as across five instruments, and a toy order book drives the telemetry endpoints. The trading loop's own tick generator uses .
- Broker connector with simulation fallback
- When the broker terminal package is unavailable or unconnected, every connector method returns simulated account data and random order tickets, so the system runs without a broker. The cloud bridge sends market orders only when an access-token environment variable is set and otherwise returns a message that a bridge is required. One further connector is a stub.
Results
From the lab's own experiments and records. They have not been independently replicated.
Walk-forward backtest over 500 bars
The lab's records report a return of +9.92%, maximum drawdown of -1.34%, Sharpe ratio 3.84 and Sortino ratio 6.12, with the pass criterion met. The first part's backtest entry points generate synthetic preset pairs, so this result does not establish performance on market data.
Stated win rate has no recorded run
The technical reference of both parts states a 92.4% win rate for the 2.5 sigma barrier. No record shows the experiment, data or trade count behind that figure.
Mirror latency figure measures a fixed signal
The technical reference states a 0.24 ms fan-out latency. The C++ benchmark that measures fan-out repeats a fixed signal 1000 times through an in-memory mirror, and the Python asynchronous mirror reports a fixed simulated 1.2 ms latency, so neither figure measures order execution.
Command-line backtest prints hardcoded figures
The test suite and code show that the second part's command-line backtest command prints fixed numbers without simulating anything.
Macro basket backtest assumes a fixed gain
The second part's real-data backtester applies a fixed per-trade gain in its Johansen basket mode, so that mode's results reflect the assumption rather than market data.
Documentation and code disagree in several places
The technical reference describes an augmented Dickey-Fuller test, exact maximum-likelihood OU fitting, ATR lot sizing and a basket half-life target under 12 minutes. The code uses a single-lag Dickey-Fuller regression with step-function p-values, an OLS AR(1) fit and fixed-fractional sizing, and measures half-life in bars.
HJB controller is a closed-form heuristic
The drawdown sizer is named after the Hamilton-Jacobi-Bellman equation, but the code computes a Merton fraction times an exponential barrier and solves no control problem. Its Python and C++ versions differ in scaling and caps.
Unit tests pass in both parts
The documentation reports 6 of 6 tests passing in the first part and 5 of 5 in the second. The tests cover cointegration, OU fitting, barrier signals, risk limits, the Johansen solver, the order-flow blocker and the multi-account manager.
Concepts
- Cointegration
- Two or more non-stationary price series are cointegrated when some linear combination of them is stationary. That combination is the spread the system trades.
- Hedge ratio
- The coefficient in that makes the spread stationary. The system estimates it by OLS on a rolling window.
- Ornstein-Uhlenbeck process
- A continuous-time mean-reverting stochastic process, . Here sets the speed of reversion toward the mean .
- Half-life of mean reversion
- The expected time for a deviation from the mean to halve, . The system uses it to reject spreads that revert too slowly.
- Equilibrium volatility
- The stationary standard deviation of the OU process, . The system uses it to standardise the spread into a z-score.
- Dickey-Fuller test
- A unit-root test that regresses the change of a series on its lagged level. A strongly negative t-statistic indicates stationarity.
- Johansen procedure
- A multivariate cointegration method that finds stationary combinations of several series from a generalised eigenvalue problem on residual moment matrices.
- Barrier rule
- A decision rule with fixed thresholds on the z-score: enter at 2.5, take profit within 0.15 of zero, stop at 3.8.
- Order-flow imbalance
- A signed measure of net buying or selling pressure computed from changes in the best bid and ask prices and sizes. The second part uses it to detect abrupt moves.
- Merton fraction
- The allocation for an asset with excess return , volatility and risk aversion . The second part uses it as the base size before applying the drawdown barrier.
- Drawdown barrier
- A multiplicative gate , where slack is the remaining distance between trailing drawdown and its hard cap written as a fraction, that shrinks position size to zero as trailing drawdown approaches the cap.
- Trailing drawdown
- The fall of equity from its running peak, as a fraction of that peak. Both parts use it as a hard halt condition.
- Walk-forward backtest
- A backtest that re-estimates all model parameters at each step using only past data, so that no future information enters a decision.
- Two-phase evaluation rule
- The pass criterion that both backtesters encode: a profit target of 8% reached without breaching a drawdown cap of 4.5% in the first part or 4.2% in the second.
- Simulation fallback
- A design in which every execution connector returns simulated results when no broker connection is present, so the whole system runs offline.
About this page
Written from the lab's own documents and source code. Figures and results are the lab's measurements as it recorded them at the time, and have not been independently replicated.
Market results here are backtests and logs kept by the lab. Nothing on this page is financial advice.
Published under the PolyForm Noncommercial License 1.0.0: free for noncommercial use.