FACULDADEDE ENGENHARIADA UNIVERSIDADEDO PORTO

Quantum Algorithms for Portfolio Management

Duarte Frazão

Mestrado Integrado em Engenharia Informática e Computação

Supervisor: Koen Bertels Second Supervisor: José Matos

July 19, 2021

Quantum Algorithms for Portfolio Management

Duarte Frazão

Mestrado Integrado em Engenharia Informática e Computação

Approved in oral examination by the committee:

Chair: Prof. João Paulo Fernandes External Examiner: Prof. Imran Ashraf Supervisor: Prof. Koen Bertels

July 19, 2021

Abstract

Quantum Computing is the process of leveraging quantum phenomena such as superposition and entanglement to solve problems that are intractable for classical computers. These properties al- low quantum computers to process an exponential amount of states in parallel in relation to the number of quantum bits, which is the main limitation of classical computing. With recent suc- cessful innovation on building more powerful quantum computers, the research community has started to explore different areas that will be disrupted when operational error-corrected quantum computers become a reality. One recent area of research is Quantum , intended to be the bridge between and Finance. The focus lies on understanding which problems in this area will be impacted by quantum computers. These can either be problems that can be solved more efficiently or problems that have never been solved due to classical computer limitations. Finance is one of the largest industries in the world, impacting every citizen in many ways, from our savings and investments to the companies that we rely upon to live our lives. Port- folio Management is the sub-field of Finance that tries to find the optimal investment portfolio for each individual investor. Several contributions have been made to understand the future of Portfolio Management with quantum computing, mainly using quantum annealing, a restricted family of quantum computers with the objective of finding global minima in combinatorial opti- mization problems. However, gate-based quantum computers will allow a much wider range of possibilities, which are still under-explored. More research on Quantum Finance using gate-based quantum computers is warranted to understand what will be possible in the future. In this work, we solve the Portfolio Management problem of finding the optimal portfolio that minimizes risk and maximizes returns for a given risk profile on a gate-based quantum computer simulator. The quantum algorithms chosen were QAOA and its new version QAOA+. QAOA is the basic ver- sion, it is already available and contains a large body of literature covering it. QAOA+ is a recent proposed version, it still has few pieces of literature associated. To understand how and when should we use QAOA and QAOA+ for Portfolio Management, an in-depth comparison between the two algorithms for this topic was realized. We implemented our solution using IBM’s quantum platform, Qiskit, using a perfect quantum simulator to test the algorithms. We analyzed a possible scenario of choosing a portfolio from 15 assets to understand the quality of the results, where we found that the implemented QAOA+ yielded better solutions than QAOA. Finally, several metrics were gathered to compare both algorithms, such as execution time, circuit depth, number of gates, number of qubits, and number of classical loop iterations. Even though Qiskit did not provide all the circuit resources needed to reach the most efficient version, we concluded that our implemen- tation still achieved a better performance than QAOA in most metrics evaluated. Possibilities of further work were also identified throughout the dissertation for future research.

Keywords: Quantum finance, Portfolio Management, Quantum Computing

i ii Resumo

Computação Quântica é o processo de aproveitar fenómenos quânticos como sobreposição de estados e entrelaçamento quântico para resolver problemas que são inviáveis para computadores clássicos. Estas propriedades permitirão processar uma quantidade exponencial de estados em relação ao número de bits quânticos, a maior limitação de computação clássica. Com a recente inovação, bem sucedida, na construção de computadores quânticos mais potentes, a comunidade científica começou a explorar diferentes áreas que vão sofrer uma mudança de paradigma quando computadores quânticos operacionais e com correção de erros se tornarem realidade. Uma área recente de investigação é a de Finanças Quânticas, com o objetivo de fazer a ligação entre Com- putação Quântica e Finanças. O foco baseia-se em compreender que problemas nesta área serão impactados por computadores quânticos. Estes estão divididos em problemas que podem ser resol- vidos mais eficientemente ou que nunca foram resolvidos devido às limitações de computadores clássicos. A indústria financeira é uma das maiores do mundo, afetando os cidadãos de várias for- mas, desde as suas poupanças aos seus investimentos. A Gestão de Carteiras é uma sub-categoria de Finanças que tenta encontrar o portefólio ótimo para cada investidor. Várias contribuições já foram feitas para compreender o futuro de Gestão de Carteiras com computação quântica, prin- cipalmente usando Recozimento Quântico (Quantum Annealing). Por outro lado, computadores quânticos gate-based vão permitir mais possibilidades, que ainda estão inexploradas. Mais in- vestigação em Finanças Quânticas usando computadores quânticos gate-based é necessária para entender o que será possível no futuro. Neste trabalho, resolvemos o problema de Gestão de Carteiras de encontrar o portefólio ótimo que minimize o risco e maximize os retornos para um determinado perfil de risco usando um simulador de computadores quânticos gate-based. Os al- goritmos quânticos escolhidos foram o QAOA e a sua nova versão QAOA+. QAOA é a versão base, já disponível e com muita literatura associada. QAOA+ é uma versão proposta recentemente ainda com pouca investigação associada. Para perceber melhor como e quando devemos usar o QAOA ou o QAOA+ para Gestão de Carteiras, uma comparação detalhada foi feita entre os dois algoritmos para o tópico em questão. Implementámos a nossa solução usando a plataforma para computação quântica da IBM, Qiskit, usando um simulador de computador quântico perfeito para testar os algoritmos. Analisamos o cenário de escolher um portefólio de um grupo de 15 ati- vos para perceber a qualidade dos resultados, onde descobrimos que a nossa implementação do QAOA+ mostrou melhores soluções que o QAOA. Finalmente, várias métricas foram recolhidas para comparar ambos os algoritmos, como o tempo de execução, profundidade do circuito, número de gates e número de ciclos clássicos. Apesar do Qiskit não conter todos os recursos necessários para construir a versão mais eficiente possível, concluímos que a nossa implementação ainda con- seguiu atingir uma melhor performance que o QAOA em grande parte das métricas avaliadas. Possibilidades de investigação futura também foram identificadas ao longo da dissertação.

Keywords: Quantum Finance, Portfolio Management, Quantum Computing

iii iv Acknowledgements

I want to thank everyone that in one way or another helped me finish my Master’s Degree and this dissertation. To Professor Bertels, who guided me into the field of Quantum Computing, giving me the tools and means to complete this work, all while pushing the Quantum community forward. To Professor Matos, who helped me bring together the two fields of Quantum and Finance, while helping me improve my knowledge and work. To Aritra Sarkar, whose expertise and advice helped me work through any roadblocks. To the rest of the QBeeX team, who provided me with a collaboratively work environment to learn and explore this new field. I also want to thank all my friends that were part of this journey and contributed to make it such a great experience. To Basia, for getting me out of the house and being the best support I could ever ask for. Finally, none of this would have been possible without my family, who guided me throughout all my life.

Duarte Frazão

v vi “The first principle is that you must not fool yourself, and you are the easiest person to fool.”

Richard P. Feynman

vii viii Contents

1 Introduction1 1.1 Context ...... 1 1.2 Motivation ...... 2 1.3 Objectives ...... 2 1.4 Document Structure ...... 3

2 Background5 2.1 Quantum computing ...... 5 2.1.1 Quantum bits ...... 5 2.1.2 Gates ...... 7 2.1.3 State of multiple qubits ...... 8 2.1.4 Entanglement ...... 9 2.1.5 Scaling on quantum computing ...... 9 2.1.6 How to make a quantum algorithm? ...... 10 2.1.7 State of the hardware ...... 10 2.1.8 Approaches to quantum research ...... 11 2.1.9 How to evaluate a quantum algorithm ...... 11 2.2 Finance ...... 12 2.2.1 ...... 12 2.2.2 Modern Portfolio Theory ...... 12 2.2.3 QUBO ...... 13

3 Literature Review 15 3.1 Different approaches to Finance using quantum computing ...... 15 3.2 Surveys on Quantum Finance and Combinatorial Optimization ...... 16 3.3 Quantum Finance, using quantum annealing ...... 19 3.4 Quantum Approximate Optimization Algorithm (QAOA) and Quantum Alternat- ing Operator Ansatz (QAOA+) ...... 22 3.5 Quantum Finance, using universal quantum computers ...... 25 3.6 Literature Analysis ...... 27

4 Problem Statement 29 4.1 Problem ...... 29 4.2 Main hypotheses ...... 30 4.3 Contribution ...... 30 4.4 Scope ...... 31 4.4.1 Perfect qubits ...... 31 4.4.2 Finance assumptions ...... 31

ix x CONTENTS

4.4.3 Qiskit ...... 31

5 Implementation 33 5.1 Data ...... 33 5.2 Portfolio Management base problem ...... 35 5.3 Quantum algorithms ...... 36 5.3.1 QAOA ...... 36 5.3.2 QAOA+ ...... 37 5.4 Constraints ...... 41 5.4.1 Constraints as penalty terms ...... 41 5.4.2 Constraints as mixer operator ...... 43 5.4.3 Penalty terms versus mixer encoding ...... 44 5.5 Overview of the solution ...... 45 5.6 Initial analysis ...... 45 5.6.1 Conservative profile ...... 46 5.6.2 Risky profile ...... 47 5.6.3 Results ...... 48

6 Results 51 6.1 Experimental results ...... 51 6.1.1 Test environment ...... 51 6.1.2 Tests settings ...... 51 6.1.3 Gates ...... 52 6.1.4 Algorithm Memory Consumption ...... 52 6.1.5 Circuit depth ...... 53 6.1.6 Number of gates ...... 53 6.1.7 Algorithm execution time ...... 55 6.1.8 Quantum part execution time ...... 57 6.1.9 Number of classical iterations ...... 57 6.2 Hypotheses evaluation ...... 58

7 Conclusions 61 7.1 Difficulties ...... 61 7.2 Future Work ...... 61 7.3 Contributions ...... 62 7.4 Conclusion ...... 62

A Solution Example Data 65

B Qiskit gates 69

References 71 List of Figures

2.1 Bloch Sphere...... 6 2.2 CNOT gate ...... 8 2.3 Efficient frontier example...... 13

3.1 General structure of the quantum global optimization algorithm ...... 19 3.2 Results from investment trajectory algorithm ...... 21 3.3 QAOA high-level overview...... 24 3.4 Description of mixer structure for Portfolio Rebalancing problem...... 26

5.1 Data retrieval process...... 33 5.2 QAOA circuit (p=1)...... 36 5.3 Current version of QAOA+ circuit...... 39 5.4 Example of QAOA+ with parameterized swap gate implemented...... 40 5.5 Number of assets mixer structure...... 43 5.6 Sector allocations mixer structure...... 44 5.7 Feasible solutions analysis...... 46 5.8 Conservative profile solution...... 47 5.9 Risky profile solution...... 48 5.10 Results for the risk of portfolio...... 49 5.11 Results for expected returns of the portfolio...... 49 5.12 Results for cost of portfolio...... 50

6.1 Gates execution time...... 52 6.2 Memory consumption...... 53 6.3 Circuit depth comparison...... 54 6.4 QAOA+ vs QAOA circuit depth...... 54 6.5 Number of gates comparison...... 55 6.6 QAOA+ vs QAOA number of gates...... 56 6.7 Algorithm execution time...... 56 6.8 Quantum part execution time...... 57 6.9 Number of classical optimization iterations...... 58 6.10 Percentage of feasible states in the set of possible states...... 59

B.1 X gate...... 69 B.2 Hadamard gate...... 69 B.3 RX gate...... 69 B.4 RZ gate...... 70 B.5 S gate...... 70 B.6 SDG gate...... 70

xi xii LIST OF FIGURES

B.7 SWAP gate...... 70 B.8 CNOT gate...... 70 List of Tables

A.1 Covariance matrix for solution example ...... 66

xiii

Chapter 1

Introduction

1.1 Context ...... 1 1.2 Motivation ...... 2 1.3 Objectives ...... 2 1.4 Document Structure ...... 3

1.1 Context

Finance is one of the largest industries in the world. Touching everything in our day to day lives, from savings and investments, to the companies from which we consume goods and services. As software evolved, so have the tools that this industry relies upon for normal operation. Nowadays, most of the market activity is in one way or another reliant on software. It is estimated that high- frequency trading, computer programs that trade equities based on market indicators, account for up to 50% of the total United States equity trading volume [6]. One important area of Finance that impacts all investors is how to model their investment port- folio in such a way that minimizes risk and maximizes the potential returns. Portfolio Management deals with the problem of finding the ideal portfolio for each individual investor. The ideal portfo- lio depends on several variables related to the goals and profile of the investor. Age, for example, is one the variables that completely changes the investment approach. A young investor is focused on growing his wealth, and is willing to tolerate more risk if the potential reward is compelling. A retired investor is focused on maintaining his wealth, so the main focus is to reduce any risk of losing money, opting for a portfolio with low risk and consistent moderate rates of return. Another important aspect for investors is having a diversified portfolio, this can mean, for example, having investments in different market sectors. The benefit of diversification is giving protection to a large and fast depreciation of the portfolio. A well diversified portfolio will hedge its investments with other highly uncorrelated investments, protecting the investor when a sector downturn happens.

1 2 Introduction

