Application of Quantum Computing To An Investment Portfolio.

Blessing Magabane
8 min readSep 30, 2020

Welcome to the quantum era, are you ready?

Source : https://www.theguardian.com/commentisfree/2019/sep/28/google-quantum-computer-internet-security-threat

Authors : Blessing Magabane and Seturumane Tema.

Classical vs Modern approaches.

In the quantum realm matter behaviours differently, for example in classical mechanics the universe is deterministic. Given the initial position of a moving particle at some initial time, I can tell you where that particle will be in future. Newtonian mechanics can be used to describe the position and motion of the particle. For instance if I know the mass of the particle and the associated acceleration I can calculate the force and other properties of the particle with ease. The mathematical construct to classical mechanics have determinism embedded in it.

However, in the quantum world the same particle that we could determine with certainty in classical terms. No longer follows the same rules, the particle is now probabilistic. The particle behaves like a wave. This wave is described by the Schrodinger wave equation. This wave has similar properties to a normal wave such as the superposition principle. The principle of superposition stems from the fact that if you have two solutions to Schrodinger’s equation, their sum is also a solution. One of the most famous illustrations of the superposition principle is the thought experiment known as Schrodinger’s cat. If you have a cat in a closed box containing a radioactive source, Schrodinger asked; is the cat alive or dead? The answer to that question, also proposed by Schrodinger, is that the cat is alive and dead at the same time. It’s in a superposition of both states, until you open the box and find that it is in either state.

Now that we have looked at the difference between classical and quantum mechanics, we will look at classical computers which are Turing machines. A Turing machine is nothing but an infinitely long memory tape divided into cells of 1's and 0's known as bits and is equipped with a memory reader. The reader is not limited to that, it can also be instructed to change a 1 bit to a 0 bit and even change either a 1 or 0 bit to an unmarked bit known as the halt state of the machine.

Quantum computers on the other hand use superposition and quantum entanglement. To explain entanglement, the Nobel prize winning physicist Frank Wilczek gave the following example: consider a system of two objects, he called the objects c-ons. The c-ons can come in two shapes, they could either be a square or a circle — which he described as being their possible states. For both c-ons there is a set of four possible joint states, namely: (square,square), (square,circle), (circle,square) and (circle,circle). If the knowledge about one state does not give us useful information about the other state, we say that the two states are independent. If the information we know about one state tells us something about the other state then the two states are entangled.

In this article the objective is to optimise an investment portfolio using quantum mechanics approaches. A quantum computer and classical one will be used, the results from both will be compared.

Background :

Let’s say you are an analyst at an asset management company and you are managing an investment portfolio. You are instructed to maximize the return on investment. The best approach would be to pick the best performing shares and invest in those. But if you really want to get value for your money you will need to go a step further and optimise how you allocate those investments on each share. In investment 101 there is a phrase that states; don’t put all your eggs in one bucket. For that reason you will need to invest in a portfolio that holds an ensemble of shares such an instrument is the Exchange Traded Fund also known as ETF.

The article focuses on the SATRIX DIVI ETF, particularly the Top 7 shares. Those shares are Kumba Ore, MTN Group, Vodacom Group, BHP Group PLC, Multichoice Group, British American Tobacco and AngloAmerican. To query the trading data yahoo finance was used. To learn more on how to query financial data you can read more from my previous articles on the following link,

The optimisation problem will be presented as a mean-variance portfolio optimisation problem. The parameters of the mean-variance optimisation problem are as follows a vector of binary decisions it indicates which assets to pick and which not to, the expected return for the assets ,the covariance between assets, the risk appetite of the decision maker, the budget and number of assets to be selected.

The IBM quantum computer was used to solve our optimisation problem. For that reason the article closely follows the work that was done initially by IBM and mirrors a similar tutorial. The IBM platform is known as the IBM Quantum Experience and can be accessed by the following link,

Data Preparation :

