\(\def\ket#1{\mid #1 \rangle}\)

Quantum Algorithm for Calculating Financial Portfolio

A lot of problems in financial field need far more computational power than current computers. This is because the situations of the market are too many and changed rapidly. Such situations make some kinds of combinatorial problems which need a lot of computation power and usually solved approximately.

The quantum computer can do a role in this circumstance. One of the main advantages of the quantum computing is in that it can solve the combinatorial problem efficiently. By using superposition states of qubit, the quantum computer evaluate multiple cases simultaneously.

Let’s see the detailed procedure of how the quantum computer can calculate distributions of financial value efficiently.

1. Problems in Finance

In the finance, it is important to estimate future movement of portfolio value. Portfolio means combination of financial assets such as stocks, bonds and cash.

Each asset has different property. For example, when the situation goes well, option can make huge profits but when it goes bad, option makes catastrophic loss. On the other hand, the value of bank deposit doesn’t change compared to option or stock.

Therefore, it is important to set appropriate balance between risk and profit. Portfolio is best strategy to handle this problem. For example, by investing half of money on the asset with high risk and high return and investing another half on the asset with row risk and row return, we can control between risk and return.

figure1

Therefore, the value of the portfolio is affected by multiple events which affect on the components of the portfolio. To supervise such complicated structures, people usually approach them with statistical methods.

By assuming each event as random variable and combining them into one, we can handle the total values of the portfolio.

For random variable \(L_{i},i=1,2,...,m\), we can define total values random variable \(L = \sum_{i=1}^m L_i\). Each \(L_i\) represent the presumed movement of single assets. For example, if we assume the probability that some event A occur as \(\theta\) and the expected profit when the event occur as \(\lambda\), then we can set the random variable connected with the event as \(L_1 = \lambda X_1\), \(X_i \sim Bernoulli(\theta)\). We can set more complicated situation by using various distribution such as Normal Distribution or gamma distribution.

figure2

The main obstacle which makes the problems harder is in that each event is correlated with each other ;or, quantum-theoretically speaking, entangled with each other. Therefore, we can not calculate the total distribution of \(L\) by just simply stacking each distribution.

We can understand above situation with an example. Assume that a portfolio consists two events \(L_1 \sim Bernoulli(\theta_1)\) and \(L_2 \sim Bernoulli(\theta_2)\). If the two events are irrelevant with each other(i.e. independent), than we can calculate distribution of total value \(L = L_1+L_2\) with the theorem of \(Pr(L_1,L_2)=Pr(L_1)Pr(L_2)\).


\[Pr(L=2)= Pr(L_1=1,L_2=1) = Pr(L_1=1)Pr(L_1=1) = \theta_1 \theta_2\] \[Pr(L=1) = Pr(L_1=1,L_2=0 \mbox{ or }L_1=0,L_2=1) =Pr(L_1=1)Pr(L_2=0)+Pr(L_1=0)Pr(L_2=1)\]

​ \(= \theta_1(1-\theta_2) + (1-\theta_1)\theta_2\)

\[Pr(L=0) = Pr(L_1=0 , L_2 = 0) = (1-\theta_1)(1-\theta_2)\]

However, if the two events are connected with each other, for example, \(L_1\) is event of sunny day and \(L_2\) is event of rainy day, then we can calculate the total distribution as follow with the fact that \(L_2 = 1-L_1\).


\[Pr(L=2) = Pr(L_1=1,L_2=1) =0\] \[Pr(L=1) = Pr(L_1=1,L_2=0 \mbox{ or }L_1=0,L_2=1) = \theta_1 + (1-\theta_1) =1\] \[Pr(L=0) = Pr(L_1=0,L_2=0) =0\]

We can think above situation with quantum sense as below.

\[\ket{L} = \ket{L_1 L_2} = a \ket{00}+b\ket{01}+c\ket{10}+d\ket{11}\]

By setting the amplitude of every cases, we can design joint distribution of multiple random variables. Therefore, we can say that the quantum computer can deal with multiple random variable problems in the stage of fundamental unit.

2. Issues of the financial data science

We can summarize that main interests of finance about above structures are as follow

A. Expecting future values of specific portfolio

B. Calculating Value At Risk

C. Optimizing best portfolio combination

A. Expecting future values of specific portfolio

First of all, we can trace and visualize the distribution of values of some portfolio with above structure. With them, we can monitor the profits and loss of the company or sell some financial products to customer. The important thing is that we can not only estimate an single expectation point but also see the uncertainty and possibility of values.

figure3

The above three cases have a same expectation point \(\mu\). We can see that the first case is mild one so we can expect that future value is made around mean values. However, if we see the second case, then the probability that the future value is made around the mean is much lower than two peaks. The final case means that even though the mean is higher than the mode of the distribution, it is because of the potential that the portfolio could make huge profits.

Therefore, we cannot see the detail characteristics of the portfolio with just one point. By monitoring whole trend of the portfolio we can do the better decision and precise prediction.

figure4

B. Calculating Value At Risk

We can say that the hottest issue dominating the financial field is Basel 3. The Basel 3 means regulations to control global financial market risk and prevent catastrophic market event.

A single crisis on a few company can affect the whole financial market due to the complicatedly entangled relation among the companies. When the 2008 global financial crisis occurred, the global market leader shared common opinion that they have to handle the risk more strictly and systematically. Therefore, they have made several regulations such as Basel 1 and Basel 2. Now, the new regulation Basel 3 has been negotiated to apply on all of the financial company of the world until 2023.

The main tools of controlling such crisis is Value at Risk (VaR). Value at Risk literally means the value of a company when the crisis occurs. It is calculated by 5 percentile of the total values of the company assets. All of the company affected by Basel 3 must satisfy capital adequacy ratio with their VaR. \(VaR(L) = -inf\{\gamma \mbox{ such that } Pr(L \leq \gamma) \geq \alpha \}\)

Among three issues mentioned above, researchers mainly focus on developing algorithms for calculating the VaR.

C. Optimizing best portfolio combination

The above two issues target to handle their current portfolio and risk and do not directly increase the profits of the company. However, the third issue is directly connected with the profits. The most important thing of the portfolio is to decide the best ratio of each assets which maximize the profits.

Therefore, we can develop the total value of portfolio as \(L = p_1 L_1 +p_2 L_2 + ... +p_m L_m\). We can consider \(L_i\) as uncontrollable part and \(p_i\) as controllable part. Therefore, by calibrating the ratio \(p_i\), we can control the risk and profit of the portfolio.

However, deciding such value is not easy one. If the numbers of events and complexity of entanglement among events increase, the problem cannot be solved by ordinary optimizing algorithm such as Gradient Descent or Newton’s Method. It almost become combinatorial optimization problem because the problem become containing variable selection problems too.

One of the potentials of the quantum computer is that it can solve optimization problems really well. For example, QAOA, VQE and QNN could be used to maximize the profits of the portfolio. By evaluating all of the cases in once, the algorithm can solve the combinatorial problem a lot efficiently.

Therefore, it will become one of the most prosperous fields using the quantum computer.

3. Algorithm for calculating the values of portfolio

All of the methods target to estimate distribution function \(F(x) =Pr(L \leq x)\). In the statistics,symbol \(\hat{\cdot}\) is used to denote estimator of \(\cdot\). Therefore, defining \(\hat{F}(x)\) means defining method to estimate the target distribution \(F\)

A. Historical Simulation

In most basic sense, the distribution of portfolio could be calculated using past data. For example, 10 day VaR which means the 5-percent worst possible loss during 10 days could be calculated by 5-th percentile of past cases.

For example, we can calculate 10 day VaR as follow.

day 1 2 3 4 248 249 250      
value $132 $146 $143 $139   $170 $165 $149      
amount of changes - +14 -2 -4   +2 -5 -16      

Then we can expect the 10 day VaR as 0.05*250 = 12th least value of amount of changes. This is very simple and easy way to calculate the VaR. And we could see them as estimating the distribution with Empirical Distribution Function. \(\hat{F}(x) = \hat{Pr}(X\leq x) = \frac{1}{n}\sum_{i=1}^n I(X_i \leq x)\)

B. Delta-Normal Methods

This method is a statistical methods. First of all, it assume that total portfolio value \(L\) follows normal distribution i.e. \(L \sim N(\mu, \sigma^2)\). Secondly, estimate the parameters \(\mu\) and \(\sigma^2\) as \(\hat{\mu}=\frac{1}{n}\sum_{i=1}^n x_i,\hat{\sigma}^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \hat{\mu})^2\). Then we can estimate the distribution \(f(x)\) as below. \(\hat{f}(x) = f(x;\hat{\mu},\hat{\sigma}^2) = \frac{1}{\sqrt{2 \pi \hat{\sigma}^2}} \exp\left(-\frac{1}{2\hat{\sigma}^2} ( x-\hat{\mu})^2 \right) \\ \hat{F}(x) = \int_{-\infty}^{x} \hat{f}(t) d t\)