For risk averse investors too much diversification is also unwarranted, as it limits the potential returns of the portfolio. Portfolio Management is a sub-problem of Combinatorial Optimization, belonging to the class of NP-hard problems. Finding the optimal portfolio through a brute-force approach scales expo- nentially, and thus classical computers are incapable of solving this problem for large instances. To find a close to optimal solution, classical computers use machine learning and heuristic algorithms. Finally, we get to Quantum Finance, a recent field of research that focuses on the different ap- plications of quantum computing to Finance. One such application being Portfolio Management. Quantum computers, by leveraging the quantum phenomena of superposition and entanglement, will exhibit implicit parallelization of processed states, possibly discovering new and better ways to solve problems that until now were difficult or intractable to solve on classical computers.

1.2 Motivation

Quantum Computing is still in its early stages, and remarkably hard physics challenges will need to be overcome in order for quantum to add value to industries, and consequently, to our lives. While it is not possible to predict if and when quantum will disrupt Finance, we can already start to research what will be the possible applications. Furthermore, although quantum computers work in a way that humans are not yet able to fully understand, their behaviour follows a specific set of rules that makes it possible to simulate on classical computers. With that, work on the various parts of the quantum computer stack is being done to accelerate the time for quantum computers to come to market. The goal is that when error-corrected quantum computers come to fruition, the entire rest of the stack is already available to use [3]. Quantum Finance is still a new field of research, with a large set of problems and algorithms not yet explored. This poses a great opportunity to anyone interested in Finance that wants to explore how quantum computing will impact the industry.

1.3 Objectives

This work aims to explore and contribute to the current state of Quantum Finance, more specif- ically in Portfolio Management. For that, we started by exploring existing research and possible algorithms to use. The Modern Portfolio Theory [12] formulation was selected as a target prob- lem. After that, we chose an algorithm that is expected to be ran on near-term quantum computers, QAOA. Given that recently a newer version was proposed where literature is still scarce, QAOA+ [9], we decided to explore how QAOA and QAOA+ compared in the context of Portfolio Manage- ment. The approach was to build a solution to the problem using IBM’s quantum platform, Qiskit, that compared the two versions. The research done proved successful, even though some technical difficulties regarding Qiskit were found, our solution using QAOA+ exhibits better results than QAOA, which is used on most literature for gate-based quantum computers. 1.4 Document Structure 3

1.4 Document Structure

This work is composed of the following seven chapters:

• Chapter1 (p.1), Introduction, describes the context, motivation and objectives of the work;

• Chapter2 (p.5), Background, goes over some concepts needed to understand the following chapters;

• Chapter3 (p. 15), Literature Review, describes the process taken to review the literature on Quantum Finance and Portfolio Management;

• Chapter4 (p. 29), Problem Statement, defines the problem we are trying to solve;

• Chapter5 (p. 33), Implementation, describes the decisions taken and the implementation of the solution developed. It also presents an example scenario to illustrate and validate the solution;

• Chapter6 (p. 51), Results, contains all the data gathered and analysed to evaluate and compare the algorithms used;

• Chapter7 (p. 61), Conclusions, concludes with the difficulties faced, future work, our con- tribution and conclusion of the work. 4 Introduction Chapter 2

Background

2.1 Quantum computing ...... 5

2.2 Finance ...... 12

This chapter describes pre-requisites from Quantum Computing and Finance needed to under- stand the rest of this work.

2.1 Quantum computing

Quantum physics was born out of necessity to explain elementary particles’ duality behavior, which act both as particles and waves functions. In this theory, objects are described as wave functions, but when measured, behave like particles. This is known as the wave-particle duality problem, and there is still no answer to how the process works. The wave function behavior con- sequences are the quantum phenomena of superposition, entanglement, Heisenberg uncertainty principle and others.

2.1.1 Quantum bits

In classical computing each bit can represent either state 0 or 1. In quantum computing, informa- tion is represented by a quantum bit (qubit) which can represent either state 0, 1 or a combination (superposition) of the two states at the same time, this superposition will collapse to one of the basis states, in this case 0 or 1, when a measurement is performed. We introduced the concepts of states, superposition, collapse and measurement. We’ll provide some basic background of each concept after exploring the notation used in quantum computing, Dirac Notation1.

1This is by no means a detailed explanation, and we refer the reader to Desurvire’s book on Classsical and Quantum Information Theory [5] for an in-depth description.

5 6 Background

Figure 2.1: Bloch Sphere.

Source: Wikipedia

As seen before, the qubit can be in a superposition of states 0 and 1, which we can represent in the 2D space of orthonormal basis ~u and~v:

" # " # 1 0 ψ~ = α~u + β~v = α + β = α |0i + β |1i = |ψi (2.1) 0 1

α and β are complex numbers, representing the amplitude of the projection of state |ψi to the corresponding basis state. They are also the coordinates of the state of the qubit, ψ~ , in a 2D complex vector space, the Hilbert Space. The right side of the equation is the representation of the state of the qubit in the Dirac Notation. Instead of an arrow representing the vector we use the ket notation, |i. We can use the Bloch Sphere seen in Figure 2.1 to visualize the possible positions of the qubit state, where the North of the sphere represents the |0i state and the South the |1i state. Each possible state vector has unit 1. Here, ϕ and θ represent angles between state |ψi to the x and z axis respectively, and can be used to represent any state in the Bloch Sphere with the following formulation:

θ θ |ψi = cos |0i + eiϕ sin |1i (2.2) 2 2 To get the probability of the |ψi state collapsing to the basis states (|0i,|1i), or any other basis, we take the squared cosine of the angle between |ψi and the basis state. This cosine is actually the amplitude of the projection of |ψi to the basis state. A general definition for the probability of state |ψi collapsing to an arbitrary state |xi, where the angle between the two equals α is then:

p(hψ|xi) = cos2 α (2.3)

here hψ|xi means state |ψi collapsing to state |xi. 2.1 Quantum computing 7

Although a qubit in superposition is in a combination of states, when measured, the super- position will collapse to either state |0i or |1i. With such measurement we effectively destroy the superposition and following measures will yield the same result. This measurement process is stochastic, meaning that in order to retrieve the probability distribution we need to execute the algorithm multiple times. It is also probabilistic, |α|2 and |β|2 represent the probability that a mea- surement reads state |0i and |1i respectively. As here we only have two measurement possibilities, it follows that:

|α|2 + |β|2 = 1 (2.4)

2.1.2 Gates

Similarly to classical computing, in quantum computing we use quantum gates to modify the state of qubits. These gates are unitary operators and change the basis states of the space, rotating the Bloch Sphere. For example, here a quantum gate A is applied to a qubit in state |ψi with amplitudes α and β:

" #" # a a α |ψ0i = A|ψi = 11 12 a21 a22 β

= (a11α + a12β)|0i + (a21α + a22β)|1i 0 0 = α |0i + β |1i (2.5)

here α0 and β 0 represent the final amplitudes after applying the gate A. The most basic gates for quantum circuits are the Pauli X, Y, and Z gates, which correspond to rotations of the Bloch Sphere in the X, Y, and Z axis by an angle π:

" # " # " # 0 1 0 −i 1 0 X = Y = Z = 1 0 i 0 0 −1 Closely related to the Pauli gates there are the rotation gates RX, RY, and RZ, which parame- terizes the rotation by a specified angle. Naturally, an RX gate parameterized by π is equal to the X gate, and the same applies for the other two rotation gates. All 2x2 operators can be constructed by a linear combination of these three rotation gates. Additionally, other gates will be used during this work. The Hadamard gate is used to perform various operations, such as bringing qubits into super- position or entanglement. It is represented by the following matrix: " # 1 1 1 H = √ 2 1 −1

The Hadamard can be seen as changing the basis states from |0i and |1i to the |+i and |−i basis states, which represent equal probability of collapsing into state |0i and |1i. 8 Background

Figure 2.2: CNOT or Controlled-Not gate

There are also controlled 2-qubit gates, meaning that one qubit behaves as the control qubit and the other as the target. If the control qubit is one an operation is applied, if zero nothing happens. For example, in Figure 2.2 the Qiskit circuit contains a CNOT gate, it applies an X gate to qubit 0 if the control qubit (small blue dot), which is qubit 1, is 1. This gate is present in most quantum algorithms, for example, to create entanglement between qubits. The CNOT gate is represented by the following matrix:

  1 0 0 0   0 0 0 1 CNOT =   0 0 1 0   0 1 0 0 There is also the Swap gate, which swaps the amplitudes from two qubits and a parameterized version of the Swap gate, that partially swaps the amplitudes from two qubits. The matrices that represent these gates are:   1 0 0 0   0 0 1 0 Swap =   0 1 0 0   0 0 0 1   1 0 0 0  φ φ  0 cos( ) isin 0 Parameterized Swap(φ) =  2 2  0 isin φ cos φ 0  2 2  0 0 0 1

During the work several Qiskit circuits will be presented that include gates that were not refer- enced here, as they perform similar operations to the ones described. Nevertheless, for reference AppendixB (p. 69) lists all the gates used during the work, their meaning and also the correspond- ing Qiskit representation.

2.1.3 State of multiple qubits

Previously we referred that a qubit state is a vector in an Hilbert space. When we combine multiple qubits, the basis states are tensored together to form an extended basis. Given two basis N and V, 2.1 Quantum computing 9 the combined basis of the space will be:

N ⊗V = (|0i,|1i) ⊗ (|0i,|1i) = (|0i ⊗ |0i,|0i ⊗ |1i,|1i ⊗ |0i,|1i ⊗ |1i) = (|0i|0i,|0i|1i,|1i|0i,|1i|1i) = (|00i,|01i,|10i,|11i) (2.6)

The last three equalities of the equation represent different notations to describe the combined basis of the space. We’ll use the last one throughout the dissertation. In cases where the state contains a large number of repeated states we can also use the follow- ing notation:

|0000001111i = |0i⊗6 ⊗ |1i⊗4 (2.7)

2.1.4 Entanglement

Entanglement is the quantum phenomena of connecting the outcome of the collapse from each qubit. To do this, we bring two qubits into a Bell state, or EPR state, which can be:

1 Φ+ = √ (|00i + |11i) 2 1 Φ− = √ (|00i − |11i) 2 1 Ψ+ = √ (|01i + |10i) 2 1 Ψ− = √ (|01i − |10i) 2 (2.8)

The bell states cannot be factored into the tensor product of pure states, which is why they are entangled with each other. Given an experiment where we entangle two qubits in a lab, and send one of them to a far-away distance, we realize that if we measure the qubit which is still in the lab, we instantaneously know how the other qubit will collapse, even when that other qubit is still in superposition and hasn’t been measured.

2.1.5 Scaling on quantum computing

One important aspect not yet covered is the potential of superposition. Classical computers lack the physical capabilities to solve problems that scale exponentially, such as NP problems. Quan- tum computers, by leveraging the quantum phenomena of superposition exhibit an implicit par- allelization behaviour, precisely where classical computers fall short. Quantum computers can represent 2n parallel states simultaneously, where n is the number of qubits. This exponential growth allows quantum computers to efficiently solve some technological important problems with exponential speedup [16]. Some of these were infeasible to compute until now. 10 Background

For context, IBM expects to have a quantum computer with 1000 qubits by 2023 [11]. In a scenario of perfect qubits, the number of possible parallel states would be:

21000 ≈ 10301

Many qubits are needed to build one error-corrected qubit, so the actual possible parallel states will be much lower. However, if they manage to achieve their goal it will be a significant step for the industry, as quantum computers currently have less than 100 qubits.

2.1.6 How to make a quantum algorithm?

A quantum algorithm follows these steps:

• Encode data into a state of n qubits;

• Bring qubits into superposition;

• Apply an algorithm simultaneously to all states (automatic for quantum computers but not for classical computers);

• Measure qubits;

• Repeat the previous steps on the same qubits until we have a probability distribution of the states.

It is important to note that, unlike classical computing, we need to execute the algorithm multiple times, the reason being that quantum computing is inherently probabilistic, so the correct answer is not always achieved. After multiple executions, a probability distribution of the possible states is built, and the most probable outcomes are chosen.

2.1.7 State of the hardware

There are various approaches to build quantum computers, for this work we consider only gate- based quantum computers. The most advanced technology that allows to tap into the full potential of quantum computers. Qubits currently available are called real qubits. They still suffer from qubit decoherence and errors from quantum gate operations. The former refers to when a qubit state is lost by a small interaction with the environment, the latter to errors generated by a quantum gate operation. Comparing current qubit error rates, 10−2/−3, to that of CMOS transistors, 10−15/−16, we see that there is still a long way for error rates to improve. In 2018 Preskill [17] proposed that we are in the NISQ (Noisy Intermediate-Scale Quantum) era, which he defines as the time where we don’t have enough qubits to create a quantum circuit that is both fault-tolerant and also surpasses the capabilities of today’s classical computers. 2.1 Quantum computing 11

2.1.8 Approaches to quantum research

There are different approaches to research quantum algorithms. One is the NISQ approach, that focuses solely on what we can do with current quantum com- puters, accounting for their physical limitations. The other is the PISQ approach, which as de- scribed by Bertels et al.[3][4], uses perfect quantum simulators that abstract the current limita- tions that quantum computers exhibit today. While there are compelling reasons for choosing either approaches, ultimately this work takes the second , assuming perfect quantum computers. The main reason is the complexity that arises from trying to account for physical errors, greatly limiting what we can explore in new fields, which in our view is one of the goals for this stage. In this approach we explore how much value quantum can bring in the future, while quantum computers are still in the development phase. Although we followed the perfect quantum computer route, without a doubt that NISQ re- search is needed, as this will improve the integration with faulty quantum computers, and much of that work will certainly accelerate the merging of quantum software and hardware. However, these two approaches can also advance in parallel. While NISQ focuses on discov- ering techniques for quantum error correction, others can explore future applications of quantum computing that will only be achieved when error-corrected quantum computers become a real- ity. Many of the developed NISQ techniques are also being integrated directly into the quantum platforms, this way high-level algorithm development will also benefit from NISQ research.

