Enhancing Knapsack-based Financial Portfolio Optimization Using Quantum Approximate Optimization Algorithm
Abstract
Portfolio optimization is a primary component of the decision-making process in finance, aiming to tactfully allocate assets to achieve optimal returns while considering various constraints. Herein, we proposed a method that uses the knapsack-based portfolio optimization problem and incorporates the quantum computing capabilities of the quantum walk mixer with the quantum approximate optimization algorithm (QAOA) to address the challenges presented by the NP-hard problem. Additionally, we present the sequential procedure of our suggested approach and demonstrate empirical proof to illustrate the effectiveness of the proposed method in finding the optimal asset allocations across various constraints and asset choices. Moreover, we discuss the effectiveness of the QAOA components in relation to our proposed method. Consequently, our study successfully achieves the approximate ratio of the portfolio optimization technique using a circuit layer of , compared to the classical best-known solution of the knapsack problem. Our proposed methods potentially contribute to the growing field of quantum finance by offering insights into the potential benefits of employing quantum algorithms for complex optimization tasks in financial portfolio management.
1Department of AI Convergence, Pukyong National University, Nam-gu, Busan 48513, South Korea
2Department of Management Information Systems, Chungbuk National University, 1, Chungdae-ro, Seowon-gu, Cheongju-si, Chungcheongbuk-do, South Korea
*Corresponding author: Youngsun Han (youngsun@pknu.ac.kr)
Keywords
best-known solution (BKS), portfolio optimization, knapsack problem, quantum approximate optimization algorithm (QAOA)
1 Introduction
The financial industry plays a remarkable role in the economic health and growth of every country. In the constantly evolving world of financial markets, technological advancements are shaping traditional portfolio optimization methods, presenting new opportunities and challenges; this process involves enlarging assets to reduce risk by offsetting individual risk profiles crucial to the investment process [1]. Although there are many portfolio optimization models, they possibly have limitations. For example, the mean-variance model, which provides solutions as percentages of the total budget, can result in fractional allocations of non-feasible assets [2]. In the constant pursuit of optimization, some studies have explored extensions to portfolio optimization [3]. Among these, a technique that reformulates the financial portfolio optimization problem as a knapsack-based problem has been proposed [4, 5].
Knapsack problem [2] was adapted for portfolio optimization by treating all assets included in the portfolio as items. The value of each asset is represented by its expected return, usually estimated using historical data or forecasting techniques. The weight of each item corresponds to a risky asset, typically measured by its standard deviation or the variance-covariance matrix of the assets. The knapsack capacity corresponds to the budget or available capital that can be invested in the portfolio. By reformulating the knapsack problem, the primary objective is to maximize the total value of the portfolio while satisfying the capacity constraint and potentially other constraints, such as a target return or a minimum number of assets. However, similar to [6], the knapsack problem is considered NP-hard even with polynomial-bounded weights and values. Therefore, exploring new paradigms for optimization owing to the computational complexity of solving this problem is crucial [7, 8].
Similarly, the paradigm of quantum computing, leveraging the properties of quantum mechanics, has been developed to solve complex problems intractable for classical computers [9, 10]. The financial domain is a primary aspect of quantum computing, with applications spanning price derivation, risk modeling, portfolio optimization, and fraud detection [11]. As technology redefines problem-solving in finance, the quantum approximate optimization algorithm (QAOA), rooted in quantum computing, offers the promise of efficiently finding approximate solutions for computationally demanding problems within the polynomial-bounded NP optimization complexity class [12]. In [13, 14], the application of QAOA to the knapsack problem is explored for optimization purposes.
In this paper, we reformulate the classical portfolio optimization problem as a knapsack problem that allows for an efficient mapping onto quantum algorithms, particularly advantageous for NP-hard financial optimization. By treating each asset’s expected return as value and its risk as weight, the knapsack model aligns portfolio constraints with total risk, permitting optimization under capacity constraints. Our approach introduces a novel Quantum Walk Mixer (QWM) combined with the Quantum Approximate Optimization Algorithm (QAOA), integrating the Quantum Fourier Transform (QFT) within the oracle. This QWM-QAOA framework ensures feasible states are targeted while reducing computational complexity. Empirical results demonstrate that QWM-QAOA enhances solution space exploration, providing robust portfolio configurations with high approximation ratios even under various noise conditions, thus showcasing a significant advancement in leveraging quantum algorithms for practical finance applications. The contributions of our study can be summarized as follows:
-
•
We propose a portfolio selection approach that formulates the portfolio problem as a knapsack concern by incorporating expected returns from the Markowitz model [15] and setting the capacity according to the knapsack framework.
-
•
We present a Quantum Walk Mixer to Quantum Approximate Optimization Algorithm (QWM-QAOA) for the knapsack problem, integrating a shallow circuit layer to decrease computational complexity and improve solution quality.
-
•
We demonstrate that our model consistently enhances the identification of optimal solutions for the knapsack problem, achieving an impressive approximation ratio ranging from 100% to 95% in scenarios involving the selection of 2 to 8 stocks.
The paper is organized as follows: Section 2 provides the background knowledge. Section 3 explores the related work. Section 4 details our proposed method. Section 5 demonstrates the experimental setup and performance evaluation. Section 6 dissects the findings of the proposed method, underscoring its achievements and limitations. Finally, we conclude our study in Section 7.
2 Background
In this section, we briefly describe the background knowledge of portfolio optimization, the knapsack problem, and the quantum approximate optimization algorithm (QAOA).
2.1 Portfolio Optimization
Portfolio optimization is a mathematical framework that maximizes returns while minimizing risks through strategically selecting assets within an investment portfolio [16]. This is typically achieved by strategically allocating the proportion of each asset in the portfolio to optimize the risk-return tradeoff by considering the specified risk tolerance. The process involves four steps: i) identifying suitable assets, ii) projecting anticipated yields based on historical data for future forecasts, iii) quantifying the risk by assessing the uncertainty of each asset, and iv) selecting the optimal portfolio that maximizes the expected yield for a given risk level [17]. One of the various models used in this study was the Markowitz model developed by Harry Markowitz in 1952 [15]. This analysis is in conjunction with the variance of the rate of return, providing a significant assessment of portfolio risk under a rational framework of assumptions. The Markowitz model represented the maximum expected yield by allocating funds into stocks as follows [18]:
(1) |
where indicates the anticipated return at time per stock invested in, and is the rate at which return in the security where time is discounted back to the presents. The standard deviation—the variance of return—is a statistical measure used as an indicator of the uncertainty or risk linked to return. These statistical indicators effectively measure the extent to which returns deviate unpredictably from the average value over a specific period. The variance represents the degree of variation exhibited by the return concerning the expected return , as illustrated:
(2) |
The covariance of returns measures the relative riskiness of a security within a portfolio of securities. For two securities, denoted as and , the covariance of their returns as
(3) |
Furthermore, covariance can be measured depending on the variability of the two individual return series:
(4) |
where is the correlation coefficient of returns, and and are the standard deviation of and . As previously stated, an efficient portfolio is characterized by selecting individual assets within the portfolio and weighting each asset. Therefore, the portfolio return is calculated as a weighted average of the returns of the individual investments within the portfolio. Next, denoted as the weight and applied to each return of the portfolio takes form as follows:
(5) |
where is independent of . The simplified version of the variance of a portfolio can be written as
(6) |
where is the variance of the portfolio, is the percentage of the investor’s assets that are allocated to the asset, and the represents the variance of the asset and the covariance between the returns for assets and denoted as . Traditional asset allocation methods, such as the Markowitz theorem, reportedly provide solutions in percentages. This approach can suggest allocating half of a market share, which is often impractical [2]. Therefore, proposing a method for determining the number of shares for each asset is crucial; this involves the conversion of expected returns, prices, and budget into interval values and determines the priority and importance of each share by framing it within a knapsack-based model.
2.2 Knapsack Problem
In this context, a given set of items with known sizes is selected and packed into a knapsack with a fixed capacity [19]. This problem is one of the simpler NP-hard problems in combinatorial optimization because it focuses on maximizing an objective function while adhering to a single resource constraint. To find the exact solutions, some techniques have been employed, such as relaxations, bounds, reductions, and other algorithmic approaches [20]. These techniques include genetic algorithms [21], dynamic programming [22], simulated annealing [23], Tabu search [24], and greedy algorithm [25]. These classical approaches are instrumental in providing optimal solutions. Although these conventional approaches are successful and valuable, they are limitations in computation in the classical domain. Furthermore, the new paradigm of quantum computing introduces optimization techniques, including QAOA, to tackle problems such as the knapsack problem, yielding better solutions than classical computation techniques [26, 27].
2.3 Quantum Approximate Optimization Algorithm(QAOA)
In combinatorial optimization, QAOA excels as solutions tailored for quantum computing while leveraging the strengths of classical computing [12, 28]. QAOA, a hybrid quantum-classical algorithm, has demonstrated remarkable effectiveness in addressing recent NP-hard problems, including Max-Cut [29], traveling salesman problem [30], and quadratic unconstrained binary optimization (QUBO) [31]. Consider a combinatorial optimization problem involving an N-bit binary string represented as , with a classical objective function is maximized. The goal is to find a solution that provides a high approximation to the maximum values of [32]. QAOA encodes this classical objective function into a quantum Hamiltonian ,
(7) |
Furthermore, operates diagonally on the computational basis states of dimensional Hilbert space (-qubit space). Ideally, the performance of the -level QAOA improves with increasing . For the -level QAOA, the state is initialized, while the and a mixing Hamiltonian:
(8) |
are applied alternately with controlled duration, resulting in a wave function:
(9) |
This variational wave function is characterized by variational parameters, and . The expected value of in this state is determined through repeated measurements on a computational basis:
(10) |
Furthermore, a classical computer is used to search for the optimal parameters and maximize the averaged output :
(11) |
Next, the approximation is assessed by the ratio between the optimized values and the maximum possible value , as the approximate ratio:
(12) |
This approximation ratio reflects how close the QAOA solution is to the optimal classical solution. Typically, the search for this approximate ratio begins with a random initial estimate of the parameter and performing gradient-based optimization [33].
3 Related Work
Recent studies have explored hybrid approaches to enhance different quantum algorithms for knapsack-based portfolio optimization problems. For example, [34] introduces Quantum-Inspired Evolutionary Algorithm (QIEAs) for difficult knapsack problems. Similarly, [35] used Quantum-inspired meta-heuristic approaches for constrained portfolio optimization problems. These advancements highlight the potential of hybrid quantum-classical approaches for tackling real-world optimization challenges.
Our study builds upon several key pieces of research that delve into the application of QAOA to the knapsack problem concerning portfolio optimization. QAOA has been employed as a portfolio optimization method. In this approach, the portfolio optimization problem is transformed into a binary version. Accordingly, the weight vector is discretized, with the element taking values of either 0 or 1. In [36], a comprehensive study of quantum computing approaches for multi-knapsack problems is proposed by investigating some of the most prominent and state-of-the-art quantum algorithms using different quantum software and hardware tools. Consequently, quantum computing offers the potential for good and fast solutions to multi-knapsack optimization problems in various fields, such as logistics (allocating goods to containers), resource allocation in computing (distributing tasks among different servers), and financial portfolio optimization (allocating assets among different investment opportunities). In [37], the Markowitz models of portfolio optimization were converted into binary knapsacks. A hard constraint model was employed by incorporating hard constraints into the quantum algorithm, involving designing mixing operators based on the constraint conditions. Additionally, a combination of - and -mixers was used to encode the constraints in the quantum circuit. -mixers were used to mix the quantum state and generate a superposition of feasible solutions, whereas -mixers were used to enforce the hard constraints. Moreover, using a hard constraint model ensured that the quantum state evolved between feasible solutions satisfying the constraints while allowing for a high degree of flexibility in opting parameters. Another intriguing study highlights the strengths of the quantum walk optimization algorithm (QWOA) [38] compared to other quantum optimization algorithms while highlighting the challenges posed by the complex and large solution space associated with its lattice structure. Moreover, the quantum mixer optimization algorithm (QMOA) was introduced as an extension of QWOA. It enhanced the efficiency of quantum optimization algorithms for portfolio optimization by reducing the number of iterations required for computations [39].
4 Knapsack-based Portfolio Optimization
In this section, we explain our overall architecture, knapsack-based portfolio formulation, and QAOA for the knapsack problem.
4.1 Overall Architecture
This section outlines the complete process from stock data preprocessing to determining the optimal portfolio configuration using a quantum-enhanced approach. As shown in Figure 1, the workflow begins by processing historical stock prices to compute the daily returns using the Markowitz-based portfolio optimization model. Algorithm 1 calculates the expected returns (E(R)), which are crucial inputs for formulating the portfolio selection as a knapsack problem. This step maps the expected returns, stock weights, and capacity constraints into a knapsack framework to define the feasible portfolio configurations. In the next phase, Algorithm 2 solves the knapsack-based portfolio optimization problem. Here, we first construct the feasible oracle using Quantum Fourier Transform (QFT) [40] to ensure that only valid solutions are considered for further optimization. Once a feasible solution is identified, the Quantum Walk Mixer (QWM) is applied within the Quantum Approximate Optimization Algorithm (QAOA), following the approach of [38]. The combination of QWM and QAOA (QWM-QAOA) efficiently explores the solution space, minimizing computational complexity while improving the accuracy of the optimization. The final output is a binary string, where each bit represents whether a stock is included or excluded from the portfolio. For instance, a result of (1,0) for two stocks indicates that Stock A is selected, while Stock B is excluded, thus guiding the final portfolio selection and investment strategy.