In this section we get the data into a format that is useful to work with. The algorithms that are going to be utilised make use of arrays. The mean-variance portfolio optimisation problem makes use of a number of parameters.

We calculate the mean of each of the share as shown below,

Define an array to hold the mean values of each share,

The optimisation of the portfolio is solely based on the closing price of each share, hence the focus is on the closing price. The next step is to group all the shares into a data frame. The screen-print shows that process,

Once the closing price information is grouped together, the next step is calculating the covariance matrix,

The covariance matrix is a data frame, it is converted into an array with dimensions, 6 rows and 6 columns. The screen print below shows the conversion process,

A plot of the covariance matrix is shown below,

Figure 1 : Covariance matrix.

Modeling:

In this modeling section, algorithms from the IBM Quantum Experience tutorial are used. The outputs to that to optimisation problem are qubitOp and Offset. The mean variance portfolio equation definition is shown below,

Quantum approaches on a classical computer:

In this subsection a conventional computer is used to optimise a portfolio, the classical computer is an Apple Macbook air.

Before we deploy the quantum mechanics algorithms to optimise the portfolio, a classical optimisation algorithm is used as a baseline for the quantum algorithms,

The next algorithm that is used is the Variational Quantum Eigensolver (VQE),it is purely quantum in nature,

The algorithm uses 500 iterative to arrive at the final result and used random seeds to search for the optimal solution. The VQE is a quantum algorithm the entanglement parameter is used fully.

The next quantum algorithm is the Quantum Approximate Optimization Algorithm (QAOA), it a hybrid between quantum mechanics and classical optimisation,

Similarly to VQE the algorithm makes use of iterations to solve the problem. However in this case only 250 iterative are used. Since the algorithm is not fully quantum the is no entanglement.

Quantum approaches on a quantum computer:

An actual quantum computer is going to be used to optimise the portfolio. The IBM Quantum Experience is a computing platform built on a quantum architecture. Algorithms that are used in the classical computer are also going to be used on the quantum computer to compare the results. However the baseline algorithm will be omitted,

The first algorithm is the the Variational Quantum Eigensolver (VQE), it is purely quantum in nature,

The second algorithm is the Quantum Approximate Optimization Algorithm (QAOA), it a hybrid between quantum mechanics and classical optimisation,

The above code was used on a quantum computer, the code is exactly the same as the one used on a classical computer.

Results :

The baseline algorithm was used on both the classical and quantum computer the solution produced is similar.

Classical Computer — NumPyMinimumEigensolver result.
Quantum Computer — NumPyMinimumEigensolver result.

This was expected, running such a model ensures that the quantum computer is calibrated correctly and also serves a benchmark for the quantum algorithms.

The optimal solution for Variatonal Quantum Eigensolver (VQE) on the quantum computer has the same selection as the baseline algorithm but a different probability.

Quantum Computer — Variational Quantum Eigensolver results.

However on the classical computer the for same algorithm VQE, the selection is entirely different,

Classical computer — Variational Quantum Eigensolver results.

On the other hand the Quantum Approximate Optimisation Algorithm (QAOA) on the quantum computer, produced an optimal selection similar to the VQE selection on the classical computer.

Quantum Computer — Quantum Approximate Optimization Algorithm results.

The same algorithm QAOA on the classical computer produces completely different solution with the values parameter having a positive value.

Classical Computer — Quantum Approximate Optimization Algorithm results.

The selection vector which has zeros and ones tell us which share you should pick and which ones not to pick.

Conclusion :

The performance on the classical computer and the quantum computer are more less the same in this instance. The data is fairly small; further study is required to arrive at a conclusive argument which shows that the quantum computers perform better than classical computers or vice versa. At the moment what we have demonstrated that both approaches work.

The code used in article can be assessed through the following link,

You can follow and contact me on the following platforms,

Twitter :@blessing3ke

LinkedIn : https://www.linkedin.com/in/blessing-magabane

--

--

Blessing Magabane

A full stack Data Scientist with experience in data engineering and business intelligence.