2.1.9 How to evaluate a quantum algorithm

The main challenge in evaluating an algorithm is the fact that we simulate the quantum computer behaviour in a classical computer. Although there are quantum simulators than mimic the same process of a quantum computer, shot based simulators, the evaluation of the execution time will naturally be different when evaluated on a real quantum computer. Nevertheless, any speedups obtained in simulators will mean that current research will be able to explore larger problems, an important goal for this stage of quantum research. With this in mind we measured the following metrics:

• Circuit depth;

• Number of gates;

• Number of qubits;

• Execution time;

• Memory consumption;

• QAOA classical loop iterations. 12 Background

The first three being related to how would it behave on a real quantum computer. Execution time and memory consumption are related to algorithm performance on quantum simulators. The classical loop iterations are relevant for both real quantum computers and simulators.

2.2 Finance

In order to understand the Finance component of this work we briefly explain the basic components of a financial market and give an overview of the Modern Portfolio Theory and QUBO encoding.

2.2.1 Financial market

There are various types of financial markets, each with their own rules and procedures. Throughout the work we will use the following definition of market:

• A market purpose is to facilitate the trading of company shares;

• Shares represent a percentage of ownership on a company;

• Shares are bought and sold by matching buyers and sellers at an agreed price;

• Brokers act on behalf of investors to trade these shares, some taking a commission for the service;

• Several financial instruments are used to trade shares. The most common are long and short positions. Long positions is when an investor buys a share with the expectation of selling it later at a higher price. Short positions are more complex. Here an investor A buys a share from a shareholder B and sells it at the market price. The expectation is that the price goes down, the short investor buys the share again and returns it to the original share holder, profiting or losing the difference. The broker facilitates this process for a commission.

2.2.2 Modern Portfolio Theory

The Modern Portfolio Theory, developed by Markowitz [12], defines how an investor with a spe- cific risk profile can construct a portfolio that maximizes returns and minimizes risk. In Quantum Finance it is common to use a particular case of this model that uses binary instead of continuous variables. The model is given by the following minimization function:

γ −µT ω + ωT Σω (2.9) 2 here µ is a vector of expected returns for each asset, ω is a vector of binary decision variables indicating which assets were chosen, µT ω represents the expected returns of the portfolio, this term is the returns component of the function. Σ is the covariance matrix, ωT Σω represents the portfolio variance, meaning how much is the portfolio expected to vary, or how volatile is the portfolio, this term is the risk component of the function. The portfolio variance is divided by 2.2 Finance 13

Figure 2.3: Efficient frontier example.

Source: Plotly Notebooks. two due to the expansion of the Taylor polynomial. Finally, γ is a positive scalar that models the risk profile of the investor, giving more weight to the risk component for larger values of γ and more weight to the returns component for lower values of γ. The covariance matrix and vector of expected returns are calculated using the daily logarithmic returns from past market data, this enforces the normalization of the returns. From now on, as it is usual in Finance literature, we will refer to them as log returns or simply as returns. The theory also defines that there is no single optimal portfolio, but an optimal portfolio for each level of risk. This is the efficient frontier, which we can see from Figure 2.3, by the orange line. Portfolios under this line are considered sub-optimal. This theory contains unrealistic assumptions, and several methods are used in the Finance industry to approximate this theory to reality. Nevertheless, this theory is commonly used in Quantum Finance as a base problem for research, and this work follows the same pattern.

2.2.3 QUBO

Commonly, the Modern Portfolio Theory is encoded as a Quadratic Unconstrained Binary Opti- mization (QUBO) problem. A QUBO encodes the problem using binary decision variables and restricts the solutions using quadratic penalties or rewards to the minimization/maximization func- tion. It is expressed by the following optimization problem:

Minimize/Maximize y = xt Qx (2.10)

here x is a vector of binary decision variables, Q a symmetric square matrix of constants used to model the problem and xT the transpose of x. Penalties and rewards being quadratic only affect matrix Q. One advantage of this approach is that several common observed constraints have the equivalent QUBO penalty readily available. 14 Background Chapter 3

Literature Review

3.1 Different approaches to Finance using quantum computing ...... 15 3.2 Surveys on Quantum Finance and Combinatorial Optimization ...... 16 3.3 Quantum Finance, using quantum annealing ...... 19 3.4 Quantum Approximate Optimization Algorithm (QAOA) and Quantum Alternating Operator Ansatz (QAOA+) ...... 22 3.5 Quantum Finance, using universal quantum computers ...... 25 3.6 Literature Analysis ...... 27

In this chapter we’ll get an understanding of what is the current state of Quantum Finance, more specifically in regards to Portfolio Management. The area of research is quite recent and literature is still scarce. One of the disadvantages of still being a recent field is how broad it is, joining an entire field of Finance and different quantum technologies. To work around this limitation, the structure of this chapter will be divided in groups of literature that will help get a better understanding of the field. In the end, an analysis of the literature is done that ties together the different groups researched. This will serve as context for the next chapter.

3.1 Different approaches to Finance using quantum computing

We analysed two key contributions for the future of Quantum Finance. First, a different approach to the random walk theory, which leverages quantum phenomena to more accurately model the price evolution of asset prices. Second, how a stock market can be modelled using quantum formalism, given that a financial system behaves more like a quantum system than a mechanical system. Although this work does not present a fundamentally different approach to any Finance process, these new methods reviewed are still relevant for future research.

15 16 Literature Review

Orrell [15] presents a book on an applied mathematics point of view for Quantum Finance and Economics. For the Finance component, a quantum version of the random walk theory is formu- lated, which is a theory used in Finance to model the time evolution of stock prices randomly. The classical random walk uses a random model, which can be understood as arbitrary decisions. For the quantum version, Orrell suggests that the mental state of the decision-maker is more accurately modelled using a quantum wave function. There are three main differences between the classical random walk and its quantum counter- part. First, the quantum walk is a superposition of states. Second, unlike the classical, the quantum is not random but deterministic, only using probabilities for the measurement process and collaps- ing the state to one of the possible outcomes. Third, the quantum walk provides a polynomial speedup against algorithms that use the classical random walk. Additionally, Orrell uses the quantum walk to describe a quantum algorithm for options pric- ing1, which takes into account the same variables as the Black-Scholes equation, the main method for the pricing of options. Instead of modelling the evolution of the option price randomly, it uses a quantum walk. This provides the aforementioned speedup and has the advantage of taking into account investor behaviour. Schaden [19] presents what is considered to be the first mathematical definition of a quantum market: a superposition of financial states where measurements are represented as transactions. In his work, he describes how a stock market can be modelled from the ground up, evolving with each transaction in the market, which is seen as a partial measurement and represented by unitary operators. To model the temporal evolution of the system, operators are used to act as market dynamics and to model the probability distribution of future behaviour.

3.2 Surveys on Quantum Finance and Combinatorial Optimization

Here we look into three surveys. Two are related to Quantum Finance, one from the perspective of a company that is active in the development of quantum annealing solutions while the other from one of the leaders in the development of gate-based quantum computers. This distinction is relevant given the competition that these two technologies currently face, and the inherent bias in their arguments. Finally, a survey on Combinatorial Optimization on quantum computers is analysed, as Port- folio Management is included in this problem category. Orús et al. [16], a group of researchers specially active in the development of quantum an- nealing algorithms, give an overview of Quantum Finance state of the art and possible disruptions, both in terms of algorithm research and hardware capabilities. They make a case for quantum annealers, a restricted family of quantum computers with the objective of finding global minima in combinatorial optimization problems. The support for this

1Options are a type of financial derivatives that are based on the underlying price of an asset, for more information we refer the reader to Investopedia 3.2 Surveys on Quantum Finance and Combinatorial Optimization 17 technology is based on the fact that it is already commercially available and has lower physical restrictions. It is also pointed out that quantum annealers with 2000 qubits (from D-Wave) are already available, while gate-based quantum computers only feature 72 qubits (on the Google quantum computer). Important to note that quantum annealers can only achieve, with limited control, a small subset of gate-based quantum computers capabilities, so although the difference in qubits is significant, we cannot directly compare how they stack against each other. However, for some instances of combinatorial optimization problems quantum annealers will likely be a compelling choice when control over the process is not required. Finally, the authors briefly point out how to develop optimization algorithms using quantum annealers, how some machine learning methods can be applied using quantum computing, and how to adapt the Monte Carlo method to a quantum version, which has already demonstrated a quadratic speed-up. Egger et al. [7], from a quantum research group in IBM, give an overview on the current state of quantum algorithms used in Finance. They divided them in three main areas: • Simulation

• Optimization

• Machine Learning The focus here will be specifically on optimization in combinatorial problems, where Portfo- lio Management is included. Most of the literature on Portfolio Management has been done using quantum annealing, here the authors present how the same problems can be solved using gate- based quantum computers. Given that Portfolio Management is a QUBO problem, they advocate for the use of approximation algorithms instead of quantum annealing. The Quantum Approxi- mate Optimization Algorithm (QAOA) and the Variational Quantum Eigensolver (VQE) being the industry standards. They note that both QAOA and VQE do not theoretically guarantee a speedup when compared to the classical algorithms finding exact solutions, but they are guaranteed to find a solution of specified quality in polynomial time. This poses great interest in the exploration of near-term capabilities of gate-based quantum computers as it can demonstrate quantum advantage when the hardware matures. QAOA and VQE are based on the variational method of quantum mechanics. The method is used to find the ground state (minimum eigenvalue) of Hamiltonians when searching through all possible states is intractable. The Hamiltonian is an operator that describes the total energy of the system. To find the ground state of the Hamiltonian, a subset of the complete Hilbert Space is chosen by parameterization, this is done by using a set of parameters to select the ansatz (subspace for each iteration). The method has two phases, a quantum part that calculates the minimum eigenvalue for the given ansatz, then a classical part updating the parameters through a classical optimization algorithm that generates the next ansatz. These two phases are repeated until a near-optimal solution is found. 18 Literature Review

To compare results with a brute-force approach, the diagonalization of the Hamiltonian is used. This technique finds the eigenstates and corresponding eigenvalues of the system optimally. As expected, it scales exponentially with the Hilbert Space dimension. Simple experiments were conducted for the classic case of Portfolio Management, showing promising results for further experimentation. In the experiment, results from VQE specifically were found in the efficient frontier, as seen in Subsection 2.2.2, with the optimal results from brute- force search. However, this experiment was done in a small scale portfolio of only six assets, so research with more data is needed. Zahedinejad et al. [20] surveyed current state of the art on solving combinatorial optimiza- tion problems using gate-based quantum computers. It is argued that the field is divided in four approaches:

• Digitizing adiabatic quantum computing (AQC);

• Global quantum optimization;

• Approximation of ground state from QUBO problem;

• Quantum sampling.

Similar to Egger et al., they note the already large body of literature for solving QUBO problems using quantum annealing, so this approach is omitted from the survey. Digitizing AQC is the manipulation of the time evolution of the system though a set of one and two qubit gates forming an operator. To simulate AQC, we use this operator to evolve the system’s Hamiltonian from an initial state of uniform superposition to the ground state (global minima) of the problem Hamiltonian. The number of gates needed to perform this method is in order O(MIk), where M is the number of time steps of the time evolution, k is the maximum amount of qubits an Hamiltonian acts on, and I is the number of Hamiltonians that compose the system’s Hamiltonian. Global quantum optimization uses Grover’s search algorithm as a subroutine to find the global minima of an Hamiltonian. Figure 3.1 (p. 19) depicts the general structure of a quantum optimization algorithm. It starts with an initial solution, performs a Grover’s search subroutine to find a solution with lower cost, if successful we replace the initial solution with the new lower cost solution. If the search fails or we achieve a stopping criteria the algorithm ends, otherwise, we optimize the Grover’s search subroutine through known algorithms, which can be independent of the problem. Grover’s search √ complexity is O( 2N), given that we repeat this subroutine until a criteria is met, the complexity is maintained. Approximation of the ground state from QUBO problems refers to variational methods seen above by Egger et al., and the author explains the same process. Quantum sampling refers to the quantum version of the Metropolis sampling. In the classi- cal version, the algorithm starts with an initial state and follows with a series of update rules to bring the state to a lower energy state. If the result configuration has lower energy we accept the new state, otherwise to prevent being trapped in a local minimum the new state is accepted with 3.3 Quantum Finance, using quantum annealing 19

Figure 3.1: Flowchart denoting the general structure of a quantum global optimization algorithm iteratively employing Grover’s search algorithm as a subroutine [20]

β(E −E ) probability e old new , where β is a constant, Eold the current state and Enew the new configu- ration. The quantum version uses the quantum phase estimation2 algorithm to iteratively sample lower energy states. Similar to the classical version it accepts new states with lower energy and otherwise it accepts the new state with the probability from the classic version defined above. Concluding, the authors present several areas of research on combinatorial optimization using gate-based models.

3.3 Quantum Finance, using quantum annealing

