Tutorial: Implementing QAOA for Portfolio Optimization
Step-by-step tutorial showing how to formulate a small portfolio optimization problem as QAOA, with tips on parameter selection and shot budgeting.
Tutorial: Implementing QAOA for Portfolio Optimization
QAOA (Quantum Approximate Optimization Algorithm) is a hybrid approach to combinatorial optimization that can be adapted for portfolio selection problems. This tutorial walks through problem formulation, circuit design, parameter choices, and practical tips for running experiments on simulators and hardware.
“QAOA’s strength is in offering a tunable quantum-classical loop that can be adapted to resource constraints.”
Problem setup
Consider a toy portfolio with N assets and a budget constraint. Convert the objective (expected return minus risk penalty) into a quadratic unconstrained binary optimization (QUBO). The mapping uses binary variables that indicate whether an asset is included.
Key steps:
- Define expected returns r_i and covariance matrix C.
- Set objective: maximize sum(r_i x_i) - lambda * x^T C x.
- Translate into QUBO: minimize -sum(r_i x_i) + lambda * x^T C x with appropriate scaling.
Constructing the QAOA circuit
QAOA alternates between applying a phase-separator unitary based on the problem Hamiltonian and a mixing unitary. For each depth p, we have 2p parameters (gammas and betas).
Practical tips:
- Start with p=1 or p=2 to gauge behavior; deeper circuits increase gate count and susceptibility to noise.
- Map the QUBO terms to multi-qubit Z rotations for the phase operator. For pairwise terms, decompose into CNOT-RZ-CNOT patterns.
- Mixers are typically single-qubit X rotations parameterized by beta.
Optimization strategy
Use classical optimizers that tolerate noise; COBYLA and SPSA are common. SPSA is robust with noisy evaluations and requires fewer function evaluations. Employ parameter warm-starts from smaller instances or from simulated annealing solutions.
Shot budgeting and error mitigation
Allocate shots adaptively: use more shots near promising parameter regions. Incorporate readout error mitigation and simple zero-noise extrapolation if available. Use classical shadows or grouping techniques to reduce shot overhead for multiple observables.
Evaluation metrics
Compare the best-found solution to classical baselines like greedy heuristics and local search. Evaluate expected return, realized risk, and the fraction of times the quantum sampler returns top-K solutions.
Example workflow
- Formulate QUBO from sample dataset of 6 assets.
- Implement p=1 QAOA circuit and test on a simulator for multiple random seeds.
- Optimize using SPSA with 100 iterations, using 512 shots per evaluation.
- Run final candidate on hardware with readout mitigation and additional shots for validation.
Conclusion
QAOA is a promising route for near-term quantum advantage in combinatorial finance tasks. For practical adoption, emphasize hybrid engineering: warm-start classical heuristics, budget shots efficiently, and keep circuits shallow. This approach allows teams to compare quantum-enhanced strategies directly against well-optimized classical baselines.
Related Topics
Jin Park
Quantum Algorithm Developer
Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.