However, above methods don’t consider the complicated structure at all. Its algorithm is too simple to catch the future of the portfolio exactly. Therefore, we can use a montecarlo method on a lot sophisticated mixture model to calculate the VaR.

The problem is the usual montecarlo methods need a lot of computational power. And the quantum computer can solve this problem.

C. Quantum Algorithm

The quantum algorithm could be the best methods to catch exact trend of the data. It is introduced at D. Egger et al(2021) Credit Risk Analysis Using Quantum Computers and D. Egger et al(2020) Quantum Computing for Finance: State-of-the-Art and Future Prospects.

The paper suggest circuit to calculate the portfolio.

figure5

Loading Step

The algorithm is divided into three process. The first process, Gate U, is loading step. It encodes the random variables \(L_i\) of the portfolio \(L\) into X-register qubits. Z-register is used to design correlations between X. For a single Bernoulli random variable \(X \sim Bernoulli(\theta)\), we can implement it using rotation-Y gate.

\[R_y(\alpha) \ket{0} = \cos(\alpha)\ket{0} + \sin(\alpha) \ket{1}\]

If we set the \(\alpha\) as \(\mbox{arc} \sin (\theta)\), then we can get \(\ket{X} = R_y (\mbox{arc} \sin (\theta)) \ket{0} = (1-\theta)\ket{0}+\theta \ket{0}\).