We now analyse quantum annealing solutions for Portfolio Management. This has been the default choice for Quantum Finance research. Although we are not going to use such technology in this work, there is a benefit to assess its current state. Given that we model quantum annealing algorithms similarly to certain gate-based algorithms, we can use the expertise from their research on quantum annealing that overlaps with our work. Muguel et al. [13] propose a dynamic hybrid quantum-classical algorithm for portfolio op- timization with a minimal holding period for each asset. The algorithm finds the near optimal investment trajectory over a period of time for an investor’s portfolio, given a specified level of risk.

2For more information on the quantum phase estimation we refer the reader to the Qiskit Textbook. 20 Literature Review

It takes an hybrid iterative approach, meaning that it uses classical and quantum computing (hybrid) and does not compute the entire investment trajectory at the same time, it iteratively computes the best trajectory at each time-step with past portfolios pre-selected. At each time-step quantum annealing is used to find the near optimal investment trajectory. Using classical computing it filters solutions that do not respect the minimum holding period. To compute cost at each time step the Markowitz’s Modern Portfolio Theory cost function is minimized:

T γ T H0 = ∑−µt ωt + ωt Σt ωt (3.1) t 2

here t represents the corresponding time-step, µt is the vector of expected returns, wt the fraction of money invested in each stock, γ is the risk profile and Σt is the covariance matrix. The first term represents expected returns and the second the risk associated with the investment trajectory of the portfolio. The cost is calculated by the sum over the investment trajectory of two components, the nega- tion of the expected returns of the portfolio at each time step (first term), added with the chosen portfolio variance at each time-step multiplied by the risk profile parameter (second term). Ex- pected returns and covariance matrices can be retrieved from past market data. The minimum holding period constraint is used for cases where short term trades are taxed at a higher rate than long term trades, so this parameter ensures this holds at every trade. The number of investment trajectories grows exponentially for each time step computed:

K×Nt O(Na ) (3.2) here Na is the number of assets, K is the specified number of assets for the portfolio and Nt the number of time steps needed to compute the investment trajectories. With such scaling, the authors opted for an iterative approach, using quantum annealing to find a near optimal investment trajectory at each time step and classical computing to rule out trajectories which do not fulfill the minimum holding period. This filtration is based on the Sharpe Ratio of the solution – a risk adjusted expected return. With this simplification the problem is effectively reduced to a variation of the single time-step portfolio optimization. The difference is in the cost function, which uses a sequence of portfolios instead of just one. To solve the problem of encoding the percentage of portfolio allocation for each asset into the qubits, a binary encoding was used:

Nq−1 1 q ωn = ∑ 2 xn,q (3.3) K q=0

here xn,q is a binary variable that indicates if for asset n the position q of the binary encoding q is one, 2 xn,q encodes the allocation for asset n using binary encoding. Dividing by the number of possible assets in the portfolio, K, yields the allocation of asset n in the portfolio. 3.3 Quantum Finance, using quantum annealing 21

Figure 3.2: Results from investment trajectory algorithm and random portfolios [13]

To favour valid solutions in the minimization function the following constraints are added:

• Reward solutions with all the money invested;

• The sum of assets held at time-step t needs to be equal to a number K specified by the investor;

• The maximum portfolio allocation for each asset is limited to x% of the portfolio where x is a parameter defined by the investor.

To reduce the space of solutions searched, the assets are grouped in clusters based on their time-series similarity. Time-series represents the evolution of asset prices recorded at regular intervals over a period of time. Then, only the asset with the best historical Sharpe Ratio is kept in each cluster.

The number of clusters used (Nc = 7) is based on analysis of past data, where it was concluded that the mean variance of each cluster did not change significantly for a number of clusters larger than 7. To test the algorithm the authors simulated an execution from May the 31st 2019 to May the 31st 2020 on a set of 50 international assets and indices, for different risk profiles (minimum risk, 5%, 10%, 15%, and 20% annual risk) with results shown in Figure 3.2. The solutions retrieved seem to be close to the efficient frontier, but given that not all solutions were plotted we cannot validate this conclusion. Given that only random portfolios were used for comparison, the quality of results is hard to analyse from a reader’s point of view. However, the results we see are promising, achieving for example, 40% annualized profit for a portfolio with 8% annualized volatility. Concluding, Mugel et al.propose various improvements to current approaches to Portfolio Management using quantum computing, mainly: the hybrid quantum-classical approach to solve 22 Literature Review the minimum holding period, clustering of data to reduce the solution space and binary encoding for portfolio allocation. Rosenberg et al. [18], similar to Mugel, solve the optimal trading trajectory problem using a quantum annealer. Two things differ from Mugel, the Hamiltonian defined and the encoding of asset allocations, this last difference is not relevant for the present work, as it discusses the impact of each encoding on a quantum annealer. The main difference is accounting for transaction costs and the market impact of the trading activity. They define the problem as:

T T γ T T T 0 w = ∑(µt ωt − ωt Σt ωt − ∆ωt Λt ∆ωt + ∆ωt Λt ωt ) (3.4) t=1 2 The formulation is a maximization function. The first two terms represent the sum of expected returns of the holdings ω and the risk of the portfolio, following what we’ve seen on the Modern Portfolio Theory Subsection 2.2.2. Additionally two more terms are used. The first encodes the transaction cost with temporary market impact, Λt , which is the price paid to execute the order added with the temporary conse- quences of a large buy order. The second is the permanent market impact of executing a large buy 0 order, Λt , a large buy order means less shares being traded, which reduces supply, consequently increasing the asset price and the returns. However, the authors do not give insight on how the market impact can be calculated. An extension to the problem is also suggested, instead of calculating risk with estimations of the covariance matrix at each time-step, it is proposed to be calculated by the variance of the returns from the proposed trajectory:

T T γ T 2 1 T T risk[ω] = ∑[(µt ωt ) − ∑ (µt ωt )(µt ωt0 )] (3.5) T t=1 T t0=1 here the variables follow the same naming from the Modern Portfolio Theory Subsection 2.2.2. The risk is assumed to be the mean of differences between the risk at time-step t (first term) with the risk at all other time-steps (second term). As before, the risk is multiplied by γ, representing risk aversion. Concluding, although this work was similar to Muguel’s, several extensions to the cost function are presented, which can help when creating our solution.

3.4 Quantum Approximate Optimization Algorithm (QAOA) and Quan- tum Alternating Operator Ansatz (QAOA+)

We will now analyse the target algorithm for this research, QAOA. It has the potential to show quantum advantage, but until now, no theoretical or practical demonstration has been made that supports this. Given its low requirements in terms of circuit depth and number of qubits necessary, it is also considered as one of the first quantum algorithms that will be ran successfully on near- term quantum computers. 3.4 Quantum Approximate Optimization Algorithm (QAOA) and Quantum Alternating Operator Ansatz (QAOA+) 23

Farhi et al. [8] present the Quantum Approximate Optimization Algorithm (QAOA), that finds approximate solutions for Combinatorial Optimization problems. These are represented by an objective function that encodes the costs of satisfying, or not, each clause of the problem. The algorithm is based on two parameterized operators. The cost operator U(C,γ), which encodes information about the problem via phases in the qubits:

m U(C,γ) = e−iγC = ∏ e−iγCα (3.6) α=1

here γ is the operator parameter, and Cα a boolean indicating if clause α is satisfied. And the mixer operator U(M,β) that shuffles the qubits to prevent the algorithm to be stuck on local optima:

n x U(M,β) = e−iβM = ∏ e−iβσ j (3.7) j=1

x here β is the operator parameter, M the operation of shuffling qubits, and σ j is the single qubit operator x for shuffling qubit j. Then we have the initial state |si, or ansatz, which is an equal superposition of all possible states:

1 |si = √ |zi n ∑ 2 z

The parameters γ and β are vectors of size p, where p >= 1, with γ = γ1...γp and β = β1...βp. The cost and mixer operator are then applied p times to the initial state |si:

|γ,βi = U(M,βp)U(C,γp)...U(M,β1)U(C,γ1)|si

It is demonstrated that |γ,βi will result in the optimal solution for p → ∞ and that if we optimize the parameters we can get an approximation of the optimal solution for smaller values of p. The entire algorithm is composed of two parts, as we can see from Figure 3.3 (p. 24). A classical part that selects the parameters and optimizes their selection, and a quantum part that computes the result state by applying the parameters and measuring the circuit. It first starts by making a guess of a good set of parameters. Then the quantum algorithm runs the parameterized circuit and evaluates the solution. Using a classical optimizer the parameters are changed and we repeat this cycle until we achieve a stopping criteria. This criteria is managed by the classical optimizer, it can stop by reaching the maximum number of iterations or failing to achieve better solutions. The result is an approximate solution to the problem that minimizes or maximizes the objective function. Hadfield et al. [9] propose a more generic formulation of the QAOA, the Quantum Alternating Operator Ansatz, allowing for a more generic family of mixer operators to be used. This family 24 Literature Review

Figure 3.3: QAOA high-level overview. Gray boxes are executed by a classical computer and yellow boxes by a quantum computer or simulator. restricts the evolution of the algorithm to states that satisfy all the constrains, the feasible subspace. This is different from the original QAOA where all solutions, valid or invalid, can be evaluated. Given that the acronym is the same as the original version, from now on we’ll refer to this version as QAOA+. The circuit is caracterized by:

• A cost operator UC(γ) that encodes the costs of the objective function, this is maintained from the original version;

• A mixer operator UM(β) that depends on the domain and structure of the problem. here γ and β are real parameters. Similar to QAOA, the circuit consists on p alternating applications of the mixer and cost operators to an initial state:

|γ,βi = U(M,βp)U(C,γp)...U(M,β1)U(C,γ1)|si (3.8)

here the initial state is trivial to implement and satisfies all the constrains, meaning that it belongs to the feasible subspace. Generally we deal with constraints that need to maintain a Hamming weight of K between some or all of the qubits – i.e, the number of qubits from the group that is evaluated to |1i is K. In the original QAOA, constraints were enforced via penalty terms in the objective function, where the mixer shuffled qubits randomly, regularly evaluating invalid states. In QAOA+ con- straints are enforced through the mixer, this creates a large reduction of the amount of states that we search as the constraints are effectively encoded into the circuit. In order for this to happen the mixer needs to satisfy two properties:

• Preserve the feasible subspace on all mixing operations

• Provide transitions between all pairs of feasible states 3.5 Quantum Finance, using universal quantum computers 25

Satisfying these two properties, and with an initial state that is in the feasible subspace we auto- matically enforce the constraints. An important aspect is that the cost operator does not affect the feasible subspace, only the phases of each qubit. The paper proceeds to work through common optimization problems and solving them using QAOA+, proposing different mixers. One such mixer that will be used on our solution is the ring mixer. This mixer provides transitions in a ring shape structure. It provides transitions between all pairs of feasible states while maintaining a global Hamming weight. In a Portfolio Management problem the Hamming weight could be the number of assets the investor wants to select for the portfolio. The ring mixer is given by:

Uring(β) = Ulast (β)Ueven(β)Uodd(β) (3.9)

Even and odd is the parity of the qubits and last is the last qubit. Each unitary is given by:

