This project focuses on solving the portfolio optimization problem using both classical and quantum-inspired methods. The goal is to find an optimal allocation of assets that maximizes returns while minimizing risk. The workflow progresses from data preparation to quantum optimization via QAOA, followed by a comprehensive comparison of results.
The main steps covered across the notebooks are:
- Data Preparation and QUBO Formulation (
Data and QUBO.ipynb) - Brute Force Solution (
Brute Force Method.ipynb) - Classical Optimization using CVXPY (
CVXPy Method.ipynb) - Quantum Approximate Optimization Algorithm (QAOA) (
QAOA GPU.ipynb) - Result Comparison and Visualization (
Comparison.ipynb)
We begin by defining the problem through historical asset data. The expected returns and covariance matrix are computed to quantify performance and risk.
The classical portfolio optimization problem is defined as:
subject to:
where:
- (
$\mu$ ) is the vector of expected returns. - (
$\Sigma$ ) is the covariance matrix. - (
$\lambda$ ) is the risk-aversion coefficient.
This objective function is then reformulated as a Quadratic Unconstrained Binary Optimization (QUBO) problem:
where
Key Outputs:
- Asset statistics and correlation heatmaps.
- Constructed QUBO matrix visualizations.
The brute force approach evaluates all possible combinations of portfolio allocations, serving as the ground truth for benchmarking.
For
Key Outputs:
- Optimal portfolio configuration.
- Stored results in
.npzformat.
Using the CVXPY library, we solve the same problem via convex optimization, under continuous relaxation or binary constraints.
CVXPY solves:
subject to linear or quadratic constraints.
After solving the optimization, the main results — such as objective function value, annualized return, annualized risk, sharpe ratio, and optimal weights — are stored in a compressed NumPy file (.npz) for later use.
Key Outputs:
- Optimal allocation vector.
- Stored results in
.npzformat.
We apply the Quantum Approximate Optimization Algorithm (QAOA) using Qiskit to solve the QUBO on a simulated quantum backend (GPU-accelerated environment).
- Define the cost Hamiltonian from the QUBO matrix.
- Configure QAOA parameters (layers (
$p$ ), optimizer, etc.). - Run the optimization and measure probabilities.
The cost function for QAOA corresponds to the expectation value:
where
Key Outputs:
- QAOA energy convergence.
- Risk vs. return energy for QAOA.
Finally, results from all methods (Brute Force, CVXPY, and QAOA) are compared in terms of accuracy and solution quality.
- Optimal portfolio composition.
- Objective function value.
Key Visualizations:
- Comparative plots of performance.
-
Brute-force:
Provides the exact optimal solution by exhaustively exploring all possible portfolios. However, it is computationally expensive and scales poorly as the number of assets increases. -
Classical (CVXPY):
Finds a near-optimal solution much faster using convex optimization. In this case, its result nearly coincides with the brute-force optimum, confirming its accuracy and efficiency as a classical benchmark. -
Quantum (QAOA):
Achieves a feasible but suboptimal portfolio, with a lower expected return than the classical and brute-force results. This reflects current limitations in parameter tuning and circuit depth, though it illustrates the potential of quantum methods for combinatorial optimization.
├── Data and QUBO.ipynb
├── Brute Force Method.ipynb
├── CVXPy Method.ipynb
├── QAOA GPU.ipynb
├── Comparison.ipynb
├── figures/
│ ├── qubo_heatmap.png
│ ├── brute_force_plot.png
│ ├── cvxpy_frontier.png
│ ├── qaoa_convergence.png
│ ├── qaoa_probabilities.png
│ ├── comparison.png
│ └── risk_vs_return_qaoa.png
└── README.mdProject: Quantum Portfolio Optimization (QAOA) Tools: Python, Qiskit, CVXPY, NumPy, Matplotlib