By entangling them, we can design m numbers of the Bernoulli random variables \(X_i \sim Bernoulli(\theta_i)\) as follow. \(\ket{X_1} \otimes \ket{X_2}\otimes ...\otimes \ket{X_m} = ((1-\theta_1) \ket{0}+\theta_1 \ket{1})\otimes ((1-\theta_2) \ket{0}+\theta_2 \ket{1})\otimes ...\otimes ((1-\theta_m) \ket{0}+\theta_m \ket{1})\)

We can develop above algorithm to design more general random variable. For example, we can design any discrete random variable \(X_i \sim \sum_{i=1}^j \sqrt{p_j} \ket{j}\). We can also design multivariate version of it as \(\ket{X_1} \otimes \ket{X_2}\otimes ... \otimes \ket{X_m}\). With the Z register, we can design joint probability too.

Any way, we can write the result as follow. \(U\ket{0} = \ket{X_1,X_2,...,X_m}\)

Computing Step

In the computing step, the gate integrate the random variables into one. That is, the result is as follow. \(S(\ket{X_1,X_2,...X_m}\ket{0}) = \ket{X_1,X_2,...X_m}\ket{\lambda_1 X_1 + \lambda_2 X_2 + ...+ \lambda_m X_m}\) \(\lambda_i\) is the value making the random variable into real profits or loss. Therefore, we can assume \(L_i = \lambda_i X_i\) and \(L = \sum_{i=1}^m L_i =\lambda_1 X_1 + \lambda_2 X_2 + ... +\lambda_m X_m\)

The real implementation of them is little bit tricky so I’ll omit it.

\[\def\bra#1{\langle #1 \mid}\]

Measuring Step

In the final step, the result of the gate C could be written as follow. \(C (\ket{i}\ket{0}) = \begin{cases}\ket{i}\ket{1} \mbox{ if }i\leq x \\ \ket{i}\ket{0} \mbox{ otherwise}\end{cases}\) The value \(x\) is predetermined one. So the gate C is actually parameterized gate \(C(x)\) We can understand the result as a estimator of probability such as \(\hat{F}(x) = \frac{1}{n} \sum_{i=1}^n I(L \leq x)\)

Therefore, we can summarize the circuit with the gate \(A(x) = USC(x)\) as \(A(x)\ket{0} = USC(x) \ket{0}\). Then the expectation of the circuit is itself the estimator of cumulative distribution function i.e. \(\hat{F}(x) = \bra{0}A^{\dagger}(x) MA(x)\ket{0}\).


Reference

  • D. Egger et al(2021) Credit Risk Analysis Using Quantum Computers
  • Montanaro A. (2015) Quantu speedup of Monte Carlo Methods
  • D. Egger et al(2020) Quantum Computing for Finance: State-of-the-Art and Future Prospects