Portfolio Optimization of 60 Stocks Using Classical and Quantum Algorithms
PPortfolio Optimization of 60 Stocks UsingClassical and Quantum Algorithms
Chicago Quantum ∗ email the authorsAugust 21, 2020 Contents
Abstract
We continue to investigate the use of quantum computers for build-ing an optimal portfolio out of a universe of 60 U.S. listed, liquid equities.Starting from historical market data, we apply our unique problem formu-lation on the D-Wave Systems Inc. D-Wave 2000Q TM quantum annealing ∗ Jeffrey Cohen, Alex Khan, Clark Alexander a r X i v : . [ q -f i n . GN ] A ug ystem (hereafter called D-Wave) to find the optimal risk vs return port-folio. We approach this first classically, then using the D-Wave, to selectefficient buy and hold portfolios. Our results show that practitioners canuse either classical or quantum annealing methods to select attractiveportfolios. This builds upon our prior work on optimization of 40 stocks Our work is inspired by the notion that we can find attractive investment port-folios from a universe of US equities leveraging a quantum computer. As wescale the problem with the number of equities analyzed (portfolio choices are2 n ), we investigate whether quantum annealing can scale up vs. classical meth-ods and select a reasonable sized grouping of attractive portfolios, as opposedto just one ideal solution.We advanced our classical methods. We now have five methods to find theideal portfolio from 60 stocks in under a minute. This raises the bar for quantumannealing, which takes about 0.13 seconds (or ∼ , µs ) to sample 200 to500 times within one run (to find the best N out of 60 stocks). The D-Wavetime, 21 seconds, is an accumulation of all runs used in this research in ourprimary account, and the results are an accumulation of all valid portfoliosfound in this research.We retain our prior formulations; The Chicago Quantum Net Score and theChicago Quantum Ratio defined by the followingCQNS( R w , α ) = V ar ( R w ) − E [ R w ] α (1)and CQR( R w ) = Cov im ( R w ) σ ( R w ) (2)where R w is a weighted portfolio, α > Cov im is the covariance of our portfolio against the entire market, whichwe take as the S&P 500 for this article.In this paper we will provide our progress, and setbacks, with classical meth-ods, then focus attention on our quantum annealing on the D-Wave DW 2000Q 62,048 qubit, D-Wave 2000Q lower-noise system, with the [16,16,8] Chimeratopology. We will then provide a comparative analysis and discuss the scale-uppotential of the D-Wave. We performed our research during a time of market increases for the largestcompanies, and a relatively low interest rate environment. Our analysis useda risk-free rate of 1%. The markets have seen a rise of 18.60% over the pastyear, when taken as the average of the increases of the four equity indices weuse: S&P 500, Nasdaq Composite, Russell 2000 and Wilshire 5000. The range2f β for the 60 stocks was [0 . , . We start with a Monte Carlo random sampling analysis to understand the high-level shape of the energy landscape before we look to the different methods tosolve it. We score in excess of 220 thousand portfolios across all portfolio sizesand store the average, minimum and maximum CQNS values which we can plotand review. As shown in 1 the blue bar shows the CQNS average, which isstable across portfolio sizes, which implies there is no bias toward any portfolioof a particular magnitude. Additionally, in green we see the CQNS minimumvalues which have a few special cases, which are highly attractive portfolioswhere the expected return greatly outweighs the expected risk. The shape maybe different for each set of stocks analyzed.Figure 1: CQNS minima and averages
We keep track of our random samples in an array which holds the minimum,maximum and average CQNS score for each size portfolio analyzed. We initial-ize this with random samples in a discrete distribution (centered around N/ N/ . × possible3ombinations. We cannot count on sampling all of them. However, we ran thisexperiment twice. In one case we found the best answer and in another we foundthe 2 nd best answer; both in 24 seconds. Again, this only worked because thebest answer was in a tail of the portfolio sizes with very few possibilities, andthe random sampler can find them.Like in the simulated annealing case, the Monte Carlo analysis has the great-est range of CQNS values at the smallest portfolios (best and worst portfolios).The range and relative attractiveness narrows as we analyze larger portfoliosizes. In the graphics, the sequence moves from small to large portfolios. A genetic algorithm looks to bring the best attributes (stocks) forward from twoportfolios (parents) by a process of breeding them and creating new portfolios(children and mutations) that we then score. We keep the best X portfolios asscored by the CQNS as parents in the next generation, then breed again.Our genetic algorithm (GA) is custom coded to start with an initial popula-tion of parents (either 456 random portfolios or seeded with D-Wave solutions).We tune it to run for 40 generations and pass the 40 best solutions (equal orbetter values only) to the next generation. We breed a ratio of 3:2 children tomutations. Experimentally, both solve the problem of optimizing the 60 assetportfolio quickly. In our last run, the GA (456 random) took 7 seconds and GA(2,588 D-Wave) took 48 seconds to find the best solution. Typically, however,the GA (D-Wave) runs 20% faster than GA (random) as we start with a smallerand better scoring initial population.
A simulated annealer models the temperature-based evolution process, wherethe algorithm is looking for the lowest energy solution where the ability to jumpto a new interim solution outside of a local minima decreases as the systemcools. At higher temperatures, it is more free to tunnel or jump to neighboringenergy levels and look for deeper energy minima. As the temperature “cools”,it becomes harder to jump far and we look for the best solution in that neigh-borhood. In this model, the Chicago Quantum Net Score is a fixed multiple ofthe energy level at each ( N of 60-asset) QUBO. By minimizing the energy level,we find the best CQNS and investment portfolio.Our simulated annealer is custom coded in Python 3 in about a page of code.In our tuned version, it finds the optimal 60 asset solution some of the times,and a good solution otherwise. We can tune it to run longer, which increasesthe frequency of success. In our last run, it found the optimal portfolio from 60stocks in 15 seconds.We tune our simulated annealer with four parameters. (1) When to jumpto a neighboring solution. When the temperature is warm, sometimes our algo-rithm jumps even when the score is slightly worse. (2) Initial temperature andminimum temperature which determines the temperature range for annealing.43) Cooling rate determines how fast the temperature cools per cycle, and isused to determine the number of annealing cycles T max − T min cooling rate , and (4) the num-ber of annealing trials, or as D-Wave calls them “sweeps” per annealing cycle.We tune this mix to maximize the frequency of finding the optimal solution inthe shortest time. This is an ad-hoc exercise.We also use the D-Wave Simulated Annealer as an alternative sampler. Inour most recent runs, it finds the optimal portfolio that we allowed it to find in11 seconds, but modifies the energy level of that portfolio. We run the simulatedannealer by specifying the range of portfolio sizes, and resulting QUBO, to runthrough the annealer. Normally we run [2 , , β range,or inverse of the temperature, at [0 . , β scheduleof type “geometric.” With these settings, we run for 11 seconds, find 168 outof 9,600 trials, and see the 2 nd best result (and the best we allow it to find),repeatedly in the results. If we want to look at good portfolios at different sizes,like we can with the quantum annealing answers, we see valid portfolios at manyportfolio sizes.In the graphic below we see that the smaller portfolios (run in order of size),have the widest spread, and the best possible results. As we get larger, we seean almost asymptotic tightening of the CQNS scores in the middle. We see thiswith most samplers we use. (a) Simulated Annealing Solutions (b) Monte Carlo Simulation Figure 2: Simulated Annealing vs Monte Carlo Sampling5 .4 D-Wave Tabu Multistart MST2 Sampler
The D-Wave Tabu Sampler was run against our QUBOs and we saw the leastattractive portfolios from this method. The sampler picked most of its solutionsfrom the 20 to 40 asset size portfolios despite being run against the differentQUBOs with the penalty functions. We also see that the Tabu sampler startedby finding very large (poor) CQNS values, and quickly reached a plateau of itsbest answer. Unfortunately, the best Tabu scores found were worse by a factorof 10 or more. (a) Assets Chosen vs QUBO size (b) Portfolio Sequence
Figure 3: On the right, we see the Tabu sampler picked portfolio sizes between20 and 40 regardless of the desired portfolio sizes, and penalty functions. Onthe left we see CQNS values chosen by the Tabu sampler, and how it starts withpoor (high) values.We set the sampler to run from [2 ,
60] assets, with 200 reads per QUBO, ascale factor of 1, a maximum of 20 µs to run, and a tenure of 50. The tenure isthe number of answers to store in memory to save time in the run. Like withthe D-Wave quantum annealer, we keep and accumulate valid portfolios fromeach size portfolio, and in 11,600 trials we had 190 valid portfolios found. Thefinal run took 267 seconds. We have an open question of whether increasingthe run time, reads per QUBO, and lowering the tenure would help us findbetter answers. We had initially set the Tabu Sampler to run longer with thesesettings, but did not see better results.6 .5 D-Wave Hybrid Sampler At this point we do not see valid results from the hybrid sampler. It is more ofa “black box” solver for us where we can set a few parameters and feed it thesame 60 × ×
60 matrix used by the other methods. We set it to run acrossportfolio sizes using the same QUBO as the other methods, and it found novalid portfolios that match the size required. It does find “good” portfolios, butthe CQNS scores are incorrect due to the penalty we apply. (a) 10 assets (b) 20 assets(c) 30 assets (d) 40 assets(e) 50 assets
Figure 4: Charts showing resulting energy levels from QUBO ( N =10 , , , ,
50 assets) before (blue) and after (green) affine transformationbased on random sampling. 7imilar to our simulated annealer, a quantum annealer modifies the quantumfluctuations of a physical set of qubits to allow the spin of the qubits to jumpto a neighboring solution to find a lower energy level. The resulting energylevel, which we convert to a CQNS score, is the value the quantum annealer isminimizing by making those jumps between solutions. At the end, the systemreads the energy and spin of the qubits, rounds up or down, does a majorityvote if there is a chain break, and outputs a string in { , } (one for eachstock), the energy of the system, and the value of the chain break, if any. Were-factor the energy to a CQNS score, and append the values to an output file.We build a 60 × ×
60 “bigmatrix” of values which load the negative ofthe expected return content on the linear terms, and load the variance andcovariance content on the quadratic terms.We then apply an affine transformation to the values (shift) so the non-desired number of assets have a penalty. We set the affine transformation withthree points. The zero asset point must have an energy value of zero, the desiredasset count must have an accurate count, and we can increase the energy levelfor all other points. We create a shape like a pulley in the energy values thatresult from executing the QUBO in simulation or in D-Wave.In figure 4 we see the 10, 20, 30, 40 and 50 asset QUBO energy landscape. Webend the shape of the curve so the desired number of assets is centered aroundthe lowest energy levels, while still staying accurate at that number of assets,during a small random sampling of CQNS values. We ground the 0,0 point forzero assets, set the point for the number of assets desired to be accurate, andvary the energy level of the 60,60 asset point to the positive, or a penalty.Sometimes creating an affine transformation with the apparent shape weneed is not enough. In other words we might not get any matching results forthe desired assets. As we run our QUBO on D-Wave, we also visualize theresults of all the samples received back from D-Wave. We use that visualizationto further tune the shift of the matrix. In the chart below, we see the orangepoints which indicate the assets desired by each QUBO run. The blue pointsare the size of the portfolios returned by D-Wave. In case of overlap, we see theorange dots. You can see that as we exceed 36 assets, the portfolios receivedwere significantly smaller than desired, which required us to further adjust ourshift values.After we apply the affine transformation, we scale the matrix values to be-tween [ − . , .
9] before we send it to D-Wave. Experimentally we find D-Wavedoes better when we apply the initial scaling to the data. We believe this isbecause D-Wave does additional scaling while it feeds the data to the quantumannealer, and if the values are divergent enough may apply different scaling fac-tors to the linear and quadratic terms. This would nullify our CQNS score andthe predictive ability of our model. The D-Wave annealer can accept H Rangevalues between [ − ,
2] in the linear term and J Range values between [ − . , . a) Quadratic Affine Transformation of tri-als size 2 to 50 (b) Graduated Affine Transformationsof trials size 2 to 50 Figure 5: On the left: two trials: 2-50: resulting portfolios always lower thandesired number of assets. 20-40: after shift shows results in the number of assetsdesired. On the right: displaying how a small shift in the affine transformationallowed portfolios detected at the higher end 40 assets to increase. The desiredeffect is having as little spread as possible around a centered orange line.finds smaller portfolios despite the penalty on them. In our research on 60assets, the largest valid portfolio we received from the D-Wave was 47 assets.We believe we could continue to adjust chain strength and annealing time toincrease our chances of a matching portfolio. However, we believe we may needto further refine the QUBO for larger portfolio sizes (e.g., 45 or more assets)to continue to scale to 100 or more assets. This assumes we believe the largestportfolios can also be the most efficient.The challenge is our quadratic values become too small relative to the linearterms. At 59 assets, the linear terms still vary from [ − , . . , . N/ N have increasingcovariance values on the quadratic terms instead of decreasing as they do now.We then convert the 60 × ×
60 shifted matrix to QUBO formulations which9 a) bigmatrix for 59 assets(b) heat map for big matrix with 59 assets
Figure 6: Heat map for a big matrix with 59 assets.are individually sent to D-Wave. D-Wave applies its own scaling to achieveacceptable H range and J range values. This same matrix is used for all ofour classical models which require a matrix as input (e.g., simulated annealer,TABU sampler, and the hybrid solver).We run the quantum annealer repeatedly against our QUBOs in this exper-iment and accumulate valid portfolios (where number of assets chosen matchesthe number of assets desired in that QUBO). Our initial runs, which accumu-lated 116 values, were on the 30 asset QUBO and were intended to calibrate andtune the D-Wave and parameters we use. We adjust settings for chain strength,post processing, shift, scale, annealing time, reduce intersample correlation, andto look at the resulting solutions, and information about the programming ofthe QUBO on the qubits. We use the D-Wave Inspector to better understandthe solution space and the loading of the QUBO. Including the calibration, we10 a) bigmatrix for 2 assets(b) heat map for big matrix
Figure 7: Heat map for a big matrix with 2 assets.accumulate a total of 3725 valid portfolios with portfolio size ranges of [2 , . , .
0] against a default value of 1.0. Chainstrengths > . ×
60 QUBO shifted for 58 assets after embedding 8,or programming, the QUBO onto the D-Wave qubits and before the annealingprocess begins. The yellow line traces the path of one asset being embeddedon multiple qubits in a chain, with covariance connectivity to all other stocks.This embedding is required to ensure our covariance relationships are retainedwith the limited number of connections available between qubits in the actualhardware.We also found a relationship between annealing time and number of validportfolios found in each run. We vary our annealing time in [20 , µs , against11igure 8: The connectivity of D-Wave in the [16,16,8] topology for 58 of 60assetsa default of 20 µs . The best results came from larger portfolios [40 ,
47] andthe smallest portfolios [2 ,
4] at 100 µs and chain strength of 2. We did not tryannealing times > µs , although they can go as high as 2 , µs . Longerannealing times, and higher chain strength values, might be the way to producevalid solutions at the largest portfolios [48 , − µs . In this paper, we use the CQNS, and the related Chicago Quantum Ratio, asa proxy for the classical method of portfolio optimization. We consistently findthat the D-Wave system, with just a few valid portfolios, picks portfolios that12re on or ahead of the efficient frontier as found through random sampling.In this case, 414 valid D-Wave quantum annealing portfolios compare favorablyagainst 40,000 random portfolios, and outperform at the higher risk (or standarddeviation) levels seen below in 1011. When we build investment portfolios, wefind the D-Wave selected CQNS portfolios tend to be relatively more risky thanCQR portfolios while both are still highly efficient.Figure 9: Above: The comparison of 414 quantum portfolios vs 40000 MonteCarlo samples using the Sharpe ratio. Below: The comparison of 414 quantumportfolios vs 40000 Monte Carlo samples using CQRIn the graphic10, you can see the initial 116 valid portfolios with 30 assets(out of 60) that we used for calibration compared to our 221,660 Monte Carloresults. The quantum portfolios, in red, have relatively low CQNS values (-13.0146 vs. -0.0437 for top 10 portfolios). D-Wave appears to be picking efficientportfolios, even out of a population of average results. The blue dots reflect thegenetic algorithm and the simulated annealing results. They reflect the best, orideal values, and a sample of the values from the previous generations.Figure 10: Several Methods using CQRAfter accumulating 2,588 valid portfolios, we can see that the red dots cover asignificant portion of the efficient frontier. The quantum points provide investorswith a broad coverage of the efficient frontier after selecting just 2,588 portfolios. (a) CQR (b) CQNS
Figure 11: Several Comparative methods with different scores.14
Comparative Analysis
We measure success in whether the different methods find the ideal portfolioand how long each method takes. Six methods 12, including D-Wave, found theideal portfolio, which is the portfolio we believe has the lowest (best) CQNSscore. For four of the methods 13, we had Python time the run duration. Forthe D-Wave quantum annealer we used the percentage of account resourcesused (against a 60 second budget) for the primary account used. The classicalmethods were run on a 2013 iMAC with a 3.4GHz Quad-Core Intel Core i5,with 16GB DDR3 RAM at 1600 MHz, running macOS Catalina and Python3.7.7. Figure 12: Table of Comparative methodsFigure 13: Analysis of Comparative methods
We see a few challenges in scaling up this analysis from 60 stocks to 100, andup to 500 stocks to be analyzed at once. First, our formulation puts significantstrain on the system to evaluate portfolios with larger numbers of stocks (47+).The variance and covariance content between each stock (and loaded onto qubit15oupling terms) becomes too small to be effectively read by the D-Wave system.Values currently approaching 0.003 as compared to linear terms of -0.9. Second,room on the D-Wave QPU is filling up. When we program and embed 60stocks, we use between 1,300 and 1,700 of the available 2048 qubits. Using alinear extrapolation, there may only be room for 20% more, or 72 stocks, at thehigher end of the loading.
Our aim is to extend our research from a 40 to 60 asset universe, to find the idealportfolio out of a possible 2 options. Using the CQNS formulation we extendto 60 assets on both the D-Wave quantum annealer and five classical methods.We do this through engineering improvements and applying a graduated penaltyto the 60 × ×
60 matrix. We improve our classical methods and all run inunder one minute.We believe we can scale the problem further with improved embedding,management of the energy delta between portfolios, and continued improvementin the penalty function.Our results show that D-Wave can be leveraged to generate an efficient fron-tier landscape quickly with a small number of samples (e.g., < , Addendum
Below are two charts 14, 15 with more complete details of our analyses, stockinfo, date and time, and portfolios selected by various methods. We providethese details for the sake of repeatability by interested readers.Figure 14: Full Table of Comparative Methods16igure 15: Details of Analysis
References [1] N.Bekkers, R.Doeswijk, T.Lam, Strategic Asset Allocation: Determiningthe Optimal Portfolio with Ten Asset Classes https://papers.ssrn.com/sol3/papers.cfm?abstract_id=1368689
Oct 2009[2] G. Brinson, L.R. Hood, G. Beebower, Determinants of Portfolio Perfor-mance, June 1986, Financial Analysts Journal 42(4):39-44, DOI: [3] G. Brinson, B. Singer, G. Beebower, Determinants of Portfolio PerformanceII: An Update, May/June 1991, Financial Analysts Journal pp.40[4] DWave Quantum Annealing Systems Documentation, https://docs.dwavesys.com/docs/latest/index.html [5] DWave Simulated Annealing Sampler - Systems Documentation, https://docs.ocean.dwavesys.com/projects/neal/en/latest/reference/sampler.html [6] DATAvariance US Market Indices, https://pininvest.com/indices/ [7] Michael Marzec.
Portfolio Optimization: Applications in Quantum Com-puting.
SSRN Electronic Journal, 2013 https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2278729 [8] Harry Markowitz, Portfolio Selection, The Journal of Finance, 7,1 (1952),77-91 179] Nada Elsokkary, Faisal Shah Khan, Davide La Torre, Travis S. Humble,Joel Gottlieb. Financial Portfolio Management using D-Wave’s QuantumOptimizer: The Case of Abu Dhabi Securities Exchange. IEEE High Per-formance Extreme Computing Conference,HPEC, Sept. 2017 (edited)[10] Ors, Romn, Samuel Mugel, and Enrique Lizaso. Quantum comput-ing for finance: overview and prospects. Reviews in Physics 4 (2019)(arXiv:1807.03890 [quant-ph])[11] M. Rubenstein, Markowitz’s Portfolio Selection: a Fifty-Year Ret-rospective, The Journal of Finance, Vol LVII, Num 3, June 2002,DOI:10.1.1.404.4279[12] William F. Sharpe, Stanford University, The Sharpe Ratio, The Journal ofPortfolio Management, Fall 1994 http://web.stanford.edu/~wfsharpe/art/sr/sr.htm [13] William F. Sharpe,
Mutual Fund Performance , The Journal of B business,Vol 39, No.1, Part 2, Supplement on Security Prices. (Jan 1966), pp. 119 -138 [14] D.Venturelli, A.Kondratyev,
Reverse Quantum Annealing Approach toPortfolio Optimization Problems , arXiv:1810.08584, 2018[15] YFinance python module, maintained by Ran Aroussi, Thank you https://pypi.org/project/yfinance/ [16] Yahoo Finance provides all historical data used in these experiments,Thank you, https://finance.yahoo.com/ [17] French, Craig W., Another Look at the Determinants of Portfolio Perfor-mance: Return Attribution for the Individual Investor (July 29, 2003). https://ssrn.com/abstract=706603 or http://dx.doi.org/10.2139/ssrn.706603 [18] Patent Application US20170372427A1, USA, Quantum-Annealing Com-puter Method for Financial Portfolio Optimization, QCWare. https://patents.google.com/patent/US20170372427A1/enhttps://patents.google.com/patent/US20170372427A1/en