{'fraction_non_alphanumeric': 0.03007410605079502, 'fraction_numerical': 0.008669688466796173, 'mean_word_length': 4.847496844762305, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Portfolio rebalancing experiments using the Quantum Alternating Operator Ansatz

This paper investigates the experimental performance of a discrete portfolio optimization problem relevant to the financial services industry on the gate-model of quantum computing. We implement and evaluate a portfolio rebalancing use case on an idealized simulator of a gate-model quantum computer. The characteristics of this exemplar application include trading in discrete lots, non-linear trading costs, and the investment constraint. We design a novel problem encoding and hard constraint mixers for the Quantum Alternating Operator Ansatz, and compare to its predecessor the Quantum Approximate Optimization Algorithm. Experimental analysis demonstrates the potential tractability of this application on Noisy Intermediate-Scale Quantum (NISQ) hardware, identifying portfolios within 5% of the optimal adjusted returns and with the optimal risk for a small eight-stock portfolio.


I. INTRODUCTION
Gate-model Noisy, Intermediate-Scale Quantum (NISQ) [1] computers are becoming increasingly available in the cloud, and of sufficient scale and fidelity to run interesting quantum algorithms. Quantum algorithms such as the Quantum Approximate Optimization Algorithm of [2] and the Quantum Alternating Operator Ansatz of [3], collectively QAOA, are able to execute on NISQ hardware and provide the potential of advantage at larger scales. Mapping of industry applications onto quantum algorithms has begun, including in financial services [4], and questions are being raised as to the relevance, tractability and performance of quantum approaches to financial services problems in the quantum computing ecosystem.
In this paper we have brought together financial services and quantum software technologists to select, implement, and test a portfolio rebalancing use case using QAOA. We designed and built software based on the knowledge discussed in this paper which demonstrates this application, and executed the software on an idealized simulator of a gate-model quantum computer. We describe this financial application and its relevance, its formulation in both QAOA variants, experimental results, lessons learned, and avenues for further development.

II. PRELIMINARIES
We summarize quantum algorithms and identities upon which this research is based.
A. Binary to spin system identity Conversion from a binary system based on x ∈ {0, 1} to a spin system based on s ∈ {−1, +1} is afforded by substitution using the identity

B. Penalty functions for soft constraints
A real-valued (x ∈ R N , c ∈ R) equality constraint of the form can be converted to a form that can be solved by unconstrained optimization using a penalty function as where • P (x) = 0 when the constraint is met • P (x) > 0 when the constraint is violated • A ∈ R | A > 0 is a penalty scaling coefficient

C. Quantum approximate optimization
The Quantum Approximate Optimization Algorithm [2] has been extended [5] to minimize a polynomial cost function with real-valued coefficients and discrete solution variables. Discrete solution variables can be defined as a binary system x ∈ {0, 1} N or spin system s ∈ {−1, +1} N of N variables.
In its canonical form, QAOA's polynomial cost function is a sum-of-products expression with each product term interacting between 0 and N of the solution variables. If we consider each possible unique interaction then, using the binomial theorem, the maximum number of terms is 2 N . We observe that the total number of non-zero polynomial coefficients in a tractable problem formulation must scale favorably with respect to the problem size, as each coefficient must be calculated during pre-processing and input as a parameter to the QAOA circuit.
Many interesting optimization problems have at most quadratic terms in the polynomial cost function [6]. We restrict ourselves to quadratic problems formulated as a spin system. This results in the Ising model optimization cost function familiar to quantum annealing, as • J ij ∈ R is a coefficient of the upper-triangular coupling matrix J The execution of QAOA is as a variational algorithm where circuit parameters β ∈ [0, π] p and γ ∈ [0, 2π] p are varied to minimize the expectation value ψ 1 |C|ψ 1 , and so measure "good" solutions with high probability where is the initial state of the system, and is the final state of the system. In Eq. (5), unitary evolution occurs via two exponentiated operators: U (B, β α ) = e −iβαB and U (C, γ α ) = e −iγαC , with i = √ −1 being the imaginary number. The gates applied in a quantum computer iterate as α = 1, · · · , p due to the right-associativity of these operations. Parameter p ∈ N is the number of parameterized repetitions in the resulting quantum circuit, and relates linearly to its depth. The quantum circuit hyper-parameter space of β and γ also increases linearly with p, and is optimized classically.
For our case of the Ising model cost function in Eq. (3), the cost operator is defined in the Pauli-Z basis (σ z ) as and is not unitary but is Hermitian, allowing it to be used as the expectation value observable.
For unconstrained optimization problems, the Quantum Approximate Optimization Algorithm defines a mixing operator that explores all 2 N combinatorial solutions. It is defined in the Pauli-X basis (σ x ) [2,Equation (3)] in a way physically similar to quantum annealing, as For constrained optimization problems, the Quantum Alternating Operator Ansatz suggests B be designed to constrain the feasible subspace of solutions. One example of this is a parity mixer, which uses alternating application of Pauli-XY mixers to odd and even spin subsets [3, Equations (7)-(9)], we summarize as with and where I is the identity transform and all arithmetic is modulo N .
Such a mixer can, for example, be used to realize onehot encoding of categorical variables and has the potential to improve application performance over the original QAOA.

III. PORTFOLIO REBALANCING APPLICATION
Portfolio rebalancing is a periodic asset management process in which traders maintain an institutional portfolio's net value, adjusting asset mix based on institutional advice and hedging risk as market conditions change. Rebalancing can be achieved using a combination of financial instruments including long and short positions in assets, and their derivatives (put and call options). The frequency of institutional rebalancing depends on many factors including market volatility, risk profile, asset liquidity and trading costs. It may be performed daily, weekly or monthly. The computational load of rebalancing, including the associated risk calculations, means that it is typically performed overnight. This creates an opportunity for new methods to significantly impact institutional process. For example, a significant speed up afforded by functional quantum computers could enable financial institutions to be more agile in their decision making, responding in a more timely way to changes in market conditions.

A. Previous work
Discrete portfolio optimization of a Markowitz model portfolio [7] is proven to be NP-complete when described using integer positions [8]. The applicability of quantum computing to discrete portfolio optimization has been demonstrated using quantum annealing [9] and specialized gate-model algorithms that require quantum access to the historical record of returns [10]. In a recent review, portfolio optimization has not yet been evaluated using QAOA [4, Section III]. The potential for QAOA to provide guarantees on performance for problems such as MaxCUT has been demonstrated [11]. The work of [3] realizes hard constraints within QAOA using techniques available on today's gate-model NISQ computers. A similar concept has been proposed for quantum annealing [12] but is not yet realized in hardware, meaning annealing solutions must use soft constraint emulations based on penalty functions [6].

B. Contribution
Our contribution is the experimental evaluation of the tractability and performance of discrete portfolio optimization under constraints for a multi-period portfolio rebalancing scenario, implemented using QAOA on a simulator of a gatemodel quantum computer. We design and implement a softconstraint formulation based on [2], and compare it to a hardconstraint formulation based on [3]. We choose an idealized simulator of a gate-model quantum computer [13] as a first step in understanding algorithm and application performance, and with the intent of evaluating on NISQ computers in the future. We choose portfolio rebalancing as an application of relevance to financial services institutions, drawn from our industry experience.

C. Relevance
Discrete portfolio optimization under constraints accurately models several characteristics of institutional trading in a portfolio rebalancing scenario.
The first characteristic is that of trading in discrete lots, where the asset class can only be traded in positive integer quantities, and the dollar value of a single lot is significant with respect to the total portfolio value. Asset classes such as bonds can have this property. In this situation, the closest integer position to the continuous form solution can be a poor approximation, and discrete optimization has the potential to gain a few basis points in the trading outcome.
The second characteristic is in modeling uncertainty. While a full treatment of uncertainty in the Markowitz model portfolio covariance matrix requires semi-definite programming and results in robust portfolio optimization [14], an approximation is to discretize the portfolio position space for each asset based on its own market variance. This provides some level of robustness to non-stationary market processes that are a known limitation in the Markowitz model.
The third characteristic is in representing the investment constraint, where the total portfolio value must be approximately maintained throughout the rebalancing process. This is common to the canonical Markowitz model discrete portfolio optimization problem [15], modified in a rebalancing scenario to consider the relative position with respect to previous, rather than the absolute position in the optimization process.
The fourth characteristic is in modeling trading costs, which are only accrued in the case that trading occurs on an asset. This non-linear function includes a step-change in cost which can be naturally represented with a discrete logic function. In our rebalancing scenario, we will assume that trading costs are fixed for any trade size.
Finally, other institutional trading practices can apply constraints to trading, such as the maximum number of assets that may be held 1 , minimum allocation sizes, and constraints on trading asset classes in a multi-class portfolio. These will not be expanded further. In this paper we will assume that a perasset discrete lot size can be selected based on the first two characteristics presented here, and we will conduct a discrete portfolio optimization under constraints that includes trading costs and the investment constraint.

IV. PORTFOLIO REBALANCING FORMULATION
We define the problem of portfolio rebalancing to be a discrete portfolio optimization problem, as where 1 Commonly referred to as the cardinality constraint.
• z = {−1, 0, +1} N is the solution vector of discrete portfolio asset positions to be held, representing long (+1), short (−1) or no-hold (0) states • C RR (z) is the normalized risk-return function • C TC (z) is the normalized trading cost function • N is the number of available portfolio assets and subject to the investment constraint where • D is the net total of discrete lots to be invested 2 The risk-return function is based on the Markowitz model [7], as is an asset manager control parameter to favor low risk (λ = 1) or high return (λ = 0) • σ is the normalized asset returns covariance matrix • µ is the normalized average asset returns vector The trading cost function is based on a fixed trading cost model, as where • y = {−1, 0, +1} N is the previous portfolio position • δ(z) is the discrete Dirac delta function, where δ(z) = 1 if z = 0, and δ(z) = 0 otherwise, with z ∈ Z • T is the normalized cost incurred if an asset is traded

A. Risk-return function encoding
We choose a two-spin encoding for z i ∈ z by first defining independent binary decision variables for holding long and short positions, as where decides upon a short position and then converting binary to spin variables as in Eq. (1) The four possible spin states are illustrated in Table I. The degenerate encoding of x − i = 1, x + i = 1 will be penalized by the encoding of the trading cost function in Section IV-B.
Netted off long and short T 0 T T † Degenerate solution of trading long and short is penalized.
Substitution of the spin variable formulation Eq. (14) into Eq. (11) yields the spin-system risk-return cost function

B. Trading cost function encoding
We design a spin-system trading cost function to realize the non-linear function of Eq. (12) and generates the combinatorial value table of Table II. This conditional expression can be converted into an unconditional expression by designing coefficient multipliers based on y i that provide equivalent behavior C. Investment constraint encoding (soft constraint form) The investment constraint of Eq. (10) can be converted to a penalty function using Eq. (2), as where the penalty scaling coefficient A is determined experimentally.
Substitution of the spin variable formulation Eq. (14) into Eq. (18) yields the spin-system investment penalty function D. Investment constraint encoding (hard constraint form) The investment constraint of Eq. (10) can be realized using a pair of parity ring mixers [3] acting independently on the long and short decision variables of Eq. (13). Entanglement between the long and short positions is used to further constrain the set of feasible outcomes to those that have the correct net parity, and thus the correct net investment.
This configuration is designed beginning with the observation that, given a system of N assets encoded as Eq. (14) and a net investment of D as per Eq. (10), there are K discrete parity bands where the long and short positions can correctly net off, calculated as The design objective becomes to ensure that the long and short mixers can exchange in the subspace of any of these parity bands, but only in a way where outcomes are consistent with the net investment constraint. This is achieved using a combination of computational basis states that establish the minimum long position of D lots, and Bell states whose entanglement assures the required parity relationship across the remaining assets. The Bell states ensure that each additional long position in the solution is accompanied by a short position somewhere in the portfolio.
As in [3], only one feasible initial state |ψ 0 needs to be prepared this way, as where qubit state pairs are represented as |x − i x + i . This configuration provides a feasible initial state whose preparation is likely to be efficient on NISQ hardware. However, it does not provide a uniform solution probability across parity bands. Instead, a binomial distribution is created based on the population of possible solutions, with probability of measurement where is the count of shorted assets We acknowledge the potential for solution bias due to this initial configuration. We consider it an exercise for future development on NISQ hardware to consider this in concert with issues of circuit depth, as any improved solution will need to come within the coherence time of the target hardware.  A depiction of the initial state and algorithm configuration is provided in Fig. 1. For the same problem size, the initial parity band probability distribution is provided in Table III.

E. Soft constraint formulation using the Quantum Approximate Optimization Algorithm
The portfolio rebalancing application can be realized using an unconstrained optimization approach by combining the spin-system risk-return cost function (Eq. (15)), trading cost function (Eq. (17)) and investment penalty function (Eq. (19)), as Solving this formulation using the Quantum Approximate Optimization Algorithm involves its execution as described in Section II-C. The QAOA cost operator is of the Eq. (6) form, generated by substitution of the Pauli-Z operator σ z i for each spin s i in Eq. (23). The QAOA unconstrained mixing operator is of the standard Eq. (7) form.

F. Hard constraint formulation using the Quantum Alternating Operator Ansatz
The portfolio rebalancing application can also be realized using a constrained optimization approach by combining the spin-system risk-return cost function (Eq. (15)) and trading cost function (Eq. (17)) as C hard (s) = C RR (s) + C TC (s) and whose investment constraint is realized as described in Section IV-D with an entangled pair of parity mixers. Solving this formulation using the Quantum Alternating Operator Ansatz involves its execution as described in Section II-C. The QAOA cost operator remains of the Eq.

V. PORTFOLIO REBALANCING EXPERIMENTAL RESULTS
We execute the portfolio rebalancing formulation upon an idealized simulator of a gate-model quantum computer to assess its tractability prior to execution on NISQ hardware. We do this in a sequence of steps designed to verify the application is implemented correctly.

A. Experimental data
The input data for this experiment is the daily returns for share prices on the Australian ASX.20 market in 2017. The data covered 20 stocks and 252 trading days. Summary statistics for the daily returns are presented in Table IV.
Data for N = 8 stocks (AMP, ANZ, BHP, BXB, CBA, CSL, IAG, MQG) were selected for use in the experiments. Daily average returns (µ i ) can be found in Table IV. The asset returns covariance (σ ij ) can be found in Fig. 2. By convention, covariance σ ii = σ 2 i where σ i is the standard deviation (S.D.). For all experiments, a target holding of D = 4 discrete lots is used, as per Eq. (10).

B. Calculation of penalty scaling
A simple method to calculate penalty scaling coefficient A in Eq. (18) was adopted, as where C(s) = C RR (s) + C TC (s) is the unconstrained part of the soft constraint formulation of Eq. (23). This ensures that the value of C soft (s) for any unfeasible solution is greater than the energy for all feasible solutions. The performance of this setting for realizing feasible solutions will be validated experimentally.

C. Investigation of the solution space
We begin by evaluating the solution space using brute force methods. Given N = 8 stocks, the cost function encoding requires 16 spin variables, and presents a combinatorial space of 2 16 = 65536 solution states. Of these, only 1820 (2.78%) are feasible, determined by the investment constraint of Eq. (10) for D = 4.
In finance, it is common to plot feasible portfolio solutions against the accumulated values of expected return and risk from Eq. (11) 3 , independent of risk-return control parameter λ. This is illustrated in Fig. 3. As λ is varied, the optimal discrete solution point changes, creating a discrete efficient frontier of available portfolio solutions.

D. Investigation of a single QAOA circuit
Before enabling the outer classical optimization loop of QAOA, we first investigated the behavior for a single iteration of the Quantum Approximate Optimization Algorithm circuit on formulation Eq. (23). The penalty scaling coefficient is calculated using Eq. (25) as A = 0.03. The risk-return control parameter is set as λ = 0.9, and trading cost T = 0. We vary β and γ angles for a p = 1 execution of Eq. (5), and obtain the results in Fig. 4.
Slow variation in expectation value is observed for changes in γ. This occurs due to a problem with cost function scaling. For effective mixing of the initial superposed states |ψ 0 in Eq. (4), the cost function C must be scaled close to unity. If C is small, then γC is small, and the z-rotation of U (C, γ) =  e −iγC is also small 4 . This has the effect of a small change on expectation value for p = 1 as illustrated in Fig. 5, and slow mixing to the complete solution space for larger p.
We address this issue by scaling the input data to annualized returns instead of daily returns. Annualized returns are calculated from daily returns by multiplying both the average µ i and covariance σ ij by 250. The penalty scaling coefficient is recalculated as A = 0.75. Running the experiment again we obtain the results in Fig. 6. Initial mixing is observed to be improved, evidenced by the periodic structure in the data.

E. Evaluation of QAOA algorithms for a single portfolio
We enable the outer classical optimization loop for both the Quantum Approximate Optimization Algorithm and Quantum Alternating Operator Ansatz formulation of the problem. We investigate the cost function statistics for solutions found by these algorithms as an initial representation of the value of the resulting portfolio, for a range of quantum iterations p. We include brute force baseline statistics, generated from a uniform distribution across all possible and all feasible solutions. All statistics for QAOA experiments are calculated across 20 randomly seeded simulated runs.
The cumulative probability of the cost function is illustrated in Fig. 7. All algorithms show a significant improvement in results compared to random draw from the solution space. The Quantum Approximate Optimization Algorithm returns feasible solutions with between 33% and 66% probability, validating the choice of penalty scaling coefficient A. Interestingly, performance is best for lower p, and may be an artifact of the Nelder-mead optimizer. The Quantum Alternating Oper- ator Ansatz formulation returns feasible solutions with 100% probability, verifying the correct implementation of the mixing function and the expected simulated behavior.
The cumulative probability of the cost function restricted to the domain of feasible solutions is illustrated in Fig. 8.
The Quantum Alternating Operator Ansatz shows superior performance with respect to a random selection of feasible solutions, validating that not only is the algorithm assisting with identification of a feasible solution in the large combinatorial space, but that it is optimizing for the cost function within that subspace. The difference in performance to the original Quantum Approximate Optimization Algorithm is significant, highlighting the importance of hard constraint design in solving constrained problems using QAOA.

F. Evaluation of QAOA algorithms for portfolio rebalancing
We broaden the experiment to use the QAOA algorithms for a multi-period rebalancing scenario. In this scenario we consider average annualized returns calculated independently for each of the first 6 months in 2017, and rebalance the portfolio once per month. Trading costs are included at T = 0.015, which is of the same order of magnitude as the annualized returns of the available stocks. The monthly statistics for the annualized returns lead us to set A = 2.5 as per Eq. (25), due to the greater extremes in minimum and maximum values that occur over the shorter period.
We calculate metrics of interest to traders and quantitative analysts, including the total number of trades, the portfolio returns adjusted for trading costs, and the average risk over the period. We test using both the Quantum Approximate Optimization Algorithm and Quantum Alternating Operator Ansatz formulations, and compare to the optimal trajectory determined by the brute force methods. Note that optimization is performed independently at each time-step, meaning that the optimal trajectory is not necessarily the one discovered by the brute force methods, as multi-period market foresight is not available in this scenario. Fig. 9 shows the total number of trades performed over 6 months of rebalancing. From zero initial holdings, the maximum number of trades to reach the target D = 4 is 8 trades; 6 long and 2 short. For the remaining 5 months, the maximum number of trades is 4, netting off changes in long and short positions. This puts an upper limit on the number of trades over 6 months at 28. We observe high volumes of trading for the λ = 0 case of maximizing returns, consistent with chasing returns month-to-month that is expected when the trading cost is similar to the available returns. As λ is increased to favor minimizing risk, trading activity decreases, consistent with the observation in Fig. 2 that there are not very many pairs of stocks with the negative correlation required to reduce risk. Qualitatively both variants of QAOA are observed to perform close to optimal, with the exception of one poor result from the original QAOA formulation. Fig. 10 shows the adjusted portfolio returns µ · z − C TC (z) over 6 months of rebalancing. This plot shows the improved performance of the Quantum Alternating Operator Ansatz in achieving good returns when instructed (λ = 0), measured as within 5% of the brute force result for this experimental campaign when p = 4. Superior performance is also observed for p = 4 over p = 2 for both QAOA variants, consistent with that expected from deeper circuits with a larger hyperparameter space. Adjusted returns vary about zero when returns are excluded from the objective. Fig. 11 shows the average risk √ z T σz over 6 months of rebalancing. This plot again shows an improved performance for the Quantum Alternating Operator Ansatz that, when directed (λ = 1) to reduce risk, found the optimal solution for each of the 6 months for this experimental campaign when p = 4. The lower risk for p = 2 is an artifact of the trading trajectory, where one sub-optimal decision can lead to alternatives with a net benefit.

VI. CONCLUSION AND FUTURE WORK
In this work we have shown the application of QAOA to a portfolio rebalancing use case of interest to the financial services industry. We established the characteristics and relevance of the use case and highlighted the potential for quantum computing to impact institutional processes. We formulated two approaches to solving this exemplar application, one using soft constraints and the Quantum Approximate Optimization Algorithm, and another using hard constraints and the Quantum Alternating Operator Ansatz. For the hard constraint formulation, we designed a mixer based on the entanglement of parity mixers across long and short decision variables, which is novel in this space and demonstrates our process for tailoring existing quantum algorithms to industry use cases. We undertook an initial experimental campaign on an idealized simulator of a gate-model quantum computer to verify our implementation and to establish use case tractability.
The experimental results highlighted key issues of effective use of QAOA, including input data scaling. They qualitatively established performance advantages for the Quantum Alternating Operator Ansatz, and performance for both adjusted returns and average portfolio risk, being two key metrics of interest to industry analysts. Experimental analysis demonstrates the potential tractability of this application on Noisy Intermediate-Scale Quantum (NISQ) hardware, identifying portfolios within 5% of the optimal adjusted returns and with the optimal risk for a small eight-stock portfolio when noise and coherence time limitations are ignored.
These encouraging results warrant further investigation, including (i) circuit depth via hardware resource analysis; (ii) impact of noise via simulated performance analysis; and (iii) validation on current generation NISQ hardware. These steps help uncover the full-stack parameters critical to this use case's trajectory towards potential quantum advantage.