Module 10: Portfolio — A Global Capital PerspectiveManaging PnL, positions, and performance across multiple accounts and strategies
1. Role of the Portfolio
The Portfolio gives the trading system a consolidated financial view. Rather than acting as a ledger for one strategy, it aggregates accounts, positions, balances, and PnL across the node.
flowchart LR
subgraph srcs["📥 Global Inputs"]
direction TB
acct["🏦 Accounts A / B"]
pos["📊 All Positions"]
market["📈 Market Data"]
end
portfolio["💰 Portfolio<br/>Global Aggregation"]
subgraph outputs["📤 Output Metrics"]
direction TB
nav["Net Asset Value (NAV)"]
pnl["PnL"]
margin["Margin Ratio"]
end
srcs ==> portfolio ==> outputs
style portfolio fill:#0f1419,stroke:#4fc3f7,stroke-width:2px
2. Core Features
Account Aggregation
Aggregates balances, available capital, and margin utilization across multiple exchange accounts.
Position Management
Tracks all open positions, calculating individual unrealized PnL and overall risk exposure.
PnL Calculation
Real-time computation of realized PnL (from closed positions) and unrealized PnL (mark-to-market).
Performance Reporting
Generates a comprehensive performance analysis report post-backtest, including returns, Sharpe ratio, and maximum drawdown.
3. API Queries
# Query portfolio information within a strategy
# Net Asset Value (all accounts + unrealized PnL)
nav = self.portfolio.net_exposures(venue)
# Unrealized PnL
unrealized_pnl = self.portfolio.unrealized_pnl(instrument_id)
# Realized PnL
realized_pnl = self.portfolio.realized_pnl(instrument_id)
# Account balances
balances = self.portfolio.balances_locked(venue)
# Check if the portfolio is completely flat
is_flat = self.portfolio.is_completely_flat()4. Backtest Performance Analysis
Post-backtest, the Portfolio generates a detailed performance report comprising these critical metrics:
| Metric | Description | Key Focus |
|---|---|---|
| Total Return | Overall return of the strategy | Whether it is positive and outperforms the benchmark |
| Annualized Return | Return annualized for the year | Useful for comparison against other asset classes |
| Sharpe Ratio | Risk-adjusted return | > 1.0 is good; > 2.0 is excellent |
| Maximum Drawdown (Max DD) | Maximum peak-to-trough equity drop | Determines the maximum pain threshold you can tolerate |
| Win Rate | Proportion of profitable trades | Must be analyzed in conjunction with the payoff ratio |
| Payoff Ratio | Average profit / Average loss | > 1.5 indicates a structurally sound strategy |
| Max Consecutive Losses | Maximum number of consecutive losing trades | Tests psychological endurance and margin limits |
5. Interactive Exercise
Backtest results for Strategy A: 80% Annualized Return, 0.5 Sharpe Ratio, 60% Max Drawdown.
Backtest results for Strategy B: 25% Annualized Return, 2.1 Sharpe Ratio, 12% Max Drawdown.
Which strategy is superior, and why?
Strategy B is superior. Rationale:
- Strategy A’s Sharpe ratio of 0.5 indicates that its returns are primarily derived from assuming massive risk.
- Strategy A’s 60% max drawdown means your account equity could collapse from $1M to $400k.
- Strategy B’s Sharpe ratio of 2.1 demonstrates excellent risk-adjusted returns.
- Strategy B’s 12% max drawdown is within a highly manageable range.
- Through the application of leverage, Strategy B can be scaled to match Strategy A’s return profile while maintaining vastly superior risk control.
💡 Conclusion: Treat risk-adjusted metrics such as the Sharpe Ratio as first-class signals, not secondary decoration behind absolute returns.
6. Key Takeaways
- Consolidated Ledger: The Portfolio aggregates account, position, and PnL state across strategies and venues.
- Mark-to-Market: Real-time updating of unrealized PnL based on live market data streams.
- Performance Metrics: Risk-adjusted returns (e.g., the Sharpe Ratio) are significantly more critical than absolute returns.
- Maximum Drawdown: Dictates the maximum capital allocation feasible for running the strategy.
- Automated Reporting: Generates performance analysis reports after the backtest completes.