−iβ(XaXa+1+YaYa+1) −iβ(XaXa+1+YaYa+1) Uodd (β) = ∏ e , Ueven (β) = ∏ e a odd, a6=n a even ( e−iβ(Xd X1+YdY1), d odd Ulast (β) = I, d even Such "XY" two qubit gates represent a SWAP operation which can be parameterized by an angle β. First, Uodd swaps, in parallel, odd parity qubits with their consecutive qubit, followed by

Ueven on even parity qubits. If the number of qubits is odd a swap between the last and first qubit d is also performed. If the mixer is performed 2 times (d being the number of qubits) the second condition for the mixer is satisfied, given that we achieve all the feasible states. The advantages of QAOA+ are the faster convergence to the optimal solution and that it dra- matically decreases the state space searched, specially as the number of qubits grows. The disad- vantage is the increase in circuit depth, however this is expected to be negligible when compared to the improvements achieved by restricting the state space. This work poses great interest for the current work, as QAOA is the main target for solving Portfolio Management problems and a comparison between the two versions for some of them has not yet been done.

3.5 Quantum Finance, using universal quantum computers

As previously referred, Portfolio Management algorithms using gate-based models are scarce, so this group only has one literature analysis. Nonetheless, it encompasses most of what we need as foundation for the next chapter. Hodson et al. [10] analyses how to solve the Portfolio Rebalancing problem on gate-based quantum computers. The objective is to find the optimal portfolio that minimizes the trading costs over a period of time. 26 Literature Review

Figure 3.4: Description of mixer structure from [10]

The possibility to take short positions was also added, short positions are financial instruments that appreciate when the underlying price of the asset goes down. Two possible solutions were analysed. The first is the original QAOA, where constrains are applied by adding penalty terms to the objective function, same as quantum annealing. The second is the QAOA+ [9], where constrains are enforced using two ring mixers. The goal is to find an investment portfolio of D positions, selected from a set of N positions, N or 2 assets, as each asset has two possible positions, long and short, as seen in Subsection 2.2.1. From Hadfield’s work we know that an initial state needs to be trivial to implement. The following initial state was selected:

⊗D 1 1 ⊗N−D |ψ0i = |01i ⊗ (√ |00i + √ |11i) (3.10) 2 2 Also from the same work we know that the mixers need to:

• Preserve the feasible subspace

• Provide transitions between all feasible states

Here two mixers are applied, one to long positions and the other to short positions, as illustrated in Figure 3.4. By entangling every short and long position after the first D assets (second term of the initial state) we satisfy the first condition of the mixer. However, this does not provide a transition between all pairs of valid states (second condition), for example, a state where the last asset has a long position and not a short position is not possible given the entanglement between these two instruments. The authors note this problem and leave it as future work. The difficulty in creating an initial state that satisfies this property comes from the need to be trivial to implement, created by a constant-depth circuit proportional to the problem. Regarding results, no information about how much time the algorithm takes or how it scales was presented. However, the authors concluded that to make the mixing process faster yearly data should be used instead of daily data. 3.6 Literature Analysis 27

Additionally, QAOA+ was found to achieve better solutions in this problem, when compared to QAOA. In most cases, QAOA+ solutions had less trades and risk while achieving better returns.

3.6 Literature Analysis

From the first group, Orrell and Schaden present two fundamentally different ways to approach Finance by leveraging quantum. Although ultimately none of them were applicable to our work in Portfolio Management, they show that we cannot only research where quantum can bring speedups to current algorithms, but also where it might provide a fundamentally different approach that is more adequate than current processes. The surveys group brings a clear view of the competitive landscape that quantum is going through. On one side a large push for quantum annealing is being done given its commercial availability. On the other, companies building gate-based quantum computers admit how far they are from any kind of commercial availability but argue that working on quantum software is nec- essary, not only to bring the gap between hardware and software closer together through software but also to make future adoption faster. Egger brings a more balanced perspective, noting the large body of research on quantum annealing and the opportunities in gase-based quantum computers, with algorithms such as QAOA and Global Quantum Optimization. The last three groups are the basis for our work. Given that Portfolio Management problems are encoded as a QUBO, we were able to base the encoding on what is currently being used in quantum annealing solutions for Finance. From the surveys, we learned that QAOA was the appropriate quantum algorithm to explore combinatorial optimization problems in the near-term. We analysed QAOA and its recent new version, QAOA+, as the target algorithm. Finally, the Portfolio Rebalancing problem showed how can we use QAOA+ to solve a Finance problem. Important to note that this problem is similar to the problem we tackle in the next chap- ters. However, several aspects were missing from their research. The details of implementation were not described or explored, an in-depth comparison between QAOA and QAOA+ is missing, and analysis of the results and algorithms are also not performed. For this reason we opted to solve the Portfolio Management problem with QAOA and QAOA+, while performing an in-depth analysis, comparison and description of the implementation using a perfect quantum simulator. 28 Literature Review Chapter 4

Problem Statement

4.1 Problem ...... 29 4.2 Main hypotheses ...... 30 4.3 Contribution ...... 30 4.4 Scope ...... 31

4.1 Problem

The goal of this work was to assess how can we solve a Portfolio Management problem using quantum computing, specifically using gate-based quantum computers. Several quantum annealing implementations were already exhaustively researched, as seen in Chapter3 (p. 15). However, research on the same problem using gate-based quantum computers is still scarce, even though this technology offers a much wider range of possibilities. During the literature review two areas were clearly lacking:

• Analysis of QAOA in the context of Portfolio Management. Understand what are the scaling limitations and bottlenecks that should be expected from applying these algorithms to this topic. Additionally, explore the structure that problems need to have to be solved using QAOA. This analysis should give a clear picture of what we can do on this context using simulators and quantum computers in the future. This can guide future research on Quantum Finance using gate-based quantum computers.

• Comparison between QAOA and QAOA+. Recently, Hadfield et al.proposed a generic formulation of QAOA but analysis of QAOA+ is still scarce. Describing how is it imple- mented and what are the scaling limitations that should be expected is missing. Additionally, an analysis of the differences in implementation from the original QAOA is needed to be able to use QAOA+ for Portfolio Management.

29 30 Problem Statement

This comparison could drive adoption of QAOA+, by exploring the advantages of this ver- sion. Such advantages are: the faster convergence; reduction in solution space and alterna- tive possibilities to encode constraints.

4.2 Main hypotheses

This work was developed around the following hypotheses:

Given a Portfolio Management problem it can be solved using gate-based quantum computers, more specifically with QAOA and QAOA+. QAOA+ provides advantages over the original version. These advantages can either be in: constraints enforcement; quantum simulator execution or quantum computer execution.

The validation of the hypotheses is not straightforward, given that we are using simulators that are not able to scale to real-world scenario requirements. However, as mentioned in Subsec- tion 2.1.9 we’ll measure execution time, memory consumption, number of gates, qubit require- ments, classical loop iterations and circuit depth of the algorithms. There are three areas where we can observe advantages between algorithms.

1. Constraints enforcing, that is, being able to enforce constraints that are not possible on the other version.

2. Quantum simulator execution, a speedup is observed when compared to the other version when ran on quantum simulators. This advantages are only achieved on simulators. This will allow current research to explore larger problem sizes.

3. Quantum computer execution, where a potential speedup compared to the other version is identified for future error-corrected quantum computers.

An execution of the solution for 15 assets was performed. The decision to choose 15 as the number of assets was based on being almost the largest number of assets we were able to test, while allowing for the comprehensible analysis of results in Chapter5 (p. 33). Additionally, during the chapter it will be discussed if and how these algorithms can be modelled to tackle more complex instances of Portfolio Management, for example, without some of the simplifications made in this work.

4.3 Contribution

The contribution from this work is the experimental evaluation of QAOA and QAOA+ in the con- text of the Portfolio Management problem. Given that QAOA+ was not implemented in Qiskit, an analysis of the process taken to implement it is also described. We explore the process taken 4.4 Scope 31 to design and implement a solution for the Portfolio Management problem on quantum comput- ers using both QAOA and QAOA+, investigate differences in constraints addition and how both algorithms compare for this problem.

4.4 Scope

The Finance problem this work tackles is the single time-step portfolio management: What is the optimal portfolio of N assets that minimizes risk and maximizes returns for a given risk profile. To make this work feasible several assumptions were made.

4.4.1 Perfect qubits

As discussed in Subsection 2.1.8 we assume that we are executing our solution on a quantum computer with perfect qubits, meaning that qubit decoherence and error rates from gate operations are ignored. To accomplish this we used a perfect quantum computer simulator that ignores phys- ical restrictions. As also mentioned it is of interest to understand how these algorithms compare regarding to their execution in the simulator, as we expect to be the default setting for algorithm research in the coming years.

4.4.2 Finance assumptions

We followed the assumptions that were found on most of the literature review:

• Expected returns of each asset are the mean annual returns from past market data;

• Risk of the portfolio is the portfolio variance, which is how much the returns can deviate from what is expected, also taken from past market data;

• Risk profile is represented by a positive scalar that increases or decreases the weight of the risk term in the cost function;

• Money that is available to invest is assumed to be the number of assets to select. This means 1 that each asset selected has the same weight in the portfolio, N . All the money needs to be spent, meaning N assets need to be selected;

• The investor has enough money to buy any asset. This is a common simplification as many brokers already allow the possibility to acquire fractional shares, independent of the under- lying asset price.

4.4.3 Qiskit

The platform used to create the solution was IBM’s Qiskit [2]. It provides a wide range of tools that abstract common obstacles for quantum programming, more specifically: 32 Problem Statement

• A growing Finance library, where we can find, for example, the basic version of QAOA being used for Portfolio Management

• Perfect quantum simulators

• Original version of most quantum algorithms already available to use or compare, QAOA being one of them

• Classical optimizers, which are used in QAOA, already implemented and ready to use

• Abstraction of the problem encoding step, which simplifies the creation of the cost function and addition of possible constraints.

• Open-source and with several learning resources available Chapter 5

Implementation

5.1 Data ...... 33 5.2 Portfolio Management base problem ...... 35 5.3 Quantum algorithms ...... 36 5.4 Constraints ...... 41 5.5 Overview of the solution ...... 45 5.6 Initial analysis ...... 45

In this chapter the approach taken to implement the solution is described. It starts with the data retrieval process, explores QAOA and QAOA+ targeted to Portfolio Management and finishes by exploring the results of using our solution for a possible scenario of 15 assets.

5.1 Data

For this work the YahooFinance API was used to have access to historical data. Figure 5.1 gives an overview of how data was retrieved.

Figure 5.1: Data retrieval process.

33 34 Implementation

It starts with getting the price at the end of the day during the time period selected for each asset. To normalize the data we take the natural logarithm of the difference between prices in con- secutive days:

pt logrt = log (5.1) pt − 1

here rt is the log returns at the end of day t and pt the price at the end of day t. As an example, let’s take Apple (AAPL) and Microsoft (MSFT):

p AAPL MSFT 1 100 200 2 110 210 3 120 205

logr AAPL MSFT logr AAPL MSFT 110 210 = 2 log 100 log 200 2 0.04 0.02 120 205 3 log 110 log 210 3 0.04 -0.01

For the expected returns we calculate the mean of the log returns for each asset:

T ∑ rt µ = t=1 (5.2) x T

here µx is the expected return of asset x, T is the total number of days with available data, and rt the log returns at each day t. Following Equation 5.2, using the log returns we calculate the expected returns of each asset:

logr AAPL MSFT 2 0.04 0.02 3 0.04 -0.01

AAPL MSFT AAPL MSFT (0.04+0.04) (0.02+(−0.01)) = µx 2 2 µx 0.04 0.001

The covariance matrix encodes how correlated assets are and is given by: 5.2 Portfolio Management base problem 35

T ∑ [(xt − x) · (yt − y)] Cov(x,y) = t=0 (5.3) T

here x and y are two assets, xt is the log return of asset x at day t, x is the mean of log returns of asset x, and T is the number of days with available data. Following Equation 5.3, using the log returns we calculate the covariance matrix:

logr AAPL MSFT 2 0.04 0.02 3 0.04 -0.01

Cov AAPL MSFT Cov AAPL MSFT (0.04−0.04)·(0.04−0.04) (0.04−0.04)·(0.02−0.01) = −7 −6 AAPL 2 2 AAPL 5 · 10 8 · 10 (0.04−0.04)·(0.02−0.01) (0.02−0.01)·(0.02−0.01) −6 −4 MSFT 2 2 MSFT 8 · 10 1.3 · 10

In the diagonal line we have the variance of each asset, meaning how volatile is the asset. Non-diagonal elements contain the correlation between each asset, 1 being maximum correlation, and -1 maximum opposite correlation. The covariance matrix is used to assess the portfolio risk. The expected returns of each asset to calculate the expected return of the portfolio. The covariance matrix and expected returns vector are then multiplied by the number of trading days, 253.

5.2 Portfolio Management base problem

The base problem encoding is the same for both QAOA and QAOA+. For this work, and following the common approach in the literature review, we used the dis- crete/binary model of the Modern Portfolio Theory:

γ Cost Function = −µT ω + ωT Σω (5.4) 2 here ω is the vector of binary decision variables, meaning which assets were chosen to include in the portfolio, µ is the expected returns of the assets available, µT ω gives us the expected returns of the portfolio, Σ the covariance matrix and ωT Σω gives us the risk of the portfolio, it is then divided by two. γ is usually a positive scalar that represents the risk profile of the investor. A large γ corresponds to a conservative profile as it gives more weight to the risk term compared to the expected returns term. A smaller γ corresponds to a risky profile as it gives less weight to the risk term. 36 Implementation

Figure 5.2: QAOA circuit (p=1).

5.3 Quantum algorithms

From the literature review QAOA and QAOA+ were selected as the best candidates for Portfolio Management.

5.3.1 QAOA

As mentioned before QAOA consists on alternating between running a parameterized quantum circuit and classically optimizing the input parameters.

|γ,βi = U(M,βp)U(C,γp)...U(M,β1)U(C,γ1)|si (5.5)

The classical part of the algorithm will not be analysed on this work, and the optimizer chosen was Qiskit’s default optimizer, SLSQP1. The default SLSQP settings use a precision goal of 10−6 for the stopping criteria and a maximum number of iterations of 100. The stopping criteria for QAOA is dependant on the optimizer used. Regarding the quantum part there are three important sections that make up the circuit, which is shown in Figure 5.2 for a five qubit example. Two dashed lines, or barriers in Qiskit, were added to separate the three sections: construction of the initial state, cost operator, and mixer operator. First, the initial state, a superposition of all possible states. This is created by applying an Hadamard gate to all qubits. Possible states also include states that do not satisfy all constraints, we’ll refer to these from now on as unfeasible states. Second, the cost operator, which encodes the cost function and is parameterized by γ mul- tiplied by the corresponding cost. The objective is to encode as phases on the qubits the cost of choosing the asset related to the qubit. This operator is divided in two main operations that depend on the cost function term in question. Quadratic terms with two different variables, meaning two

1More information can be found on the Qiskit documentation 5.3 Quantum algorithms 37 assets, and terms related to one single variable. Two different variable terms are represented as a ZZ interaction, which means that both variables are selected. Qiskit implements this by applying between two CNOT gates a RZ gate parameterized by the cost and multiplied by γ. For terms with only one variable the RZ gate is applied in the same manner except this time CNOT gates are not used. In the circuit, this corresponds to the last RZ gate applied for each qubit inside the cost operator, the circuit section between the two dashed lines. Third, the mixer operator, which are RX gates parameterized by β on each qubit, the goal is to shuffle qubits and prevent the algorithm to get stuck on local optima. The circuit depth of QAOA is:

Circuit Depth = p · (6 · N − 12)

Where p is the number of alternations of the operators and N the number of assets available. Given that Farhi [8] demonstrated that for p = 1 a close to optimal solution can be achieved, the rest of the work maintains p constant. Regarding Qiskit, an implementation following Farhi’s work is already implemented. To solve a Portfolio Management problem using QAOA we need to build a cost function for our problem that can be sampled efficiently, meaning that if penalty terms are too large, then the classical optimizer will do a poor job optimizing the parameters, if they are too low then infeasible solutions might be chosen. One important aspect to note is that both operators are built via a process called Trotterization2. It uses a time evolution operator, meaning that the operator is described by an Hamiltonian in matrix form and a variational parameter t. For QAOA, the prior corresponds to the cost and mixer Hamiltonians, and the latter to angles β and γ. Using this method, when it’s time to build the circuit, Qiskit iterates over evolution operators and matches them with a set of quantum gates that approximates the operator. In QAOA there are two evolution operators, the cost and mixer operators. The mixer is then built using the following operator:

⊗D U(M,β) = e−iβ(X ) (5.6)

Where D is the number of assets available.

5.3.2 QAOA+

Since Preskill [17] introduced the NISQ concept, several authors have proposed that algorithms like QAOA, should be researched in order to close the gap between the state of quantum hardware and quantum software through work on the top layers of the stack. The main objective is to bring quantum computers to fruition faster. QAOA+, by being an extension to what can be considered

2For more information we refer the reader to Qiskit’s documentation on Trotterization 38 Implementation one of the first quantum algorithms that will be ran on quantum computers, naturally has great relevance for our research. This version has two main advantages. The first is being able to expand the complexity of constraints that we can use, given that certain constraints might be difficult to add via penalty terms. We will explore constraints addition in this chapter. The second is restricting the state space exploration of the algorithm to the set of feasible states. This has several advantages. When ran on a quantum computer this has the potential to reduce the amount of classical QAOA loops, which will reduce the algorithm execution time. On quantum simulators the execution of the algorithm will be much lower, as less states need to be tested. Although this last advantage may not be achieved on real quantum computers, current high- level algorithmic research will benefit, as larger and more relevant problem sizes can be explored with perfect quantum simulators. Although Hadfield et al.define various implementations of the mixer, in this work we’ll refer to the ring mixer as the default mixer of QAOA+, given that it provides transitions to all feasible states while minimizing repetition of transitions. As described in the literature review here is the ring mixer formulation:

Uring(β) = Ulast (β)Ueven(β)Uodd(β) (5.7) here even and odd is the parity of the qubits and last is the last qubit. Each unitary is given by:

−iβ(XaXa+1+YaYa+1) −iβ(XaXa+1+YaYa+1) Uodd (β) = ∏ e , Ueven (β) = ∏ e a odd, a6=n a even

( e−iβ(Xd X1+YdY1), d odd Ulast (β) = I, d even

This mixer performs swap operations that are parameterized by angle β, in a ring fashion. First it swaps odd parity qubits, then even parity. Additionally, if the last qubit is odd parity it swaps it with the first qubit. The resulting QAOA+ circuit is presented in Figure 5.3 (p. 39) for a 5 qubit example. Two barriers were added to separate the initial state, the cost operator and the mixer operator. |1i |0i (5.8)

Comparing to the original version, QAOA+ differs in two aspects. First, the initial state, which instead of being a superposition of all possible states is instead any subspace that only includes feasible states. Feasible states are defined as valid solutions, meaning that they satisfy all constraints the problem imposes. This initial state needs to be trivial to implement. In the original paper it was recommended that a single feasible state was constructed. 5.3 Quantum algorithms 39

Figure 5.3: Current version of QAOA+ circuit (p=1). 40 Implementation

Figure 5.4: Example of QAOA+ with parameterized swap gate implemented.

This is achieved by first selecting a valid solution and applying X gates on the qubits that match that solution.

Second, the mixer needs to maintain the state in the feasible subspace while providing transi- tions between all possible states.

The cost operator is maintained.

Regarding Qiskit, there was no implementation of QAOA+. We followed the original formu- lation to apply the mixer. As an example, the parametrized swap between the first and last qubit, which is the last operator to be applied in Equation 5.7, is constructed as:

− 1 iβ((XI⊗D−2X)+(YI⊗D−2Y)) Ulast(β) = e 2 (5.9)

1 here D is the number of available assets. The 2 was added to normalize the resulting matrix. The parameterized swap gate that is used in the ring mixer, is not yet implemented. Conse- quently, the Trotterization step described in Subsection 5.3.1 matches the parameterized swap gate with a large set of quantum gates, as seen in Figure 5.3 (p. 39). This will have implications on the solution performance.

Although this gate is not yet available in Qiskit, it is expected that they add it in the near- future given recent research on how to implement the parameterized swap gate, also known as parameterized XY gate, on superconducting quantum computers [1], the technology used by IBM.

In the future, when the gate is implemented we can expect a circuit in the form of Figure 5.4, where SWAP gates would be substituted by parameterized SWAP gates. This will achieve a large reduction in circuit depth, and consequently execution time, when compared to our current solu- tion. 5.4 Constraints 41

5.4 Constraints

We’ll now explore how constraints are implemented, which is the main difference between both al- gorithms. Experiments performed in this work only use the following constraint: elect the number N of assets to include in the portfolio. However, given that a significant amount of time was dedicated to explore the possibility of implementing other constraints and some of them have not been implemented, these are also discussed.

5.4.1 Constraints as penalty terms

Similarly to quantum annealing, QAOA encodes constraints into penalty terms. Equation Equation 5.4 is a minimization function. Negative terms penalize the solution in question, which is the case of the risk term in the cost function. On the other hand, positive terms reward the solution, which is the case of the expected returns term. To eliminate solutions that do not satisfy some problem constraint we add a penalty term that is applied when the condition is not met. To build this term we construct an equation that is zero or close to zero when the constraint is satisfied, this way we can separate valid from invalid solutions. When it’s not zero, we square it to make it positive and multiply it by a positive scalar, the result should be a large penalty term that discards invalid solutions. The constraints explored during this work were:

• Select the number N of assets to include in the portfolio

• Favour certain asset sectors

Ultimately, for comparison purposes, only the first constraint was used. Which will be the constraint used in all data retrieved for analysis. To specify the number of assets to include in the portfolio we use the following penalty term:

Penalty term = P(onesT w − N)2 (5.10)

Where ones is an auxiliary vector of ones, w is the vector of binary decision variables, onesT w gives the number of assets chosen by the algorithm, and N the number of assets specified by the investor. P is a positive scalar to scale the penalty term, which is a sufficiently large number to discard the solution. When onesT w and N are equal, the condition is satisfied, the expression results in zero and has no impact in the cost function. Otherwise, the expression results in a non- zero value, gets squared to eliminate possible negative values, and is scaled by P, penalizing this solution. The penalty term cannot be negative due to the square applied and P being positive, so it is either zero or a positive value, as we can see below: 42 Implementation

 = 0 if onesT w = N Penalty term > 0 if onesT w 6= N

We empirically found that setting a penalty scalar of value 100 is sufficient to efficiently dis- card unfeasible solutions. To favour certain sector the approach is slightly different:

−P(onesT w) (5.11)

here, instead of a penalty term we have the opposite, a reward term. onesT w is the number of assets from sectors that we wanted to favour, and P is a positive scalar. This term will reward solutions that have the most sectors that the investor wanted to favour. One important difference regarding the previous constraint is that here P is not a large number, given that we are not dis- carding invalid solutions but giving a small reward for solutions that include the specified sectors. The ideal situation would be a scenario where the investor can choose the sector allocation, meaning how much of the portfolio should be allocated for each sector, which is equivalent to selecting the number of stocks chosen for each sector. This however, is not straightforward to do with QAOA, as it involves signaling states where all the sectors have the pre-determined number of assets selected simultaneously. During the work we also explored the possibility to use binary encoding on the problem, instead of having only the possibility to choose one asset or not, with binary encoding we have the possibility of having different weights for each asset. Instead of assuming that the money available to invest is the number of assets to select, the money in this case is the number K of possible allocations, a more realistic scenario. Contrary to before, we can invest multiple allocations in the same asset. The formulation used is the same from Mugel et al.[13]:

Nq−1 1 q wn = ∑ 2 wn,q (5.12) K q=0 here wn is the portfolio allocation dedicated to asset n. K is the number of allocations. Nq is qubit number q, where qubits are only associated with the asset in question. wn,q is the selection of the binary value associated with position q and asset n. Qiskit actually simplifies this step with their encoding abstraction, we only need to specify that instead of binary these are integer variables, as well as the lower and upper bound. However, there are two challenges that arise from using binary encoding. The first is how the problem scales. By using the simplest case where we have two variables for each asset we already double the number of qubits necessary. This greatly limits our testing ability. However, this challenge is faced by any algorithm that needs binary encoding. 5.4 Constraints 43

Figure 5.5: Number of assets mixer structure.

Second, the difficulty associated with modelling constraints. Before we would count the num- ber of assets by multiplying the vector of binary decision variables by a vector of ones. With binary encoding that option is not possible. There are possibilities to achieve this by using auxil- iary qubits, this would, however, scale even more the number of necessary qubits. In this work we did not explore this possibility, given that one of the goals is to reduce the number of necessary qubits to be able to compare both algorithms.

5.4.2 Constraints as mixer operator

As we’ve seen before there are two steps to add a constraint in QAOA+. The inital state, and the mixer operator. Let’s consider the scenario where we have a total of D assets and want to choose a portfolio of N assets. As an initial state we used the following construction:

⊗N ⊗D−N |ψ0i = |1i |0i (5.13)

which is a solution where the first N assets are selected for the portfolio. The ring mixer referred in Equation 5.7 was used. Figure 5.5 illustrates the scenario where we want to select four assets from a set of nine assets. The initial state is a feasible solution, the first four assets are selected. The mixer is represented by the curved lines and applied in the following qubit order:

1. odd parity, orange line

2. even parity, blue line

3. last qubit, green line

With this mixer we don’t have to add the penalty term. Given that we are using p=1, for the mixer to take into account the costs, a first iteration of the mixer operator is executed, as suggested by Hadfield et al.. This additional iteration is needed because we are using an initial state that is not in superposition, if we weren’t, this would result in an useless cost operator as no phases could be added. To avoid this, a possibility would be to start with Dicke States[14], however this was not explored in this work. The circuit depth, when compared to the circuit presented in Figure 5.3 (p. 39), becomes much larger. In this case, we need 44 Implementation

Figure 5.6: Sector allocations mixer structure. to apply the mixer, which is the sub-circuit that is situated after the second barrier, a second time, between the initial state construction and the cost operator. Although not implemented, the sector extension and binary encoding mentioned in Subsec- tion 5.4.1 can be implemented using ring mixers. For sectors, we could even go one step further. Instead of simply favouring certain sectors a sector allocation could be done, which as mentioned before, would not be straightforward to do in the original version. Before running QAOA and using the investor allocation preference, we would calculate how many assets from each sector this allocation corresponds to. Eventually, a classical filtration of the assets could be done to remove any asset that is not included in the allocations, reducing the number of qubits needed. Then, an initial state that matches the allocation preference would be created, similar to how we did in Equation 5.13 and each sector would have an individual mixer that only mixes between assets of the same sector. Figure 5.6 illustrates how that could be accomplished, using the same color code as in Figure 5.5 (p. 43). In this scenario we want to select four assets with the following sector allocation:

1 2 1 ( 4 retail, 4 tech, 4 travel )

For that, three mixers needed to be applied. Only travel has the green line as it is the only group with odd number of assets and thus that needs to apply the last ring mixer operator. For binary encoding, Hadfield et al.also discuss how a mixer can be implemented, however, the complexity is much higher and for that reason we did not explore how we could implement it in our problem.

5.4.3 Penalty terms versus mixer encoding

Both algorithms provide a valid way to enforce constraints. However, as seen by the sector exam- ple, QAOA+ provides a significant advantage when we need to enforce complex constraints, being able to adequately guarantee the specified sector allocation. Another limitation of QAOA is bi- nary encoding, although not explored in this work QAOA+ has the potential to enforce constraints while using binary encoding for different portfolio allocations. For simpler constraints QAOA is the ideal approach, as it follows a straightforward encoding. However, if the constraints exhibit a higher complexity, to enforce them via penalty terms the number of qubits would scale much faster than through the mixer. In this case, QAOA+ is the ideal approach. 5.5 Overview of the solution 45

5.5 Overview of the solution

To illustrate the algorithm we’ll consider an experiment where we want to select from a set of 15 assets the optimal portfolio of 8 assets. The 15 assets used in this experiment, as well as covariance matrix and expected returns are available in AppendixA (p. 65). These were calculated from 1st of January 2017 to 1st January 2020 market data. We’ll analyse two different scenarios, a risky profile, γ = 0.4, and a conservative profile, γ = 0.8. As mentioned before a large value of γ gives more weight (larger penalty) to the risk term, the conservative profile, while a smaller value gives more weight (larger reward) to the returns term, the risky profile. The following four approaches will be compared:

• Mean of all possible feasible states, obtained using a brute-force search

• QAOA

• QAOA+

• Exact solution

We opted for only including feasible states in the brute-force solution as it allows for a better comparison of results. The exact solution is obtained using Numpy’s minimum eigen solver3, which Qiskit already provides an interface for simple usage. In order to have a fair comparison, data from QAOA and QAOA+ is the result of the mean from three consecutive repetitions, this enforces consistency and penalizes the algorithm results for any solution that is not close to optimal.

5.6 Initial analysis

Figure 5.7 (p. 46) plots all the feasible solutions. The horizontal axis is the portfolio variance, how much the portfolio can deviate from what is expected, and the vertical axis the annual returns the portfolio is expected to generate. Black crosses are all the feasible solutions to the problem, which for 15 assets represents 20% of all possible combinations. The yellow line represents the efficient frontier Subsection 2.2.2, where the optimal solutions for different levels of risk are situated. The horizontal black arrows indicate the direction of the portfolio risk classification. Conservative portfolios on the left, where the portfolio variance is lower at the expense of the returns, and risky portfolios on the right, where the expected returns are higher but so is the portfolio risk.

3For more information we refer the reader to Qiskit’s documentation on this solver 46 Implementation

Figure 5.7: Feasible solutions analysis.

From the covariance matrix, present in AppendixA (p. 65) we can roughly separate the assets by how risky they are, as seen in Equality 5.14. The stable assets have a smaller variance. Risky assets have a higher variance. Asset variance is present in the diagonal line of the matrix. Portfolio variance is different than asset variance. The algorithm will not try to minimize the sum of the assets variances. It will however, minimize the variance from the portfolio. This not only takes into account each individual asset variance but also how the portfolio evolves as a whole, for example, a highly concentrated portfolio on the tech sector will be worse than a diversified portfolio over many sectors, as the prior will have sharp swings in portfolio value to the upside and downside while the latter will be more consistent, sacrificing large upside swings while providing protection from large downside swings. This information is present in the non-diagonal elements of the covariance matrix, for example, the pair (NVDA,AAPL), which belongs to the tech sector, have a high correlation at 0.23, meaning that when one goes up or down in value the other follows the same direction.

h i Conservative assets = MSFT,IBM,MMM,VZ,JPM,WFC,WMT,HD h i (5.14) Risky assets = NVDA,CRSP,TWTR,CLPT

The assets with the highest expected returns, present in AppendixA (p. 65), are the following:

h i Highest expected returns = MSFT,AAPL,NVDA,CRSP,TWTR,WMT,HD (5.15)

5.6.1 Conservative profile

Figure 5.8 (p. 47) shows the solution for a conservative profile. The meaning of each triangle, solution for the different algorithms, is illustrated in the top left of the plot. In this case all solvers 5.6 Initial analysis 47

Figure 5.8: Conservative profile solution. found the same solution, in the efficient frontier and in the left side of the plot, as expected. It is not always the case that QAOA and QAOA+ find the optimal solution, but as we’ll see in the data, results were close to the exact solution. A typical solution for this portfolio will choose some combination of assets that achieves a low volatility portfolio while attempting to maximize returns. The solution found was:

h i Conservative solution = MSFT,AAPL,VZ,TWTR,JPM,WFC,WMT,HD

The expected returns of the portfolio were 17.2% and the portfolio risk of 17.7%. Only one of the assets chosen belongs to the risky group flagged above in Equation 5.15, TWTR. Six of the assets belong to the group of assets with lower variance, as seen in Equation 5.14. The results were in-line with expectations.

5.6.2 Risky profile

Figure 5.9 (p. 48) shows the solution for a risky profile. In this case all solvers found the same solution, in the efficient frontier and in the right side of the plot, as expected. A typical solution for this portfolio will choose some combination of the highest expected returns while attempting to minimize the portfolio variance. The solution found was:

h i Risky solution = MSFT,AAPL,VZ,NVDA,TWTR,JPM,WMT,HD

The expected returns of the portfolio were 20.8% and the portfolio risk of 23.3%. Most of the chosen assets are included in the highest expected returns group Equation 5.15. Although CRSP provided the highest expected return from that group, at 33%, it also had one of the highest asset variances at 67%. Additionally, it had a significant correlation with other assets. 48 Implementation

Figure 5.9: Risky profile solution.

This made the algorithm opt for instead of choosing CRSP to take a lower expected return asset, VZ at 4%, as its lower variance at 18% contributed to a risky portfolio but with downside protection. The results were in-line with expectations.

5.6.3 Results

As mentioned above, QAOA and QAOA+ are the result of three executions. The objective is that the algorithms get as close as possible to the results obtained from the exact solution. What ultimately matters is the portfolio cost, which is the results from the cost function that we want to minimize, so a lower cost represents a better solution. However, results for risk of portfolio and expected returns of the portfolio are also presented to have a clear picture of the algorithms performance. For each type of result, both profiles will be present in the same graph, the conservative profile in blue and the risky profile in red. Figure 5.10 (p. 49) illustrates the results for the risk of the portfolio. For the risky profile, the exact solution had a portfolio risk of 23.2%, QAOA+ had a slightly better portfolio risk at 22.1% compared to the QAOA with 26.5%. In the conservative profile, the exact solution had a portfolio risk of 17.7%, a similar result to QAOA and QAOA+, with 19.0% and 17.4% respectively. Given that results represent the mean of three executions, the variation indicates that, as expected, some close to optimal solutions were chosen. Both algorithms had similar portfolio risk to the exact solution, however QAOA+ performed better than QAOA, selecting almost identical portfolio risks as the exact solution. As expected, the average risk from the group of feasible portfolios is higher than the results from the algorithms. Figure 5.11 (p. 49) illustrates the results for the expected returns of the portfolio. For the risky profile, the exact solution portfolio had an expected return of 20.8%, while both QAOA and QAOA+ had similar results, 21.5% and 19.9% respectively. In the conservative profile, 5.6 Initial analysis 49

Figure 5.10: Results for the risk of portfolio. Brute-Force represents the mean of the risk of all feasible solutions.

Figure 5.11: Results for expected returns of the portfolio. Brute-Force represents the mean of the expected returns of all feasible solutions. 50 Implementation

Figure 5.12: Results for cost of portfolio. Brute-Force represents the mean of the cost of all feasible solutions. both QAOA+ and the exact solution had an expected return of 17.2%, while QAOA had 17.8%. In the expected returns the results were also close to the optimal solution, with no clear distinction from the algorithms. As expected, the expected returns from the group of feasible portfolios is lower than the results from the algorithms. Figure 5.12 illustrates the results for the cost of the portfolio. This is where we can see how the algorithms actually performs. The lower the cost the better the solution. For the risky profile the exact solution cost is -3.0, while QAOA is -2.7 and QAOA+ is -2.9. For the conservative profile the exact solution cost is -11.5 while QAOA and QAOA+ had a cost of -10.9 and -11.1 respectively. Both algorithms achieved results close to the optimal solution for both cases, with QAOA+ performing slightly better than QAOA. As expected, the cost from the group of feasible portfolios is much higher than the cost obtained from the algorithms. The results are extremely positive, as QAOA+ achieves closer to optimal solutions when com- pared to QAOA. Chapter 6

Results

6.1 Experimental results ...... 51 6.2 Hypotheses evaluation ...... 58

In this chapter we present the results from the tests performed to validate the hypotheses de- scribed in Section 4.2 (p. 30). Additionally, we evaluate and discuss the aforementioned hypothe- ses.

6.1 Experimental results

As mentioned before, we’ll compare the Portfolio Management problem of choosing a portfolio of N assets using QAOA and QAOA+.

6.1.1 Test environment

To make the experimental tests as isolated as possible, we used a machine that only ran the test script during the entire execution process. It had the following specifications:

• 16 vCPUs

• 32GB of RAM

Each data point is the average of three test repetitions.

6.1.2 Tests settings

For tests where the number of assets varies most of the algorithm settings were maintained, as they don’t have a significant impact on the algorithm performance:

•p=1

• risk profile = 0.8, a conservative profile

51 52 Results

Figure 6.1: Gates execution time.

• penalty = 100, for QAOA

• start date = 2017

• end date = 2020

The only parameter that was changed during the test script was the number of assets to include in the portfolio:

 3 if number of assets < 10 Number of assets to include in portfolio = (6.1) 8 if number of assets >= 10

Assets were selected randomly as long as data was available for the time interval chosen.

6.1.3 Gates

Regarding gate execution time, all of them measured similarly, as seen from Figure 6.1. The SDG gate, which had the largest execution time, is only present in QAOA+. No significant conclusions can be taken from the gate execution time as all gates take similar time to execute.

6.1.4 Algorithm Memory Consumption

Both algorithms consume the same memory as Qiskit allocates equal amount of memory for each possible state, 16 bytes. As expected, and verified in Figure 6.2 (p. 53) by the logarithm scale, memory scales exponentially. With our computational resources, the memory restrictions were not a bottleneck for the solution. 6.1 Experimental results 53

Figure 6.2: Memory consumption.

6.1.5 Circuit depth

Circuit depth is where the non-existence of the parameterized swap gate on Qiskit starts to have a large impact, which is illustrated in Figure 6.3 (p. 54). We observe a circuit depth much larger for the QAOA+ developed, specially for the number of assets that we were able to test with the hardware available, 18 assets. Given that circuit depth is one of the most impactful metrics to algorithm performance, the version of QAOA+ without the parameterized swap gate has a large disadvantage when compared to QAOA. However, in the near future, when the gate is available, we can expect a significant improvement, as the circuit depth gets reduced to almost the same as QAOA, which we can see from the yellow line representing the circuit depth with the gate implemented. The shape of the evolution of QAOA+ comes from the fact that when the number of assets is odd it also has to swap the last and first asset, which cannot be parallelized with the rest of the mixer. From Figure 6.4 (p. 54) we see how much larger the circuit depth from QAOA+ is compared to QAOA. The values represent in percentages, QAOA+’s circuit depth divided by QAOA’s circuit depth. Given that the mixer has a fixed circuit depth size, in the beginning is where the difference is more noticeable. However, the circuit depth converges to the 200% range, representing two times QAOA’s circuit depth.

6.1.6 Number of gates

The impact from the number of gates is not as large as the circuit depth’s, as gates can be par- allelized. However, as expected, the number of gates is much larger, scaling exponentially for QAOA+, as seen in Figure 6.5 (p. 55). 54 Results

Figure 6.3: Circuit depth comparison.

Figure 6.4: QAOA+ vs QAOA circuit depth. 6.1 Experimental results 55

Figure 6.5: Number of gates comparison.

A similar result to the circuit depth comparison is seen in Figure 6.6 (p. 56). The number of gates is also much larger in the beginning, converging to around 300%, or three times QAOA’s number of gates. For quantum simulators the number of gates starts affecting performance when it can’t, due to hardware limitations, parallellize the amount of qubits that could theoretically be executed in parallel. However, given that our hardware could only achieve 20 assets this bottleneck was not explored.

6.1.7 Algorithm execution time

The results for the algorithm execution time, which encodes the outer loop of classical optimiza- tion, are illustrated in Figure 6.7 (p. 56). The expectations were that even if it QAOA+ had a speedup it would not make up from the difference in circuit depth exhibited in Figure 6.3 (p. 54), when compared to QAOA. However, this version of QAOA+ still showed impressive results, consistently performing better than QAOA. At certain number of assets achieving even more than 2x speedup, with an average of 1.6x speedup. This confirms our assumptions that QAOA+ can bring significant speedup to current quantum simulators by encoding constraints into the mixer, reducing the search space, and a future imple- mentation of the parameterized swap gate will yield even better results. 56 Results

Figure 6.6: QAOA+ vs QAOA number of gates.

Figure 6.7: Algorithm execution time. 6.1 Experimental results 57

Figure 6.8: Quantum part execution time.

6.1.8 Quantum part execution time

In order to isolate the quantum part of both algorithms, which is the part we are effectively com- paring, an analysis of a single iteration is showed in Figure 6.8. This eliminates any impact that the outer classical loop could have, and allows for an analysis of the quantum algorithm in isolation. The results are equally impressive, with more consistency than the results obtained for the execution time of the full algorithm, as seen in Subsection 6.1.7. This difference comes from the variation in the number of classical optimizations. Additionally, the average speedup was similar at 1.7x.

6.1.9 Number of classical iterations

The expectation was that QAOA+ would allow for a faster convergence of the algorithm to the solution. This would reflect in the number of QAOA’s classical loop iterations. Figure 6.9 (p. 58) illustrates the results obtained. The results were not as expected. The number of classical iterations for both algorithms re- mains the same for most of the number of assets tested. For a number of assets larger than twelve, we see that QAOA+ performs consistently better, but only one or two less iterations. This repre- sents a speedup in the number of iterations of only 3%. There are possible arguments that could justify why this implementation does not achieve a larger speedup on classical iterations. One possible argument is the that the number of feasible states is still a significant percentage of the total number of states. This can be seen in Figure 6.10 (p. 59). The change in the graph for 8 possible assets is due to the problem settings described in Equation 6.1, where the number of assets to include in the portfolio goes from 3 to 8. 58 Results

Figure 6.9: Number of classical optimization iterations.

The percentage is extremely small for 8 assets, however, the total number of states is only 256 and there is only 1 feasible state. Where we speculate QAOA+ can start to significantly converge faster than QAOA is when the number of possible states is extremely large and the percentage of feasible states small. For 40 possible assets, a more realistic scenario for Portfolio Management, the total number of possible states is already one trillion and the percentage of feasible states 0.007%. For higher numbers of possible assets, which we were not able to test, the advantage of using QAOA+ could potentially be achieved. Another argument is the impact that the classical optimizer can have over the algorithms, given that this work used the default Qiskit optimizer, SLSQP, exploring different optimizers and their settings could yield better results. Ultimately, this work could not achieve a significant speedup in the number of classical itera- tions, and more research over the arguments enumerated is warranted.

6.2 Hypotheses evaluation

We believe the results obtained prove that the initial hypotheses was correct. Portfolio Manage- ment can be solved using gate-based quantum computers and several extensions to the problem can be tackled using QAOA and QAOA+. The theoretical approach for some of these extensions was also discussed for both algorithms. QAOA+ also provided significant advantages when com- pared to QAOA. One such advantage is the adaptability of QAOA+ to enforce complex constraints, as seen from the encodings discussion, which is a clear advantage for this algorithm. Another is the quantum simulator execution, even though the implementation of QAOA+ on Qiskit is held back by not having the parameterized swap gate, QAOA+ still provided a significant speedup of 6.2 Hypotheses evaluation 59

Figure 6.10: Percentage of feasible states in the set of possible states.

1.6x, and a larger speedup is expected when the gate is implemented. This will allow high-level algorithm development to explore larger problem sizes. Finally, our results from the classical loop iterations proved to be marginally successful. Although a faster convergence should be expected, the classical optimizer behaved similarly for both algorithms. Some arguments were enumerated to speculate over why better results in this category were not obtained, and further research is needed to possibly achieve the full potential of QAOA+. 60 Results Chapter 7

Conclusions

7.1 Difficulties ...... 61 7.2 Future Work ...... 61 7.3 Contributions ...... 62 7.4 Conclusion ...... 62

7.1 Difficulties

Several obstacles made the research on this work more challenging than what was expected. First, the fact that Quantum Computing, and more specifically Quantum Finance, are still in early stages of research. The literature is scarce, learning resources are limited, and similar work is hard to find. Given that Quantum Finance is recent, it is still a broad area of research, which made the task of finding the problem within it to tackle in this work more challenging. Second, Qiskit not containing yet the parameterized swap gate made the analysis of QAOA+ more difficult. Finally, Quantum Finance being the intersection of two large topics makes the pre-requisites needed to work on this field exceptionally large.

7.2 Future Work

Many opportunities for future work were found during the thesis:

• Find the most adequate classical optimizer for a Portfolio Management problem and under- stand its influence in the algorithm performance;

• Asses the impact of the classical optimizer on the number of classical loop iterations referred in Chapter6 (p. 51);

61 62 Conclusions

• Explore how to integrate multiple mixers is of special interest, as Finance problems regularly deal with many constraints;

• Examine how to use binary encoding with QAOA+, as it allows for different asset alloca- tions, essential for building an efficient portfolio;

• Research how to use entanglement to enforce common Portfolio Management constraints and the benefits for quantum simulators;

• Implement and asses the benefits of initializing QAOA+ with Dicke states;

• Find areas where the QAOA and QAOA+ encodings used for Portfolio Management can be used for other applications. Finally, it might be possible to implement the parameterized swap gate directly on Qiskit using Qiskit-Pulse1, a pulse-level quantum programming kit that allows for the addition of gates directly from the pulse that the quantum computer sends to the qubits. Which is described in [1].

7.3 Contributions

This work made several contributions to research:

• Literature review of Quantum Finance, more specifically Portfolio Management: An analysis was made of the current state of Quantum Finance, analysing research on Portfolio Management for different technologies.

• Analysis of QAOA+: Given that QAOA+ is still fairly recent, research is still scarce, and implementation details were not found. In this work we exhibited how can we implement such algorithm for our topic. Additionally, we explored in what scenarios it is adequate to use QAOA+. This will enable faster bootstrapping of future research in this topic.

• Comparison between QAOA and QAOA+ in the context of Portfolio Management: The largest contribution was definitely the comparison between these two algorithms, which was not found prior to this work.

• Possible research: Several possible related research topics were proposed. This comple- ments the review of the state of the art with what are the next steps in research.

7.4 Conclusion

As the world gets closer to building quantum computers, industries are assessing how will they be impacted by this breakthrough innovation. Although there is no present value added from re- searching quantum, when error-corrected quantum computers become a reality, players that are

1For more information we refer the reader to the official Qiskit-Pulse docs page 7.4 Conclusion 63 able to capitalize on this disruptive innovation will be certainly rewarded when compared to their peers. Finance in specific, is expected to be greatly impacted, as so much of the industry runs with algorithms as their backbone. Not only that, but it is one of the largest industries in the world. Quantum Finance is a field of research that is growing rapidly, exploring where quantum can bring a speedup to existing processes or solve problems that we couldn’t solve until now using classical computers. The goal of this work was to assess the feasibility of solving a Portfolio Management problem using gate-based quantum computers algorithms, more specifically QAOA and its new version QAOA+, while also exploring if QAOA+ could bring advantages over the original ver- sion. We started by reviewing literature on Quantum Finance, the QAOA algorithm, and Portfolio Management using quantum annealing and gate-based quantum computers. An implementation of QAOA+ was done in Qiskit and a Portfolio Management problem was explored for both QAOA and QAOA+. The results confirmed that we can indeed solve the Portfolio Management prob- lem using gate-based quantum computers, and that QAOA+ brings significant advantages when compared to QAOA. However, several opportunities for future work were mentioned through the dissertation that could help achieve even more advantages of QAOA+ In our view, this work is a great base point for further research on Portfolio Management using gate-based quantum comput- ers. 64 Conclusions Appendix A

Solution Example Data

MSFT   AAPL     IBM     MMM     VZ     CCL    NVDA      CRSP  (A.1)   TWTR    GM     CLPT     JPM     WFC     WMT  HD

A.1: Solution example assets

65 66 Solution Example Data HD WMT WFC JPM CLPT GM TWTR CRSP NVDA CCL VZ MMM IBM AAPL MSFT Cov 0.13 0.10 0.13 0.14 0.10 0.13 0.20 0.21 0.22 0.14 0.08 0.14 0.14 0.18 0.21 MSFT 0.13 0.10 0.13 0.14 0.08 0.14 0.20 0.21 0.23 0.15 0.05 0.15 0.14 0.24 0.18 AAPL 0.12 0.10 0.12 0.13 0.09 0.14 0.13 0.16 0.17 0.12 0.09 0.13 0.20 0.14 0.14 IBM 0.13 0.10 0.13 0.14 0.11 0.14 0.15 0.17 0.19 0.13 0.09 0.21 0.13 0.15 0.14 MMM al .:Cvrac arxfrslto example solution for matrix Covariance A.1: Table 0.08 0.09 0.08 0.08 0.07 0.08 0.01 0.05 0.05 0.06 0.18 0.09 0.09 0.05 0.08 VZ 0.11 0.08 0.12 0.13 0.09 0.14 0.15 0.16 0.18 0.24 0.06 0.13 0.12 0.15 0.14 CCL 0.17 0.13 0.16 0.18 0.06 0.19 0.26 0.27 0.43 0.18 0.05 0.19 0.17 0.23 0.22 NVDA 0.14 0.11 0.16 0.16 0.19 0.19 0.27 0.67 0.27 0.16 0.05 0.17 0.16 0.21 0.21 CRSP 0.13 0.11 0.12 0.13 0.15 0.16 0.48 0.27 0.26 0.15 0.01 0.15 0.13 0.20 0.20 TWTR 0.13 0.09 0.14 0.15 0.09 0.26 0.16 0.19 0.19 0.14 0.08 0.14 0.14 0.14 0.13 GM 0.10 0.01 0.13 0.11 0.85 0.09 0.15 0.19 0.06 0.09 0.07 0.11 0.09 0.08 0.10 CLPT 0.12 0.09 0.17 0.19 0.11 0.15 0.13 0.16 0.18 0.13 0.08 0.14 0.13 0.14 0.14 JPM 0.11 0.09 0.20 0.17 0.13 0.14 0.12 0.16 0.16 0.12 0.08 0.13 0.12 0.13 0.13 WFC 0.11 0.19 0.09 0.09 0.01 0.09 0.11 0.11 0.13 0.08 0.09 0.10 0.10 0.10 0.10 WMT 0.18 0.11 0.11 0.12 0.10 0.13 0.13 0.14 0.17 0.11 0.08 0.13 0.12 0.13 0.13 HD Solution Example Data 67

MSFT  0.3093  AAPL  0.3104    IBM −0.073   MMM −0.003   VZ  0.0394    CCL −0.008   NVDA    0.2797    CRSP  0.3332  (A.2)   TWTR 0.2234    GM  0.0135    CLPT  0.1154    JPM  0.1568    WFC −0.013   WMT  0.1835  HD 0.1626

A.2: Expected returns for solution example 68 Solution Example Data Appendix B

Qiskit gates

In this appendix we describe the gates used throughout the work with their corresponding Qiskit figure.

Figure B.1: X gate. Rotation over the X axis by angle π.

Figure B.2: Hadamard gate. Change of basis {|0i,|1i} to {|−i,|+i}.

Figure B.3: RX gate. Rotation over the X axis by angle θ.

69 70 Qiskit gates

Figure B.4: RZ gate. Rotation over the Z axis by angle θ.

π Figure B.5: S gate. Induces a 2 phase.

π Figure B.6: SDG gate. Induces a − 2 phase.

Figure B.7: SWAP gate. Swaps amplitudes between two qubits.

Figure B.8: CNOT gate. Applies X gate to target qubit (0) if target qubit (1) collapses to state 1. References

[1] Deanna M Abrams, Nicolas Didier, Blake R Johnson, Marcus P. da Silva, and Colm A Ryan. Implementation of the XY interaction family with calibration of a single pulse. arXiv:1912.04424, 2019.

[2] Gadi Aleksandrowicz et al. Qiskit: An Open-source Framework for Quantum Computing, 2019.

[3] Koen Bertels, A. Sarkar, T. Hubregtsen, M. Serrao, A. A. Mouedenne, A. Yadav, A. Krol, and I. Ashraf. Quantum Computer Architecture: Towards Full-Stack Quantum Accelerators. 2020 Design, Automation and Test in Europe Conference and Exhibition, 2020.

[4] Koen Bertels, Aritra Sarkar, and Imran Ashraf. Quantum Computing – from NISQ to PISQ. arXiv:2106.11840, 2021.

[5] Emmanuel Desurvire. Classical and Quantum Information Theory: An Introduction for the Telecom Scientist, volume 9780521881. Cambridge University Press, 2009.

[6] Deutche Bank. Research Briefing Global financial markets, 2016.

[7] Daniel J. Egger, Claudio Gambella, Jakub Marecek, Scott McFaddin, Martin Mevissen, Rudy Raymond, Andrea Simonetto, Stefan Woerner, and Elena Yndurain. Quantum computing for Finance: state of the art and future prospects. arXiv:2006.14510, 2020.

[8] Edward Farhi, Jeffrey Goldstone, and Sam Gutmann. A Quantum Approximate Optimization Algorithm. arXiv:1411.4028, 2014.

[9] Stuart Hadfield, Zhihui Wang, Bryan O’gorman, Eleanor G Rieffel, Davide Venturelli, and Rupak Biswas. From the Quantum Approximate Optimization Algorithm to a Quantum Alternating Operator Ansatz. arXiv:1709.03489, 2019.

[10] Mark Hodson, Brendan Ruck, Hugh Ong, David Garvin, and Stefan Dulman. Portfolio re- balancing experiments using the Quantum Alternating Operator Ansatz. arXiv:1911.05296, 2019.

[11] IBM. IBM’s Roadmap For Scaling Quantum Technology, 2020.

[12] Harry Markowitz. Portfolio Selection. The Journal of Finance, 7(1):77, 1952.

[13] Samuel Mugel, Mario Abad, Miguel Bermejo, Javier Sanchez, Enrique Lizaso, and Ro- man Orus. Hybrid Quantum Investment Optimization with Minimal Holding Period. arXiv:2012.01091, 2020.

71 72 REFERENCES

[14] Chandra Sekhar Mukherjee, Subhamoy Maitra, Vineet Gaurav, and Dibyendu Roy. Preparing Dicke States on a Quantum Computer. IEEE Transactions on Quantum Engineering, 1:1–17, 2021.

[15] David Orrell. and Finance: An Applied Mathematics Introduction. Panda Ohana, 2020.

[16] Román Orús, Samuel Mugel, and Enrique Lizaso. Quantum computing for finance: Overview and prospects. arXiv:1807.03890, 2019.

[17] John Preskill. Quantum Computing in the NISQ era and beyond. arXiv:1801.00862, 2018.

[18] Gili Rosenberg, Poya Haghnegahdar, Phil Goddard, Peter Carr, Kesheng Wu, and Mar- cos López De Prado. Solving the Optimal Trading Trajectory Problem Using a Quantum Annealer. IEEE Journal on Selected Topics in Signal Processing, 10(6):1053–1060, 2016.

[19] Martin Schaden. Quantum finance. Physica A: Statistical Mechanics and its Applications, 316(1-4):511–538, 2002.

[20] Ehsan Zahedinejad and Arman Zaribafiyan. Combinatorial Optimization on Gate Model Quantum Computers: A Survey. arXiv:1708.05294, 2017.