QAOA for Portfolio Optimization
Overview
Portfolio optimization is a fundamental problem in finance: select assets to maximize expected return while minimizing risk. This circuit uses QAOA to find optimal asset allocations.
The Problem
Given:
- n assets with expected returns r₁, r₂, ..., rₙ
- Covariance matrix Σ (measuring correlations)
- Risk aversion parameter q
Maximize: Return - q × Risk
CODEObjective = Σᵢ rᵢxᵢ - q × Σᵢⱼ σᵢⱼxᵢxⱼ
where xᵢ ∈ {0,1} indicates asset selection.
Encoding
Each qubit represents one asset:
- |1⟩ = Include in portfolio
- |0⟩ = Exclude from portfolio
| Qubit | Asset | Return | Risk |
|---|---|---|---|
| q₀ | Bond Fund | 5% | Low |
| q₁ | Stock Index | 8% | Medium |
| q₂ | Tech Stocks | 12% | High |
| q₃ | Crypto | 15% | Very High |
The Circuit
CODE┌───┐┌──────────┐┌──────────┐┌─────────┐ q_0: ┤ H ├┤ RZ(-2γr₀)├┤ RZZ(γσ) ├┤ RX(2β) ├─... ├───┤├──────────┤├──────────┤├─────────┤ q_1: ┤ H ├┤ RZ(-2γr₁)├┤ RZZ(γσ) ├┤ RX(2β) ├─... ...
Running the Circuit
PYTHONfrom circuit import run_circuit import numpy as np # Custom returns and covariance returns = np.array([0.05, 0.10, 0.15]) cov = np.array([ [0.01, 0.002, 0.001], [0.002, 0.03, 0.01], [0.001, 0.01, 0.05] ]) result = run_circuit(returns=returns, covariance=cov, risk_factor=0.3) print(f"Best portfolio: {result['best_portfolio']}")
Expected Output
| Metric | Example Value |
|---|---|
| Selected assets | [0, 2] |
| Expected return | 17% |
| Portfolio risk | 0.042 |
| Sharpe ratio | 0.83 |
Risk-Return Tradeoff
| risk_factor | Strategy | Result |
|---|---|---|
| 0.0 | Pure return | Highest risk assets |
| 0.5 | Balanced | Mix of assets |
| 1.0 | Risk-averse | Lower risk assets |
Real-World Applications
- Retirement planning: Balance growth and stability
- Hedge funds: Optimize risk-adjusted returns
- Index tracking: Match benchmark with fewer assets
Quantum Advantage
- Combinatorial explosion: 2ⁿ possible portfolios
- Correlation handling: Naturally encodes asset interactions
- Constraint flexibility: Budget, sector limits, etc.