Skip to main content

Portfolio Management

The Portfolio class provides position tracking, weight optimization, risk analytics, and rebalancing for prediction market portfolios. All heavy computation (Monte Carlo, Greeks, Ledoit-Wolf) runs in Rust.

4 Optimizers

Kelly, equal-weight, risk parity, and minimum variance allocation.

Monte Carlo Risk

VaR, CVaR, win probability, and Greeks via Rust simulation engine.

Auto-Rebalance

Generate rebalancing orders to move from current to target weights.

Live Engine Sync

Build a Portfolio from a running Engine with Portfolio.from_engine().

Quick Start


Constructor


Managing Positions

add_position

Add or replace a position in the portfolio.

update_price

Update the current market price for an existing position.

remove_position

Remove a position from the portfolio.

from_engine

Build a Portfolio from a running Engine’s live positions and feed data.

Portfolio Analytics

weights

Current weight per market (position value / total portfolio value).

pnl / pnl_pct

concentration

Herfindahl-Hirschman Index (HHI): sum of squared weights. Lower is more diversified. 1/N = perfectly equal.

summary

Human-readable portfolio overview.

Weight Optimization

All optimizers return target weights as dict[str, float] mapping market IDs to target allocations.

Kelly Criterion

Compute Kelly-optimal weights given your probability estimates.

Equal Weight

Simple 1/N allocation across all positions.

Risk Parity

Inverse-volatility weighting. Uses Ledoit-Wolf shrinkage covariance if return history is provided.

Minimum Variance

Minimum variance allocation using Ledoit-Wolf covariance estimation.

Rebalancing

needs_rebalance

Check whether any position deviates from target weights by more than a threshold.

rebalance_orders

Generate the orders needed to move from current to target weights.
Each order dict contains:

Risk Metrics

metrics

Compute portfolio risk metrics including Monte Carlo simulation.
Returns a PortfolioMetrics object:

Full Workflow Example