Five candidate assets are each mapped to one qubit — bit zi = 1 means "include asset i". A portfolio is a 5-bit string z ∈ {0,1}⁵, one of 32 basis states of the joint quantum register. The score to maximize is a mean-variance objective with a soft budget penalty:
O(z) = Σ zᵢrᵢ − λ Σᵢⱼ zᵢzⱼ Covᵢⱼ − P·(Σzᵢ − 3)²
H_C = diag(−O(z)) (cost Hamiltonian)
H_M = Σᵢ Xᵢ (mixer Hamiltonian)
Starting from the equal superposition |+⟩⊗5 (Hadamard on every qubit), each QAOA layer applies two unitaries in sequence:
|ψ⟩ → e^(−iβ H_M) e^(−iγ H_C) |ψ⟩
The cost unitary is diagonal — it multiplies the amplitude of every one of the 32 basis states by a phase e^(−iγ·H_C(z)) that depends only on that portfolio's score. The mixer unitary is a tensor product of single-qubit X-rotations RX(2β) that spreads amplitude between neighbouring bitstrings, letting the phase differences from the cost step turn into real probability shifts. This simulator diagonalizes the exact 32×32 statevector every step — no approximation — so the bars you see are the real Born-rule probabilities |⟨z|ψ⟩|².
- γ (cost angle) — how strongly a layer rewards high-scoring portfolios with constructive phase.
- β (mixer angle) — how much amplitude a layer redistributes across bitstrings; β near 0 freezes the state, β near π/2 fully flips each qubit's bias.
- λ (risk aversion) — raises the mean-variance penalty for correlated/volatile picks, which can change which portfolio is optimal and re-targets the bars.
- Repeating the (cost, mixer) layer p times — as real QAOA circuits do on IBM/Rigetti/Google hardware — concentrates probability on better portfolios, though a fixed γ,β schedule (rather than classically-optimized angles) will not always converge monotonically, exactly as in a real device.