Phase 2: Core Components

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
Figure 1: The Portfolio synthesizes data from multiple accounts and positions into a financial overview

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:

MetricDescriptionKey Focus
Total ReturnOverall return of the strategyWhether it is positive and outperforms the benchmark
Annualized ReturnReturn annualized for the yearUseful for comparison against other asset classes
Sharpe RatioRisk-adjusted return> 1.0 is good; > 2.0 is excellent
Maximum Drawdown (Max DD)Maximum peak-to-trough equity dropDetermines the maximum pain threshold you can tolerate
Win RateProportion of profitable tradesMust be analyzed in conjunction with the payoff ratio
Payoff RatioAverage profit / Average loss> 1.5 indicates a structurally sound strategy
Max Consecutive LossesMaximum number of consecutive losing tradesTests psychological endurance and margin limits

5. Interactive Exercise

🧠 Exercise: Performance Evaluation

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:

  1. Strategy A’s Sharpe ratio of 0.5 indicates that its returns are primarily derived from assuming massive risk.
  2. Strategy A’s 60% max drawdown means your account equity could collapse from $1M to $400k.
  3. Strategy B’s Sharpe ratio of 2.1 demonstrates excellent risk-adjusted returns.
  4. Strategy B’s 12% max drawdown is within a highly manageable range.
  5. 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

📋 Key Takeaways
  1. Consolidated Ledger: The Portfolio aggregates account, position, and PnL state across strategies and venues.
  2. Mark-to-Market: Real-time updating of unrealized PnL based on live market data streams.
  3. Performance Metrics: Risk-adjusted returns (e.g., the Sharpe Ratio) are significantly more critical than absolute returns.
  4. Maximum Drawdown: Dictates the maximum capital allocation feasible for running the strategy.
  5. Automated Reporting: Generates performance analysis reports after the backtest completes.