4.2 Knapsack-based Portfolio Formulation
Our methodology is based on the fundamental principles of mean-variance optimization, focusing on the Markowitz model. This model historically maximizes the anticipated yield of a portfolio while considering a predetermined level of risk, quantified by the variance of portfolio returns. We denoted the expected return of stock by using the mean return calculation. Next, we transformed the expected return into a knapsack problem. Subsequently, we extended this model by reinterpreting the expected return as a component of a knapsack problem, thereby aligning portfolio optimization with knapsack problem dynamics; this adaptation involves redefining the expected return of each stock as a value optimized under the constraints of total portfolio risk. This mathematical transformation effectively converts portfolio optimization into a knapsack problem:
maximize | (13) | |||
subject to |
where the risk of including stock in the portfolio, denoted as , and the total risk tolerance, denoted by , serves as the knapsack capacity. The binary variable indicates whether to include stock in the portfolio, and represents its expected return values.
This process can be summarized as Algorithm 1. It begins by extracting the historical returns of each stock within a specified time range, from the start to the end date, using the function. From line , these historical returns are then passed into the Markowitz model through the function, which calculates the expected returns, denoted as . These expected returns provide key insights into the potential profitability of the selected stocks in the portfolio problem. Specifically, the expected returns () are assigned as the values in the knapsack problem, and the weights for each stock are uniformly set to 1, representing equal weighting for all assets. Afterward, the algorithm also defines the capacity constraint () of the knapsack problem, which is set to half the number of stocks, calculated as . This framework effectively transforms the portfolio optimization problem into a knapsack problem formulation. This transformation allows for a more structured handling of assets and makes it possible to apply powerful combinatorial optimization techniques.
INPUT: : start date of stock prices, : end date of stock prices, : list of stocks
OUTPUT: : portfolio optimization modeled as a knapsack problem
4.3 QAOA for the knapsack problem
After formulating the portfolio optimization as a knapsack problem, we optimized it using Algorithm 2. We employed the QWM-QAOA to prepare the mixing Hamiltonian for the QAOA process. In lines , we set up the quantum registers and other necessary preparations for QAOA using the function. Line focuses on constructing the Mixing Hamiltonian using the QWM-QAOA approach, which is achieved via the function. This step requires parameters such as a predefined trotter step , the number of quantum registers, weights, and ancillaries. Next, the algorithm prepares the phase Hamiltonian using (line ), which plays a crucial role in the construction of the QAOA. More details on these concepts will be provided in the following sections. At each circuit layer , the algorithm computed the expectation value (line ), facilitating the determination of a new set of optimal parameter . These optimal parameters were identified using the SHGO optimization method and implemented as line . Finally, the algorithm measured probabilities (line ) through a measurement process. These probabilities were used to determine the optimal solution using the function to choose the best selection of items represented as as the optimal choice of approximation ratio.
INPUT : knapsack problem, : circuit layer, : trotter step count for QAOA
OUTPUT : approximation ratio as optimal choice
4.3.1 Feasibility Oracle
The feasibility oracle is used as a hypothetical subroutine that instantly determines whether a proposed solution to the knapsack problem violates any constraints [41]. We can explore solutions within a well-defined space of bitstrings by representing our portfolio model as a binary knapsack problem. We defined as the set of all possible bitstrings of length representing potential portfolio choices. Furthermore, each possible choice of any of the items is represented by a bitstring . ). Thus, the subset feasible solution was denoted as for the knapsack problem, and the feasibility function was defined as
(14) |
Considerably, the feasibility oracle to be unitary as:
(15) |
In portfolio optimization, a state symbolizes a specific stock allocation, which is deemed feasible (i.e., ) if the total weight does not exceed the capacity . This oracle toggles a flag qubit based on the feasibility of the state , representing a possible portfolio configuration.
Next, we allocated qubits for storage as follows: to record the formulated knapsack choices, to hold the weight of the item choice, and as the flag qubit indicating the feasibility of the state . Remarkably, the number of qubits required for , , and are deonted by , , and respectively. Upon that, the total number of qubits that are required is .
Furthermore, the total weight is calculated by adding the weight of each item to register , controlled by the corresponding bit in register . We also compare the computed weight to the capacity using an inequality check facilitated by a multiple-controlled NOT gate.
For suitable , the inequality can be verified using the following condition:
(16) |
This condition ensures that the binary representation of has zeros in all positions beyond . The feasibility oracle employs two primary unitary operations- and . augments with a predetermined offset , facilitating the binary representation required for the feasibility check; is applied conditionally based on ’s outcome.
We begin by illustrating how is prepared. Quantum Fourier Transform (QFT) [40] is employed within the unitary operation to facilitate the process of adding weights in the knapsack problem.
This process starts with the initialization of the ancillary weight register to . Next, QFT is applied to to prepare the register for quantum addition, even though the QFT does not change the state for state . This step is necessary for nonzero initial states . Post-state transformation of from the computational basis to the Fourier basis, the weight representation was distributed across the amplitude of the quantum state:
(17) |
where we use the notaion , and is the binary representation of . Furthermore, weights were added to using controlled operations applying phase rotations. These operations are conditioned on the bits of the bitstring indicating the selection of items. Each bit in determines whether the corresponding weight should be added to . The addition in the Fourier space was related to phase rotation and implemented by a sequence of controlled phase gates. The magnitude of the rotation was determined by and the position of the bit controlling the operation. The implementation of controlled additions can be described as follows: for each selected item (where the corresponding bit in is , a controlled phase rotation is applied to . The phase added to each computational basis state within is proportional to :
(18) |
This phase rotation effectively encodes the addition of into the quantum state. After completing this process, the step transformed the register back to the computational basis required, where
(19) |
The inverse QFT decodes the phase information back into a computational state representing the total weight of the selected items. If QFT encodes the weight as a superposition of phases, the inverse QFT converts these phases back into a binary number the sum of the weights. The final state of the register after applying was the binary representation of the total weight of the items:
(20) |
Figure 2 shows how is implemented using an algorithm based on QFT. Following the implementation of the unitary operation , is described in Figure 3, which comprises a quantum circuit that conditionally modifies the state of an ancillary qubit concerning the sum of weights represented in the register . Referring to Equation 16, the ancillary qubit underwent a state flip to signal a valid configuration when the total weight , augmented by a constant offset is less than the predefined threshold . This transformation was executed through several multi-controlled-NOT gates, where each gate was influenced by a qubit distinct from the weight register. The successful transition of the ancillary qubit’s state post signified a feasible solution, adhering to the knapsack’s capacity, which effectively segregates the solution space into permissible and impermissible weights.


4.3.2 Quantum Walk Mixer for Enforcing Constraints
This process relies on the mixing operator generated by mixing Hamiltonian from Equation 8 as follows:
(21) |
Alternatively, by leveraging the feasible function in Equation 14 and neighboring states for exploring the solution space, can be described as
(22) |
where is the neighbor of ( with bit flipped). Using this alternative representation, it is easy to observe that .
(23) |
where Ham represents the Hamming distance between two binary strings and , which is the count of positions where the corresponding bits differ. The exact implementation of the desired mixing operator presents challenges due to its Hamiltonian, requiring additional resources and non-commuting elements. To address this, we employ an alternative operator , closely resembling . This operator is constructed from , and the inverse for encoding feasibility information of neighboring states into auxiliary qubits that enable the controlled state manipulation. Additionally, the operator includes single-qubit gates for creating neighboring state exploration. Moreover, the feasible oracle is included to determine the feasibility of states by ensuring that only valid states are mixed. Finally, aids in adjusting the amplitudes of states based on feasibility and further refining the mixing process, whereas auxiliary qubits are employed to store feasibility information.

As shown in Figure 4, the process starts from:
(24) |
which implies that the behavior of when acting on a state is to transform it into a new state with additional information encoded in the auxiliary qubits, dependent on the feasibility function and its value at neighboring points. Therefore, the state of can be described as
(25) |
Next, neighboring state mapping is performed using to determine whether the original and neighboring states have the same feasibility. Thus, Equation 24 can be written as
(26) | ||||
Then, the bit flip of the qubit acts as:
(27) |
Therefore, we can describe the encoded feasibility information after applying and based on Equation 25 as follows:
(28) | ||||
Next,
(29) | ||||
Thus, for a given operator, which approximates the original operator, we have
(30) |
Moreover, implements given three ancillary qubits, or more precisely, it is represented as:
(31) | ||||
It follows that
(32) | ||||
where is used to generate . Moreover, is not commute and should use three ancilla qubits. Therefore, the approximate implementation of needs to use the trotter product formula. Meanwhile, using the identity , the state representing the rest of the circuit in Figure 4.
(33) | ||||
where . Furthermore, we optimized with the trotter product formula as
(34) | ||||
Moreover, to maintain the validity of the approximation within the new parameter range, the range needs to be adjusted accordingly to .
As an objective function, we use the value function . Therefore, the corresponding phase separation can be described as follows:
(35) |
4.3.3 Number of Qubit Requirements
The presented illustration implies that using a feasibility oracle with ancilla qubits requires qubits. In contrast, there is an exigency for an additional three qubits, specifically for generating the unitary (Equation 32).
5 Evaluation
This section presents the numerical results by evaluating the effectiveness of the proposed algorithm across different asset numbers along with the impact of parameter configuration.
5.1 Experimental Setup
We present the experimental setup for evaluation, specifically the datasets, hyperparameter configuration, and model setup used to evaluate our proposed approach.
5.1.1 Hyperparameter Configuration
Initially, we implemented the proposed method using the Qiskit library [42], a widely used open-source quantum computing framework. We run the algorithms on the QASM simulator, a tool provided by Qiskit for simulating quantum circuits, which helped us gain insights into the behavior and performance of the algorithms before moving on to the real quantum device. Moreover, we used a fake backend noise from 127 qubits of IBM FakeWashington. While using the real device, we used IBM Nazca, a 127-qubit quantum device, for quantum computations, which offers the opportunity to test the algorithms in a real-world quantum computing environment. The experimental phase involves conducting several tests in which we select varying stocks from , such as Apple Inc. (AAPL), Amazon.com Inc. (AMZN), Alphabet Inc. (GOOGL), Microsoft Corporation (MSFT), NVIDIA Corporation (NVDA), and Tesla, Inc. (TSLA), Netflix, Inc. (NFLX), and Visa Inc. (N). Notably, the selection of these stocks was based on different scenarios, including all cases from two to eight stocks. Postselection, we proceeded with the experimental setup of the proposed method. During the optimization process, we focused on optimizing QAOA, which was achieved by optimizing the angle parameters, i.e., and , using the classical optimizer SHGO [43]. Additionally, we integrated quantum walk to boost optimization by leveraging its benefits for refining the process and achieving superior results.
Hyperparameter | Value |
---|---|
Number of circuit layers | 3 |
Number of trotter steps | 3 |
Financial data provider | yahoo finance |
Portfolio valuation module | PyPortfolioOpt |
Classical optimizer | SHGO |
Framework for architecture implementation | Qiskit |
5.1.2 Problem Setup
To evaluate our proposed method’s performance, we defined our algorithm’s problem based on the number of assets to be optimized (Table 2). First, we selected 2–8 subsets of stocks using the capabilities of PyPortfoliopt [44]. The values represent the expected return of stocks counting from January 1, 2018, to January 1, 2023. The knapsack capacity is the maximum weight, where in our case we set it to be half of the total number of assets. This step clarifies the problem and enables us to tailor our algorithm accordingly. We aimed to evaluate the effectiveness of the QAOA optimization technique in portfolio optimization. To achieve this, we specifically evaluated the performance of the algorithm using the best-known solution (BKS), a result of using a classical algorithm [45], where signifies selection and denotes exclusion. This technique compared the results obtained from our algorithm with those of the classical solution, providing a benchmark for assessing its performance and effectiveness. By undertaking this evaluation, we can gain valuable insights into the capabilities and limitations of the QAOA optimization technique in portfolio optimization.
#Ss | Type | Values | Cap | BKS | #Qs |
2 | MSFT | 0.2430 | 1 | (0,1) | 7 |
AAPL | 0.2602 | ||||
3 | MSFT | 0.2430 | 1 | (0,1,0) | 8 |
AAPL | 0.2602 | ||||
NVDA | 0.2430 | ||||
4 | MSFT | 0.2430 | 2 | (1,1,0,0) | 10 |
AAPL | 0.2602 | ||||
GOOGL | 0.1047 | ||||
NVDA | 0.2430 | ||||
5 | MSFT | 0.2430 | 2 | (0,1,0,0,1) | 11 |
AAPL | 0.2602 | ||||
GOOGL | 0.1047 | ||||
AMZN | 0.0716 | ||||
NVDA | 0.2430 | ||||
6 | MSFT | 0.2430 | 3 | (0,1,0,0,1,1) | 12 |
AAPL | 0.2602 | ||||
GOOGL | 0.1047 | ||||
AMZN | 0.0716 | ||||
NVDA | 0.2430 | ||||
TSLA | 0.4203 | ||||
7 | MSFT | 0.2430 | 3 | (0,1,0,0,1,1,0) | 13 |
AAPL | 0.1870 | ||||
GOOGL | 0.1749 | ||||
AMZN | 0.1898 | ||||
NVDA | 0.2856 | ||||
TSLA | 0.4203 | ||||
NFLX | 0.0797 | ||||
8 | MSFT | 0.2430 | 4 | (1,1,0,0,1,1,0,0) | 15 |
AAPL | 0.1899 | ||||
GOOGL | 0.1780 | ||||
AMZN | 0.1903 | ||||
NVDA | 0.2874 | ||||
TSLA | 0.4203 | ||||
NFLX | 0.0797 | ||||
V | 0.1341 |
5.2 Performance Evaluation
In this section, we present our model performance and its sensitivity analysis.
5.2.1 Model Performance
By meticulously exploring the variable settings within our QWM-QAOA, we identified that a circuit layer depth of and a Trotter step value of yielded the best results. Figure 5 illustrates the approximation ratios for knapsack-based portfolio optimization with varying numbers of stocks (ranging from 2 to 8 stocks) under three different environmental conditions: noise-free (simulator), noisy (using FakeWashington as a simulated backend), and noisy (real device: IBM Nazca with 127 qubits).
-
•
Noise-free (Simulator): The approximation ratios remain very high across all stock configurations, ranging from 100% (for 2 and 3 stocks) to 96% (8 stocks), indicating that the algorithm performs near-perfectly in an ideal, noise-free environment.
-
•
Noisy (Fake Backend): The introduction of noise through the simulated FakeWashington backend results in a decline in performance. The approximation ratios range from 98% to 70%, with lower values observed for larger portfolios. For example, 2 stocks achieve an approximation ratio of 98%, while 6 and 7 stocks drop to 70%. Interestingly, for 8 stocks, the approximation ratio slightly improves to 78%, indicating a non-linear impact of noise for larger portfolios.
-
•
Noisy (Real Device): The experiment is executed on the real IBM Nazca device with the approximation ratios dropping further, ranging from 96% (for 2 stocks) to 51% (for 6 stocks). Surprisingly, for 7 and 8 stocks, the approximation ratios increased to 52% and 55%, respectively.
This performance reduction is due to real-world factors, such as gate errors and decoherence, which exert a more significant impact as the number of stocks increases. This unexpected result hints at the potential for further improvements, even as the number of stocks increases in a noisy environment [46]. These issues highlight the importance of advanced error mitigation techniques, though such methods are beyond the scope of this study [47, 48].

5.2.2 Sensitivity Analysis
We conducted a sensitivity analysis of key parameters using our QWM–QAOA algorithms, such as the circuit layer and the number of trotter steps . These parameters are crucial for shaping the effectiveness of our proposed algorithm. Through a methodical examination and evaluation, we present details of the relationship between these parameters and how much they influence the overall efficiency and resilience of our QWM–QAOA.
-
•
Circuit Layer: Figure 6 shows that as the circuit layer increases beyond the initial value of , the approximation ratio of the diverse portfolio optimization result consistently reaches an impressive result ranging from 100% to 95%, categorically based on the setup cases of portfolio optimization. This empirical evidence emphatically establishes that our performance consistently produces an efficient result even at some circuit layers.
Figure 6: Approximation ratio of the circuit layer is 1–5 across all problems. Remarkably, when , the approximation ratio reaches 100%, indicating that the proposed method is efficient even at the lower circuit layer. -
•
Trotter Step in QWM-QAOA: We aimed to find the parameter , representing the trotter step counts in the QWM–QAOA algorithm while maintaining a constant circuit layer of and optimize , for the resulting circuit of 1–5. Table 3 shows that the approximation ratio for various stock selections increasingly exhibits a better result starting from , ranging from 100% to 95%. When , we obtained efficient optimization results from our proposed method ranging from 100% to 96%. The approximation ratios demonstrate how increasing the trotter steps improves the portfolio optimization results, particularly when , yielding consistently higher performance across different portfolio problem sizes.
Table 3: Performance of QWM-QAOA with varying Trotter steps across different stock selection scenarios. The table presents the approximation ratios for various numbers of stocks, ranging from 2 to 8, using the QWM-QAOA algorithm with different Trotter step values (1 to 5). #Stocks = 1 = 2 = 3 = 4 = 5 2 1.00 0.96 1.00 1.00 1.00 3 1.00 0.60 1.00 1.00 1.00 4 0.77 0.99 0.99 0.99 0.99 5 0.96 0.96 0.98 0.98 0.98 6 0.96 0.97 0.98 0.98 0.98 7 0.96 0.96 0.95 0.96 0.96 8 0.96 0.96 0.96 0.96 0.96
6 Discussion and Limitation
our research provides a novel application of quantum computing, specifically through the Quantum Walk Mixer combined with a Quantum Approximate Optimization Algorithm (QWM-QAOA) integrating with Quantum Fourier Transform (QFT), to address the knapsack-based financial portfolio optimization problem. By transforming the traditional portfolio optimization problem into a binary knapsack problem formulation, we were able to leverage quantum computing to provide efficient and effective optimization strategies, particularly for NP-hard problems. The results from our experiment on noise-free simulation indicate that the QWM-QAOA approach can yield high approximation ratios in both fake backend and real quantum devices, demonstrating the potential of quantum computing in financial optimization tasks. Our study also highlights the importance of various QAOA parameters, such as circuit layer and trotter step , in optimizing the performance of our proposed algorithm. Through sensitivity analysis, we found that a circuit layer of and the number of trotter steps provided the most converged results, with approximation ratios consistently reaching between 100% and 96% in the best cases. This empirical evidence supports the notion that QAOA with the proper configuration, can outperform classical optimization approaches in the context of financial portfolio optimization problems. However, our experiments on real quantum hardware revealed some limitations. The approximation ratio dropped significantly due to unavoidable hardware noise such as gate errors and decoherence errors, with real-device performance yielding ratios as low as 50%. Despite these current limitations of quantum hardware, this finding emphasizes the pressing need for continued research in quantum error mitigation (QEM) techniques and hardware advancements to unlock the full potential of our proposed QWM-QAOA method on portfolio optimization problems in real-world applications.
Noise and Hardware Constraints: The most significant limitation encountered in this study was the impact of overall gate errors when using real quantum devices [49]. While the QAOA algorithm performed well in simulators and fake backend environments, real hardware results showed a substantial drop in approximation ratios (below 50%). This limitation reflects the current state of NISQ devices, which are not yet fully capable of handling complex optimization problems without significant fidelity loss.
Scalability: While our approach worked well for smaller portfolios, scaling QWM-QAOA to larger datasets faces challenges due to the increasing number of required qubits and the limitations of current quantum hardware, such as limited qubit availability and short coherence times. These constraints hinder its applicability to larger portfolio optimization problems. Advancements in quantum hardware and quantum error mitigation (QEM) techniques along with hybrid approaches are needed to extend QWM-QAOA to more complex real-world scenarios.
Limited Dataset: The experimental evaluations were conducted on a small selection of stocks, ranging from two to eight, providing a controlled setting to demonstrate the algorithm’s effectiveness. However, to determine its practical value, future evaluations must incorporate historical data, transaction costs, and market dynamics. Expanding the tests to larger and more diverse datasets will be crucial for assessing the broader applicability of the QWM-QAOA approach in more complex, real-world financial scenarios.
7 Conclusion
In this research, we proposed a novel approach to financial portfolio optimization by leveraging the capabilities of quantum computing, specifically through the Quantum Walk Mixer integrated with a Quantum Approximate Optimization Algorithm (QWM-QAOA). We reformulated the traditional portfolio optimization problem into a knapsack problem, enabling us to address the NP-hard nature of this financial decision-making challenge. Our experimental evaluations, conducted across simulated, fake, and real quantum devices, demonstrated the effectiveness of our approach in yielding high approximation ratios, particularly in noise-free environments. The results of our study reveal that the QWM-QAOA approach is capable of producing efficient portfolio selections, with approximation ratios ranging from 100% to 95% in noise-free conditions and from 98% to 70% on noisy fake devices. However, when tested on real quantum hardware, the results showed a decline in performance due to noise and gate errors, reducing the approximation ratios to approximately 50%. These findings highlight the current limitations of quantum hardware, particularly in dealing with noisy intermediate-scale quantum (NISQ) devices. While our proposed method showed promise, especially in noise-free environments, future work is needed to address the noise in real quantum devices. Error mitigation techniques with further exploration of quantum algorithms for optimization will be crucial in enhancing the robustness and scalability of this approach in real-world applications. Our study contributes to the growing field of quantum finance, offering insights into how quantum algorithms can be applied to complex financial problems such as portfolio optimization.
Code Availability
The code that supports the findings of this study is openly available in the Github repository, QWM-QAOA.
Acknowledgment
This research was supported by the "Regional Innovation Strategy (RIS)" through the National Research Foundation of Korea (NRF), funded by the Ministry of Education (MOE) (2023RIS-007).
References
- [1] L. S. Speidell, D. H. Miller, and J. R. Ullman, “Portfolio optimization: A primer,” Financial Analysts Journal, vol. 45, no. 1, pp. 22–30, 1989.
- [2] F. Vaezi, S. J. Sadjadi, and A. Makui, “A portfolio selection model based on the knapsack problem under uncertainty,” PLOS ONE, vol. 14, pp. 1–19, 05 2019.
- [3] Z. X. Loke, S. L. Goh, G. Kendall, S. Abdullah, and N. R. Sabar, “Portfolio optimization problem: A taxonomic review of solution methodologies,” IEEE Access, vol. 11, pp. 33 100–33 120, 2023.
- [4] S. Martello and P. Toth, “Algorithms for knapsack problems,” North-Holland Mathematics Studies, vol. 132, pp. 213–257, 1987.
- [5] R. Mansini, W. ‚odzimierz Ogryczak, M. G. Speranza, and E. T. A. of European Operational Research Societies, Linear and mixed integer programming for portfolio optimization. Springer, 2015, vol. 21.
- [6] P. C. Chu and J. E. Beasley, “A genetic algorithm for the multidimensional knapsack problem,” Journal of heuristics, vol. 4, pp. 63–86, 1998.
- [7] W. Honggang, M. Liang, Z. Huizhen, and L. Gaoya, “Quantum-inspired ant algorithm for knapsack problems,” Journal of Systems Engineering and Electronics, vol. 20, no. 5, pp. 1012–1016, 2009.
- [8] A. Gunjan and S. Bhattacharyya, “Quantum-inspired meta-heuristic approaches for a constrained portfolio optimization problem,” Evolutionary Intelligence, pp. 1–40, 2024.
- [9] D. Herman, C. Googin, X. Liu, Y. Sun, A. Galda, I. Safro, M. Pistoia, and Y. Alexeev, “Quantum computing for finance,” Nature Reviews Physics, vol. 5, no. 8, pp. 450–465, 2023.
- [10] H. Cao, S. Garg, S. Mumtaz, M. Alrashoud, L. Yang, and G. Kaddoum, “Softwarized resource allocation in digital twins-empowered networks for future quantum-enabled consumer applications,” IEEE Transactions on Consumer Electronics, 2024.
- [11] A. Saxena, J. Mancilla, I. Montalban, and C. Pere, Financial Modeling Using Quantum Computing: Design and manage quantum machine learning solutions for financial analysis and decision making. Packt Publishing Ltd, 2023.
- [12] E. Farhi, J. Goldstone, and S. Gutmann, “A quantum approximate optimization algorithm,” arXiv preprint arXiv:1411.4028, 2014.
- [13] W. v. Dam, K. Eldefrawy, N. Genise, and N. Parham, “Quantum optimization heuristics with an application to knapsack problems,” in 2021 IEEE International Conference on Quantum Computing and Engineering (QCE), 2021, pp. 160–170.
- [14] K. Kea, C. Huot, and Y. Han, “Leveraging knapsack qaoa approach for optimal electric vehicle charging,” IEEE Access, vol. 11, pp. 109 964–109 973, 2023.
- [15] H. M. Markowitz, “Markowitz revisited,” Financial Analysts Journal, vol. 32, no. 5, pp. 47–52, 1976.
- [16] K. P. Anagnostopoulos and G. Mamanis, “A portfolio optimization model with three objectives and discrete variables,” Computers & Operations Research, vol. 37, no. 7, pp. 1285–1297, 2010.
- [17] A. Gunjan and S. Bhattacharyya, “A brief review of portfolio optimization techniques,” Artificial Intelligence Review, vol. 56, no. 5, pp. 3847–3886, 2023.
- [18] C. Y. F. Anton Abdulbasah Kamil and L. K. Kok, “Portfolio analysis based on markowitz model,” Journal of Statistics and Management Systems, vol. 9, no. 3, pp. 519–536, 2006.
- [19] A. J. Kleywegt and J. D. Papastavrou, “The dynamic and stochastic knapsack problem,” Operations research, vol. 46, no. 1, pp. 17–35, 1998.
- [20] D. Du and P. M. Pardalos, Handbook of combinatorial optimization. Springer Science & Business Media, 1998, vol. 4.
- [21] T. Pradhan, A. Israni, and M. Sharma, “Solving the 0–1 knapsack problem using genetic algorithm and rough set theory,” in 2014 IEEE International Conference on Advanced Communications, Control and Computing Technologies, 2014, pp. 1120–1125.
- [22] L. E. Schäfer, T. Dietz, M. Barbati, J. R. Figueira, S. Greco, and S. Ruzika, “The binary knapsack problem with qualitative levels,” European Journal of Operational Research, vol. 289, no. 2, pp. 508–514, 2021.
- [23] D. Delahaye, S. Chaimatanan, and M. Mongeau, “Simulated annealing: From basics to applications,” Handbook of metaheuristics, pp. 1–35, 2019.
- [24] X. Lai, J.-K. Hao, and D. Yue, “Two-stage solution-based tabu search for the multidemand multidimensional knapsack problem,” European Journal of Operational Research, vol. 274, no. 1, pp. 35–48, 2019.
- [25] S. Abidin, “Greedy approach for optimizing 0-1 knapsack problem,” Communications, vol. 7, pp. 1–3, 2017.
- [26] P. D. de la Grand’rive and J.-F. Hullo, “Knapsack problem variants of qaoa for battery revenue optimisation,” arXiv preprint arXiv:1908.02210, 2019.
- [27] C. Patvardhan, S. Bansal, and A. Srivastav, “Quantum-inspired evolutionary algorithm for difficult knapsack problems,” Memetic Computing, vol. 7, pp. 135–155, 2015.
- [28] B. Chen, H. Wu, H. Yuan, L. Wu, and X. Li, “Quantum portfolio optimization: Binary encoding of discrete variables for qaoa with hard constraint,” arXiv preprint arXiv:2304.06915, 2023.
- [29] G. E. Crooks, “Performance of the quantum approximate optimization algorithm on the maximum cut problem,” arXiv preprint arXiv:1811.08419, 2018.
- [30] J. Zawalska and K. Rycerz, “Solving the traveling salesman problem with a hybrid quantum-classical feedforward neural network,” in Parallel Processing and Applied Mathematics, R. Wyrzykowski, J. Dongarra, E. Deelman, and K. Karczewski, Eds. Cham: Springer International Publishing, 2023, pp. 199–208.
- [31] A. Borle, V. E. Elfving, and S. J. Lomonaco, “Quantum approximate optimization for hard problems in linear algebra,” SciPost Phys. Core, vol. 4, p. 031, 2021.
- [32] G. Ausiello, P. Crescenzi, G. Gambosi, V. Kann, A. Marchetti-Spaccamela, and M. Protasi, “Combinatorial optimization problems and their approximability properties,” Complexity and Approximation. Springer-Verlag, 1999.
- [33] L. Zhou, S.-T. Wang, S. Choi, H. Pichler, and M. D. Lukin, “Quantum approximate optimization algorithm: Performance, mechanism, and implementation on near-term devices,” Phys. Rev. X, vol. 10, p. 021067, Jun 2020.
- [34] C. Patvardhan, S. Bansal, and A. Srivastav, “Quantum-inspired evolutionary algorithm for difficult knapsack problems,” Memetic Computing, vol. 7, pp. 135–155, 2015.
- [35] A. Gunjan and S. Bhattacharyya, “Quantum-inspired meta-heuristic approaches for a constrained portfolio optimization problem,” Evolutionary Intelligence, pp. 1–40, 2024.
- [36] A. Awasthi, F. Bär, J. Doetsch, H. Ehm, M. Erdmann, M. Hess, J. Klepsch, P. A. Limacher, A. Luckow, C. Niedermeier et al., “Quantum computing techniques for multi-knapsack problems,” arXiv preprint arXiv:2301.05750, 2023.
- [37] S. Brandhofer, D. Braun, V. Dehn, G. Hellstern, M. Hüls, Y. Ji, I. Polian, A. S. Bhatia, and T. Wellens, “Benchmarking the performance of portfolio optimization with qaoa,” Quantum Information Processing, vol. 22, no. 1, p. 25, 2022.
- [38] S. Marsh and J. Wang, “A quantum walk-assisted approximate algorithm for bounded np optimisation problems,” Quantum Information Processing, vol. 18, pp. 1–18, 2019.
- [39] J. Shunza, M. Akinyemi, and C. Yinka-Banjo, “Application of quantum computing in discrete portfolio optimization,” Journal of Management Science and Engineering, 2023.
- [40] Y. S. Weinstein, M. A. Pravia, E. M. Fortunato, S. Lloyd, and D. G. Cory, “Implementation of the quantum fourier transform,” Phys. Rev. Lett., vol. 86, pp. 1889–1891, Feb 2001.
- [41] P. Chawla, S. Singh, A. Agarwal, S. Srinivasan, and C. Chandrashekar, “Multi-qubit quantum computing using discrete-time quantum walks on closed graphs,” Scientific Reports, vol. 13, no. 1, p. 12078, 2023.
- [42] G. Aleksandrowicz, T. Alexander, P. Barkoutsos, L. Bello, Y. Ben-Haim, D. Bucher, F. J. Cabrera-Hernández, J. Carballo-Franquis, A. Chen, C.-F. Chen et al., “Qiskit: An open-source framework for quantum computing,” Accessed on: Mar, vol. 16, 2019.
- [43] S. C. Endres, C. Sandrock, and W. W. Focke, “A simplicial homology algorithm for lipschitz optimisation,” Journal of Global Optimization, vol. 72, pp. 181–217, 2018.
- [44] R. A. Martin, “Pyportfolioopt: portfolio optimization in python,” Journal of Open Source Software, vol. 6, no. 61, p. 3066, 2021.
- [45] S. Martello, D. Pisinger, and P. Toth, “Dynamic programming and strong bounds for the 0-1 knapsack problem,” Management Science, vol. 45, no. 3, pp. 414–424, 1999.
- [46] S. Johnstun and J.-F. Van Huele, “Understanding and compensating for noise on IBM quantum computers,” American Journal of Physics, vol. 89, no. 10, pp. 935–942, 10 2021.
- [47] M. Alam, A. Ash-Saki, and S. Ghosh, “Analysis of quantum approximate optimization algorithm under realistic noise in superconducting qubits,” arXiv: Quantum Physics, 2019.
- [48] B. Gaur, T. Humble, and H. Thapliyal, “Noise-resilient and reduced depth approximate adders for nisq quantum computing,” in Proceedings of the Great Lakes Symposium on VLSI 2023, 2023, pp. 427–431.
- [49] S. K. Satpathy, V. Vibhu, B. K. Behera, S. Al-Kuwari, S. Mumtaz, and A. Farouk, “Analysis of quantum machine learning algorithms in noisy channels for classification tasks in the iot extreme environment,” IEEE Internet of Things Journal, 2023.