Skip to main content
Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com

Multi-Strategy Operations

Run a portfolio of independent strategies, each with its own risk budget and Engine instance. The StrategyBook provides aggregate analytics, pairwise correlation tracking, rebalancing recommendations, and intervention alerts. The reconciliation module detects discrepancies between engine state and exchange positions.

Strategy Book

Manage multiple engines with isolated risk budgets, rolling Sharpe, and drawdown tracking.

Correlation Monitoring

Pairwise Pearson correlation of PnL changes across strategies.

Capital Rebalancing

Equal, risk-parity, and performance-based budget allocation.

Position Reconciliation

Compare engine vs exchange positions and flag breaks by severity.

Multi-Strategy Book

The StrategyBook holds references to multiple Engine instances and provides oversight, analytics, and rebalancing. It does not own engines. Each strategy is responsible for its own execution.

Quick Start

Constructor


add_strategy

Add a strategy to the book.
If risk_budget is None, all existing strategies’ budgets are redistributed equally (including the new one). If a specific budget is provided, the total across all strategies must not exceed 1.0.

remove_strategy

Remove a strategy from the book. Its PnL history and equity curve are also discarded.

update

Record PnL snapshots for each active strategy. Call this once per cycle to build up the equity curves used for correlation and Sharpe computation.
Queries each strategy’s engine via engine.status() to read current total_pnl. Updates rolling Sharpe, drawdown, and the combined portfolio equity curve.

report

Generate a multi-strategy report with per-strategy metrics, pairwise PnL correlations, and aggregate portfolio-level analytics.

MultiStrategyReport

StrategySlot

StrategyCorrelation

rebalance_capital

Compute target risk budgets for each active strategy.

Rebalancing Methods

Returns

dict[str, float] mapping strategy name to target risk budget (summing to 1.0 across active strategies).

needs_intervention

Return names of strategies that breach risk thresholds.

Returns

list[str] of strategy names that need attention.
A strategy is flagged if its drawdown exceeds max_drawdown OR its Sharpe falls below min_sharpe (once enough history has accumulated). Both conditions are checked independently.

strategy_pipeline

Return a pipeline function that records metrics for the named strategy inside hz.run().

Injected into ctx.params


Position Reconciliation

Detect discrepancies between the engine’s internal position tracking and the exchange’s reported positions. Flags missing positions, size mismatches, and side mismatches with severity levels.

How Reconciliation Works

1

Snapshot engine positions

Queries engine.positions() and aggregates by market_id (summing sizes for markets with multiple positions).
2

Snapshot exchange positions

Uses the provided exchange_positions list or attempts to fetch from engine.exchange_positions().
3

Compare both sides

For every market across both snapshots, checks for: missing positions, side mismatches, and size mismatches.
4

Assign severity

Each break gets a severity level based on the type and magnitude of the discrepancy.

reconcile

Compare engine positions vs exchange and return all detected breaks.

Parameters

Each exchange position dict should have:

Returns

ReconciliationReport with all detected breaks.

Break Severity Levels

Side mismatches are always critical. A side mismatch means your engine thinks you are long but the exchange shows short (or vice versa). This requires immediate attention.

auto_reconcile

Pipeline function for hz.run() that runs reconciliation at a configurable interval.

Parameters

Injected into ctx.params

Between reconciliation runs, the pipeline injects the results from the most recent run. The first run happens on the first cycle; subsequent runs occur every interval seconds. Critical breaks are logged at WARNING level; info-level breaks are logged at INFO.

Type Reference

PositionBreak

ReconciliationReport


Full Multi-Strategy Workflow