QAOA & VQE Quantum Portfolio Optimization Engine
A parameterized quantum optimization model and variational statevector inference engine designed for solving NP-hard cardinality-constrained portfolio optimization and combinatorial arbitrage problems via Quantum Approximate Optimization Algorithm (QAOA) and Variational Quantum Eigensolver (VQE) mapped onto longitudinal Ising Spin-Glass Hamiltonians.
Developed by At1uri as part of the Institutional Quantitative AI Suite.
1. Problem Formulation: Markowitz QUBO to Ising Spin Glass
Markowitz mean-variance portfolio selection with an exact cardinality constraint $K$ is expressed as a Quadratic Unconstrained Binary Optimization (QUBO) problem:
where:
- $\mathbf{x} \in {0, 1}^n$ is the binary asset selection indicator,
- $\boldsymbol{\Sigma} \in \mathbb{R}^{n \times n}$ is the asset return covariance matrix,
- $\boldsymbol{\mu} \in \mathbb{R}^n$ is the expected return vector,
- $q \ge 0$ is the risk-aversion coefficient,
- $K \in {1, \dots, n}$ is the target cardinality,
- $\lambda_{\text{budget}} > 0$ is the quadratic penalty enforcing the exact selection constraint.
Spin Transformation & Longitudinal Ising Hamiltonian
Applying the Jordan-Wigner / spin-1/2 mapping $x_i = \frac{I - \sigma_i^z}{2}$, where $\sigma_i^z$ is the Pauli-$Z$ matrix:
with analytical coupling coefficients:
2. Quantum Circuit Architecture
A. Quantum Approximate Optimization Algorithm (QAOA)
Starting from the uniform superposition state $|+\rangle^{\otimes n} = \frac{1}{\sqrt{2^n}} \sum_{x \in {0, 1}^n} |x\rangle$, QAOA applies $p$ alternating operator layers:
- Cost Unitary: $U_C(\gamma_l) = \exp(-i \gamma_l \mathcal{H}C) = \prod_i e^{-i \gamma_l h_i \sigma_i^z} \prod{i < j} e^{-i \gamma_l J_{ij} \sigma_i^z \sigma_j^z}$
- Mixer Unitary: $U_B(\beta_l) = \exp(-i \beta_l \sum_i \sigma_i^x) = \prod_{i=1}^n R_x(2\beta_l)_i$
B. Variational Quantum Eigensolver (VQE)
The hardware-efficient ansatz prepares $|\psi(\boldsymbol{\theta})\rangle$ via single-qubit rotations $R_y(\theta)$ interleaved with Controlled-Z ($CZ$) entangling gates.
Analytical Quantum Parameter-Shift Rule: Gradients are computed exactly on quantum statevectors without numerical finite-difference approximation:
3. Empirical Benchmarks
Trained across 3 benchmark multi-asset universes ($n=4$ to $n=5$ qubits, $2^n$ basis states):
| Universe | Qubits ($n$) | Target State | Ground Energy $E_0$ | QAOA $p=1$ $\alpha$ | QAOA $p=3$ $\alpha$ | VQE $d=2$ $\alpha$ | Entanglement Entropy |
|---|---|---|---|---|---|---|---|
| Tech Mega-Caps (AAPL, MSFT, NVDA, GOOGL) | 4 | ` | 1010β©` | -0.4697 | 88.4% | 97.2% | 92.1% |
| Multi-Asset Macro (SPY, TLT, GLD, BTC) | 4 | ` | 0110β©` | -0.3812 | 86.1% | 96.5% | 90.8% |
| Crypto High-Beta (BTC, ETH, SOL, AVAX, LINK) | 5 | ` | 10100β©` | -0.5841 | 82.7% | 94.8% | 88.6% |
(where $\alpha = \frac{\langle \mathcal{H}C \rangle - E{\max}}{E_0 - E_{\max}}$ is the approximation ratio).
4. Quickstart & Usage
from quantum_eigensolver import IsingHamiltonian, optimize_qaoa, optimize_vqe
import numpy as np
# 1. Define asset expected returns and covariance matrix
mu = np.array([0.18, 0.16, 0.34, 0.14]) # 4 assets
Sigma = np.array([
[0.0484, 0.0299, 0.0573, 0.0343],
[0.0299, 0.0400, 0.0538, 0.0346],
[0.0573, 0.0538, 0.1764, 0.0585],
[0.0343, 0.0346, 0.0585, 0.0576]
])
# 2. Map Markowitz portfolio problem to Ising Spin-Glass Hamiltonian
H = IsingHamiltonian.from_portfolio(
expected_returns=mu,
cov_matrix=Sigma,
risk_aversion=0.5,
target_cardinality=2,
penalty_lambda=1.2
)
print(f"Optimal Ground State: |{H.optimal_bitstring}> | E0: {H.E_min:.4f}")
# 3. Optimize via QAOA (p=2 layers)
result_qaoa = optimize_qaoa(H, p_layers=2, max_steps=40)
print(f"QAOA Approximation Ratio: {result_qaoa['approximation_ratio']*100:.2f}%")
print(f"Optimal Parameters: {result_qaoa['optimal_params']}")
# 4. Optimize via VQE with analytical parameter-shift rule
result_vqe = optimize_vqe(H, depth=2, max_steps=40)
print(f"VQE Approximation Ratio: {result_vqe['approximation_ratio']*100:.2f}%")
5. Repository Assets
quantum_eigensolver.py: Standalone, dependency-light Python quantum simulation and optimization engine.qaoa_circuit_weights.json: Pre-converged optimal parameter vectors $(\boldsymbol{\gamma}^*, \boldsymbol{\beta}^*)$ and $\boldsymbol{\theta}^*$.benchmarks.json: Ground state energies, spectral gaps, and approximation ratio benchmarks.- Interactive Web App: Explore real-time quantum statevector simulation in the Quantum Portfolio Optimization Studio.