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:

min⁑x∈{0,1}nC(x)=q xTΞ£xβˆ’ΞΌTx+Ξ»budget(βˆ‘i=1nxiβˆ’K)2\min_{\mathbf{x} \in \{0, 1\}^n} \mathcal{C}(\mathbf{x}) = q \, \mathbf{x}^T \boldsymbol{\Sigma} \mathbf{x} - \boldsymbol{\mu}^T \mathbf{x} + \lambda_{\text{budget}} \left(\sum_{i=1}^n x_i - K\right)^2

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:

HC=βˆ‘i=1nhiΟƒiz+βˆ‘1≀i<j≀nJijΟƒizΟƒjz+Coffsetβ‹…I\mathcal{H}_C = \sum_{i=1}^n h_i \sigma_i^z + \sum_{1 \le i < j \le n} J_{ij} \sigma_i^z \sigma_j^z + C_{\text{offset}} \cdot I

with analytical coupling coefficients:

hi=βˆ’12ΞΌi+qβˆ‘kβ‰ iΞ£ik+q2Ξ£ii+Ξ»budget(1βˆ’K)h_i = -\frac{1}{2} \mu_i + q \sum_{k \neq i} \Sigma_{ik} + \frac{q}{2} \Sigma_{ii} + \lambda_{\text{budget}} (1 - K)

Jij=q4Ξ£ij+Ξ»budget2J_{ij} = \frac{q}{4} \Sigma_{ij} + \frac{\lambda_{\text{budget}}}{2}

Coffset=βˆ‘i(q4Ξ£iiβˆ’12ΞΌi)+βˆ‘i<j(q4Ξ£ij+Ξ»budget2)+Ξ»budgetK2C_{\text{offset}} = \sum_{i} \left(\frac{q}{4}\Sigma_{ii} - \frac{1}{2}\mu_i\right) + \sum_{i < j} \left(\frac{q}{4}\Sigma_{ij} + \frac{\lambda_{\text{budget}}}{2}\right) + \lambda_{\text{budget}} K^2


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:

∣γ,β⟩=∏l=1pUB(Ξ²l) UC(Ξ³l)β€‰βˆ£+βŸ©βŠ—n|\boldsymbol{\gamma}, \boldsymbol{\beta}\rangle = \prod_{l=1}^p U_B(\beta_l) \, U_C(\gamma_l) \, |+\rangle^{\otimes n}

  • 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:

βˆ‚βŸ¨HCβŸ©βˆ‚ΞΈk=⟨HC⟩θk+Ο€2βˆ’βŸ¨HC⟩θkβˆ’Ο€22\frac{\partial \langle \mathcal{H}_C \rangle}{\partial \theta_k} = \frac{\langle \mathcal{H}_C \rangle_{\theta_k + \frac{\pi}{2}} - \langle \mathcal{H}_C \rangle_{\theta_k - \frac{\pi}{2}}}{2}


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.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including At1uri/qaoa-quantum-portfolio-optimizer