I built a quantum portfolio optimizer end to end: real market data, Markowitz risk-return math, a quantum circuit. Then I ran 10,080 experiments to map exactly where the algorithm succeeds, where it fails, and why. Every single trial was checked against the provably correct answer.
The headline finding, drawn like the market data it came from
How often QAOA recovers the exact optimal portfolio, as the number of candidate assets grows
If you read nothing else
What was built
A portfolio here is a yes/no decision on each stock: hold it or don't. That makes it a string of bits, and picking the best portfolio becomes a search over all 2n bitstrings for the one with the best risk-adjusted return. I encoded that objective as an energy landscape (an Ising Hamiltonian) where the best portfolio is literally the lowest-energy state, then used QAOA, a hybrid quantum-classical algorithm, to steer a quantum state toward it. Each stage is a separate, tested module:
A built-in self-check asserts the three mathematical forms (direct objective, QUBO matrix, Ising Hamiltonian) agree on every bitstring, so when quantum and classical answers are compared, they are provably scoring the same function.
Proof it works
On a six-stock universe (AAPL, MSFT, NVDA, GOOGL, AMZN, JPM; pick exactly 3), the quantum optimizer found NVDA + GOOGL + JPM, and the brute-force enumeration of all 64 portfolios confirms that is the optimum, rank 1 of 64. The choice is economically sensible: the two strongest growers plus the lowest-volatility bank.
| Method | Objective value | Portfolio found | Verdict |
|---|---|---|---|
| QAOA (quantum) | −0.6658 | NVDA · GOOGL · JPM | optimal |
| Brute force (ground truth) | −0.6658 | NVDA · GOOGL · JPM | reference |
| Classical greedy baseline | −0.6658 | NVDA · GOOGL · JPM | tied |
Interactive · a real quantum simulation, running in this page
This panel is not a recording. It simulates the same six-qubit QAOA circuit as the Python study — 64 complex amplitudes, alternating cost and mixer layers, Adam training the angles — in JavaScript, on the same six stocks and the identical objective H(x). Set the risk-aversion q, the budget B, and the circuit depth p, then run it. Because the problem is small, every run also brute-forces all 64 portfolios, so the verdict below is checked against ground truth, not asserted. When the algorithm misses, the badge says so.
Training the circuit
⟨H⟩ per optimizer step, 3 restarts · dashed line = true optimum
Where the probability goes
all 64 portfolios, best → worst · green bar = the true optimum
Honesty check, automated: on load the page recomputes H(x) for all 64 portfolios in JavaScript and asserts the values match the Python pipeline's (baked in at build time) to 10⁻⁶ — open the browser console to see it. Rank and approximation ratio are computed exactly as validate.py computes them.
Interactive · you vs. the algorithm
Think you can eyeball a better portfolio? Pick exactly 3 stocks (the budget B set above). Your pick, QAOA's pick, and the brute-force optimum are all scored with the same H(x), and the strip shows where each lands among all 64 possible portfolios — every tick is one portfolio, best on the left.
pick 3 stocks to reveal the comparison
The study · 10,080 trials · 51 instances · every one verified
The sweep varied problem size (4–12 assets), circuit depth, penalty strength, and four market correlation structures, with 10 seeded trials per configuration. Findings are numbered as in the full paper.
As the universe grows from 4 to 12 assets, exact-optimum recovery falls 97% → 68% → 62% → 58% → 51%. The decline is monotonic and gradual: the algorithm doesn't shatter at some critical size, it wears down predictably. It never fell below the 50% line at any size tested.
The natural fix for a struggling quantum circuit is more layers. The data says otherwise: at every size above 4 assets, the shallowest circuit won, and adding layers made success strictly worse at n=8 and n=10. At n=12, extra depth tripled compute time for no gain. The mechanism: each layer adds parameters to train, and at a fixed training budget, harder-to-train beats more-expressive.
Why does size hurt? The probability the algorithm assigns to the single best portfolio collapses from ≈19% at n=4 to ≈0.1% at n=12, always above the random-guessing floor, but by an ever-thinner margin. The algorithm still points at the right answer; the right answer just stops standing out from the crowd. This is the study's mechanistic core: not "it fails," but why it fails.
When the algorithm fails to find the exact best portfolio, it almost always returns one that is nearly as good: median solution quality stays at or above 99.9% of optimal at every size. In investing terms, the downside of a miss is measured in basis points, not blowups. The rare true failures are budget-violating portfolios, exactly the failure mode the penalty term exists to suppress.
The budget constraint ("hold exactly B stocks") is enforced by a penalty term. Halving it barely moved success (74% vs 72%), a difference within run-to-run noise. I flag honestly what this can't say: the over-penalized 2× setting was cut by the time budget and remains untested, so the claim is scoped strictly to the range studied.
At face value, portfolios built from real market data look easiest (81% success). That's a statistical trap: real-data instances only exist at the smallest sizes, so their bar is really a size effect in disguise. Comparing only the correlation regimes that span all sizes (69–73%), the differences dissolve. Conclusion: market correlation structure barely matters, and only a size-controlled comparison can show it.
The pilot study said the opposite, and I reported the reversal. An early, under-powered pilot (fewer steps, one restart, fewer trials) suggested deeper circuits rescue large problems, which was the more exciting story. The full study, with 10× the statistical power, reversed it. This page reports what the evidence supports, not what the pilot promised. It is also a concrete lesson I now carry: under-powered sweeps mislead.
No quantum advantage is claimed. At these sizes a classical computer finds the exact answer instantly; that is precisely what makes honest measurement possible. All runs used a noise-free classical simulator of a quantum computer, and real hardware would do worse. The contribution is a ground-truth-validated map of where and why a quantum heuristic succeeds and fails, failure modes included.
Why the numbers can be trusted
Where this goes next
Repeat the sweep under a realistic noise model, then on real quantum hardware; test whether smarter initialization (warm-starting from classical solutions) removes the depth penalty; and push past the brute-force limit with tensor-network simulators, where verification itself becomes the research problem. Neutral-atom machines are a natural target: their native physics is already Ising-shaped, the same form this portfolio problem takes.