Portfolio Management
ThePortfolio 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
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | "portfolio" | Portfolio identifier |
capital | float | 10000.0 | Total capital for weight calculations |
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 asdict[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.| Key | Type | Description |
|---|---|---|
market_id | str | Market identifier |
side | str | "yes" or "no" |
action | str | "buy" or "sell" |
size_delta | float | Size to trade |
current_weight | float | Current portfolio weight |
target_weight | float | Target portfolio weight |
Risk Metrics
metrics
Compute portfolio risk metrics including Monte Carlo simulation.PortfolioMetrics object:
| Field | Type | Description | |
|---|---|---|---|
num_positions | int | Number of positions | |
total_value | float | Total portfolio value | |
total_pnl | float | Total unrealised PnL | |
total_pnl_pct | float | PnL as percentage | |
concentration | float | HHI index | |
var_95 | float | 95% Value at Risk (Monte Carlo) | |
cvar_95 | float | 95% Conditional VaR | |
win_probability | float | Probability of positive PnL | |
greeks | dict[str, PredictionGreeks] | Per-position Greeks (delta, gamma, theta, vega) | |
correlation_matrix | `list[list[float]] | None` | Ledoit-Wolf covariance if available |
shrinkage_intensity | float | Shrinkage parameter |