Articulo 2
Articulo 2
Samuel Mugel,1 Carlos Kuchkovsky ,2 Escolástico Sánchez,2 Samuel Fernández-Lorenzo,2 Jorge Luis-Hita,2
Enrique Lizaso,3 and Román Orús 3,4,5
1
Multiverse Computing, Banting Institute, 100 College Street, ONRamp Suite 150, Toronto, Ontario M5G 1L5, Canada
2
BBVA Research & Patents, Calle Sauceda 28, 28050 Madrid, Spain
3
Multiverse Computing, Paseo de Miramón 170, E-20014 San Sebastián, Spain
4
Donostia International Physics Center, Paseo Manuel de Lardizabal 4, E-20018 San Sebastián, Spain
5
Ikerbasque Foundation for Science, Maria Diaz de Haro 3, E-48013 Bilbao, Spain
(Received 14 July 2020; revised 19 July 2021; accepted 19 November 2021; published 3 January 2022)
In this paper we tackle the problem of dynamic portfolio optimization, i.e., determining the optimal trading
trajectory for an investment portfolio of assets over a period of time, taking into account transaction costs and
other possible constraints. This problem is central to quantitative finance. After a detailed introduction to the
problem, we implement a number of quantum and quantum-inspired algorithms on different hardware platforms
to solve its discrete formulation using real data from daily prices over 8 years of 52 assets, and do a detailed
comparison of the obtained Sharpe ratios, profits, and computing times. In particular, we implement classical
solvers (Gekko, exhaustive), D-wave hybrid quantum annealing, two different approaches based on variational
quantum eigensolvers on IBM-Q (one of them brand-new and tailored to the problem), and for the first time
in this context also a quantum-inspired optimizer based on tensor networks. In order to fit the data into each
specific hardware platform, we also consider doing a preprocessing based on clustering of assets. From our
comparison, we conclude that D-wave hybrid and tensor networks are able to handle the largest systems, where
we do calculations up to 1272 fully-connected qubits for demonstrative purposes. Finally, we also discuss how
to mathematically implement other possible real-life constraints, as well as several ideas to further improve the
performance of the studied methods.
DOI: 10.1103/PhysRevResearch.4.013006
exhaustive solver. We expose how preprocessing is performed, Notice that ωtT t ωt is the variance of the portfolio return at
and reduce the problem’s dimensionality using a clustering time t. In practical situations, one typically measures risk at
algorithm. We then do a detailed comparison of all the results, time t in terms of the volatility, which is the square root of this
focusing on the obtained Sharpe ratios and computing times. variance. Nevertheless, Eq. (2) is a convenient way to quantify
From our comparison we conclude that, as of today, D-wave the risk in the dynamic setting since it makes the optimization
hybrid and tensor networks are able to handle the largest problem better behaved, being the prefactor 1/2 a convention.
systems, where we do calculations up to 1272 fully-connected The goal of modern portfolio theory is to find the trajectory,
qubits for demonstrative purposes. Interestingly, we see that which maximizes returns for a fixed risk. It is common to
there is no clear answer as to which is the “best” algorithm request the total investment at any given time is fixed, i.e.,
and/or hardware platform to deal with large systems, as this
depends strongly on different figures of merit.
N
We show how it can be expressed quadratic unconstrained with K the total investment [14]. Let us define at this step the
binary optimization (QUBO) problem, and discuss the dif- normalized weigths
ferences between the continuous and discrete formulations.
In Sec. III we give a very brief overview of the D-wave ωn,t
ωn,t ≡ , (4)
hybrid, VQE, and TN algorithms. In Sec. IV we expose the K
data-preparation procedure, which reduces the problem’s di- so that their sum at every time t is equal to one. In terms
mensionality by identifying irrelevant assets and performing of these normalized weigths, the problem can be solved by
clusterization. Section V compares results obtained using the finding the trajectory {ωti , . . . , ωt f }, which minimizes:
Gekko, exhaustive, D-wave hybrid, VQE, VQE-constrained,
and TN solvers. Section VI discusses industry relevant next
tf
γ T
steps, such as the inclusion of more real-life constraints (e.g, H= −μtT ωt + ω t ωt + ρ(uT ωt − 1)2 . (5)
market impact, exact linear transaction costs, and the so-called t=ti
2 t
10 − 5 − 40 rule) and potential performance improvements.
Finally, in Sec. VII we wrap up and conclude. By analogy to quantum mechanics, we shall refer to the
above cost function H as Hamiltonian. γ is the risk aversion,
which tunes the eagerness of the investor to explore risky
II. PROBLEM OVERVIEW trajectories, and ρ is a Lagrange multiplier that imposes the
The dynamic portfolio optimization problem can be ex- constraint in Eq. (3) as a penalty term. We have introduced
pressed in a form amenable to a quantum computer. In what the N-dimensional vector u, with un = 1 ∀n, which makes the
follows, we present the problem in some technical detail. constraint in Eq. (3) more compact. The Lagrange multiplier
Where possible, we use the notation of [11]. ρ is fine-tuned in order to satisfy Eq. (3).
Note that Eq. (5) can also be written as
013006-2
DYNAMIC PORTFOLIO OPTIMIZATION WITH REAL … PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
This quantifies the amount of return per unit of risk of trading given by the expression
trajectory. Notice that the numerator is the Return, and not the
Profit, which would imply removing all possible additional
tf
T
Profit ≡ μt ωt − λ(ωt )2 , (13)
costs (such as transaction costs, to be discussed later). Notice t=ti
also that, for example, one rebalancing step, the denominator
is the normalized volatility, understood as the square root of i.e., the percentual returns minus the percentual costs.
the variance of the normalized returns. A large Sharpe ratio
means a large return for the risk that is assumed, whereas a B. Continuous versus discrete formulations
ratio close to zero means the opposite, and a negative ratio In this article, we chose to discuss the portfolio optimiza-
means losses instead of profits. tion problem with discrete variables, which is more relevant
to big industry players, as investment funds typically trade in
2. Transaction costs large, discrete amounts. In this section, we will briefly discuss
The problem stated above is simplistic as it does not ac- the case where the asset allocations ωn,t can be approximated
count for transaction costs. These frequently are comparable by continuous variables. This problem is comparatively sim-
to the profit incurred by a given portfolio. The transaction pler, as it gives us access to the full toolbox of differential
costs are typically a percentage of the transaction (whether calculus.
buying or selling assets). They can be expressed in terms of
unnormalized weigths as 1. Continuous asset allocations
When no transaction costs are present, the problem can
tf
tf
N
actually be solved exactly. The minimization of Eq. (6) can
Cost ≡ νt |ωt | = νnt |ωn,t+1 − ωn,t |, (9)
then be written as
t=ti t=ti n=1
∂H ∂ht
with νnt the cost percentage (e.g., νnt = 0.001 for 10 basis = = 0 ∀t, (14)
∂ωtT ∂ωtT
points (BPS), meaning a cost of the 0.1% of the total amount
of the transaction). The objective function, which accounts for which, using μtT ωt = (μtT ωt + ωtT μt )/2 [15], amounts to
these costs in terms of normalized weigths is given by 1 γ
− μt − ρu + t + ρu · uT ωt = 0. (15)
tf
γ 2 2
H= −μtT ωt + ωtT t ωt + νt |ωt | + ρ(uT ωt − 1)2 . Therefore, the optimal solution at time t is given by
t=ti
2
γ −1 1
(10) ωt = t + ρu · uT μt + ρu , (16)
2 2
Note that this is not of the form in Eq. (6), since ωt correlates and the optimal dynamic portfolio is just the concatenation of
times t and t + 1. the optimal portfolios at each time t. For completeness, one
The (percentual) transaction costs are not polynomial in could also get an equation for the multiplier ρ:
the variables ωn,t because of the absolute value function. This
could limit the applicability of some quantum optimization ∂H ∂ht
= = 0 ∀t, (17)
methods. To get around this problem, we can Taylor-expand ∂ρ ∂ρ
the absolute value, in a way similar to the expansion in Ref. [7] which in the end simply implies:
for a step-function. Alternatively, we could introduce ancillary
qubits to treat this problem exactly, as explained in Sec. VI. uT ωt = 1. (18)
Here, we choose to approximate Eq. (9) by a parabola in the This is nothing but the condition in Eq. (3), implying:
considered range of ωn,t :
γ −1 1
K uT t + ρu · uT μt + ρu = 1, (19)
νt |ωt | ≈ ωt t ωt , ωn,t ∈ 0,
T
, (11) 2 2
K
which is indeed an equation for ρ at each time t. In practice,
with t the best matrix of transaction costs at time t that is though, it is much easier to simply use Eq. (16) for a suffi-
compatible and realistic with market conditions. This is an ciently large ρ, and check a posteriori that Eq. (3) is satisfied
excellent approximation to Eq. (9) when the ωn,t are discrete up to some degree of accuracy.
variables and K /K is small. The cost function therefore re- When transaction costs are included, it is no longer possi-
duces to: ble to solve the problem analytically. In the continuous-time
tf limit, we can recast the problem as a set of nonlinearly cou-
γ T
H= −μtT ωt + ω t ωt + λ(ωt )2 + ρ(uT ωt − 1)2 , pled ordinary differential equations. To do so, we notice that
t=ti
2 t in the discrete formulation the increment in time t between
two consecutive time steps is t = 1. The continuous-time
(12)
limit can then be taken as t → 0, implying
with λ the optimal parabolic coefficient for the transaction
tf tf
ωt
costs, as discussed above. Finally, let us remark that in this t → dt, → ω̇, (20)
setting, the percentual profits of the trading trajectory are t=ti ti t
013006-3
SAMUEL MUGEL et al. PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
with ω̇ the time derivative of the vector of asset allocations ω, with x ∈ {0, 1}Ntot the bit vector and Q ∈ RNtot ×Ntot the corre-
which is now a vector field. In this limit, the cost function is sponding QUBO matrix, which can be easily derived from
given by Eqs. (12) and (25). To solve this problem on a quantum
tf computer, we quantize Eq. (26) by promoting the bit variables
S= L(ω, ω̇, t )dt. (21) {xn,t,q } to qubit operators {x̂n,t,q } with eigenstates |0 and |1.
ti Our conclusion at this step is that the portfolio optimization
We will refer to S as the action and L(ω, ω̇, t ) as the La- problem, with discrete investments, as happen in real life, is a
grangian, by analogy to physics. The Lagrangian is obtained natural problem for quantum and quantum-inspired methods.
by taking the continuous-time limit of the cost function H, Its formulation is directly a QUBO, by construction, without
Eq. (12). Finding the optimal trading trajectory thus reduces the need of further mapping the problem to anything else:
to a conventional functional minimization problem. Our goal we can feed this problem to a quantum or quantum-inspired
is to find the time path of ω, which minimizes the action S: solver as is.
013006-4
DYNAMIC PORTFOLIO OPTIMIZATION WITH REAL … PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
FIG. 1. Quantum circuit used for VQE and VQE-constrained algorithms. The system had 15 qubits on the whole, of which 12 were used
in the ansatz. The initial state was |0⊗12 . In the figure, single-site boxes are one-qubit y rotations, and the two-qubit gates are CNOTs (target
qubit being the large circle). In the end, measurements in the computational basis (boxes after the vertical dotted line) are performed on each
qubit and stored in a classical register (as shown by the arrows).
tunneling events, which allow for a more efficient exploration circuit consisted of 82 C-NOTs and 24 variational one-qubit
of the landscape of local minima, especially when the energy rotations, as shown in Fig. 1.
barriers are tall and narrow. Moreover, in order to tackle slightly-larger problems than
In this paper we used the quantum annealer provided by those reachable by plain-vanilla VQE, we implemented a new
D-wave, in particular the so-called D-wave 2000Q proces- and original approach, which we call VQE-constrained for
sor, which gives access to 2048 noncoherent qubits coupled dynamic portfolio optimization. The idea here is quite simple:
through the so-called chimera graph. This architecture allows use VQE to sample several low-energy states at every rebal-
us to solve problems for up to 65 fully-connected qubits, ancing time t, and then use a classical approach to find, which
due to embedding overheads. The D-wave hybrid algorithm combination of these provides the highest returns over the
uses a hybrid classical-quantum strategy to overcomes this whole trading time period. This approach is inspired by low-
limitation, allowing us to deal with much larger problems. In energy-subspace methods in physics. It follows the intuition
a nutshell, D-wave hybrid breaks down problems, which are that the optimal portfolio can be built in most cases from a
larger than the capability of the quantum processor into parts. combination of near-optimal states. Thus, we identify these
These are subsequently recombined to produce the solution. states using VQE (this is the computationally expensive part),
and then recombine them and estimate their associated profits
classically (which is computationally cheap). Our strategy
B. Variational quantum eigensolver here was to look for the best 10 solutions at each trading step
using VQE. Then, in the postprocessing, we tried all possible
The variational quantum eigensolver (VQE) [18] is a hy-
combinations until finding the one that mininized the cost
brid quantum-classical algorithm for optimization. The idea is
function.
to do a variational optimization of a quantum state in order to
obtain an approximation to the ground state of a Hamiltonian.
This idea is quite generic, but the point of the VQE algorithm
is that the ansatz quantum state is, itself, a real quantum state C. Tensor networks
that is implemented on a quantum processor by some quan- TNs are representations of complex quantum states based
tum circuit. The gates in the circuit depend on parameters, on their local entanglement structure [22,23]. Take for in-
which are the variational parameters of the algorithm. After stance a system of n qubits. Any wave function of the system
estimating the energy of the quantum state via sampling, the can be described inefficiently just by giving its O(2n ) coeffi-
parameters are then fine-tuned to lower the energy (using, e.g., cients in the computational basis. As such, these coefficients
conjugate gradient). After a number of iterations, the energy can be understood as a tensor with n indices, where each
converges, producing an approximation to the desired ground index takes two possible values (say, 0 and 1). We could then
state. The performance of VQE depends strongly on several think of replacing this huge, nasty tensor, by a network of
aspects, but most importantly on the choice of variational interconnected tensors with less coefficients, see Fig. 2 for an
quantum circuit. In some cases, the search for some com- example. This construction defines a TN, with each subsystem
plex ground states require of a strongly-entangling quantum in the figure corresponding in practice to the Hilbert space of a
circuit, in turn increasing the complexity of the algorithm. qubit. Constructed in this way, the TN depends on O(poly(n))
However, VQE is still a good option as an optimization tool in parameters only, assuming that the rank of the interconnecting
current noisy intermediate-scale quantum (NISQ) processors indices is upperbounded by a parameter D, which is called
[19]. “bond dimension”. Similarly, interconnecting indices in the
For the sake of this paper, we implemented VQE optimiza- network are also called “bond indices”, and provide the struc-
tion in the quantum processors of IBM-Q, up to 12 qubits. The ture of the many-body entanglement in the quantum state. Any
circuit ansatz for VQE optimization is shown in Fig. 1. It is D > 1 provides an entangled quantum state.
based on a strategy of strongly entangling layers, inspired by As is well known in physics, TNs are a natural tool to solve
the circuit-centric classifier design from Ref. [20], with single- optimization problems. People have been using them as an
qubit rotations around the y axis. In particular, we developed ansatz to approximate low-energy eigenstates of Hamiltoni-
our own VQE algorithm using Xanadu’s PennyLane library ans, and many algorithms have been invented to this aim (see,
for quantum machine learning [21], which is well suited to e.g., Ref. [23] and references therein). The idea here is that,
run on IBM’s quantum backend. Our variational quantum by mapping optimization problems to Hamiltonian eigenvalue
013006-5
SAMUEL MUGEL et al. PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
013006-6
DYNAMIC PORTFOLIO OPTIMIZATION WITH REAL … PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
FIG. 3. Dendogram showing possible data clusters. The Euclidean distance between the different time series is shown on the vertical axis.
transactions are calculated as the sum of returns during the built datasets of different sizes. We considered datasets of
course of that month. Note that we could have calculated them size XS, S, M, L, XL, and XXL, each of which pushes a
on the basis of a rolling average. This has the advantage of solver to its limit. The S dataset, for instance, is the maximal
eliminating daily fluctuations, which make it easier to extract system size, which the exhaustive solver could handle. Details
trends. On the flip side, the asset returns used in comparison of these datasets are shown in Table I. The risk aversion γ
would only approximately reflect the actual asset returns. represents a compromise between risk and returns. By tuning
The daily covariance is an estimate of the daily fluctuations this parameter, we can find the portfolio, which promises the
of a group of assets, encoded in the matrix t at time t. We highest returns for any fixed risk. The set of most profitable
estimate the covariance at time t based on the fluctuations portfolios for all risks is known as the efficient frontier. In
in assets’ returns over a window of the prior 20 business all simulations, and for the sake of simplicity, we set the risk
days. As a remark, notice also that clustered assets have, aversion parameter γ = 1.
by construction, low covariance (since similar assets—i.e., In Table II we show the comparison of Sharpe ratios ob-
those with large covariance—are the ones being clustered!). tained with the different methods and datasets, in Table III
In practice, this also means having a smaller risk factor in the we show the profits (i.e., returns minus transaction costs,
final cost function. percentual), and in Table IV we show an estimation of the
Once we get an optimal portfolio trajectory for clustered computational running time of our simulations. Entries were
effective assets, we unfold the investment by assuming an left blank when a dataset’s size exceed a solver’s capabilities.
equal investment on each asset forming each specific cluster. Note that the solution, which minimizes the cost function
From this we obtain the daily return on an equal investment in H does not always extremize the profit, returns, and Sharpe
each asset within each cluster, and in turn an overall trading ratio. For dataset M for instance, the TN simulation produces
trajectory in the original variables. a trajectory, which presents higher profits and Sharpe ratio
than other solvers, but is further away from the global minima.
V. RESULTS Another example is dataset L, for which Gekko produces the
largest profits, but the largest Sharpe ratio is obtained with
Let us now discuss the results obtained with the different
techniques [26]. To show the capabilities of each solver, we
013006-7
SAMUEL MUGEL et al. PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
TABLE I. Specifics of the different datasets used for benchmarking the different algorithms and hardware platforms. Risk aversion for all
datasets is fixed to γ = 1 and transaction costs to λ = 1. Time steps Nt are measured in business months (i.e., not considering weekends due
to closure of some markets).
Param. XS S M L XL XXL
N 3 4 4 8 8 8
Nt 2 5 7 17 29 53
Nq 1 1 1 2 2 3
Ntot 6 20 28 272 464 1272
2Ntot 64 O(106 ) O(108 ) O(1081 ) O(10139 ) O(10382 )
K 2 3 3 5 10 15
K 1 1 1 3 3 7
TNs instead (see Tables II and III). In fact, the performance We have observed that the D-wave hybrid approach works
of Gekko is quite remarkable, sometimes even better than well for this problem, better in fact than a simple D-wave
quantum and quantum-inspired solutions depending on the approach (results not shown). Specifically, D-wave hybrid al-
metric, but unfortunately the method hits a memory wall lows us to solve problems up to 1272 fully-connected qubits in
around 500 qubits. In this sense, it would be nice to test also 171 seconds, which in our opinion is really fast. We conclude
the performance of other quantum-inspired solutions such as that hybrid classical-quantum approaches can be already quite
Fujitsu’s Digital Annealing, Microsoft QIO, and Amazon’s useful for quickly finding good-quality solutions to practical
Alpha-QUBO, as well as popular methods nowadays such as optimization problems. For the sake of comparison, the cur-
metaheuristics. Some of these techniques provide also a very rent version of our TN solver took 116 833 seconds in solving
good performance that would be worth analyzing. We leave the same problem running on a common laptop (a MacBook
this for future studies. Pro using Matlab), and a pure quantum-annealing approach in
Rosenberg et al. were able so study a system of 24 fully D-wave 2000Q would only have been able to solve up to 65
connected qubits at most (see Ref. [11] Table IV) using fully-connected qubits. We observe also that D-wave hybrid
the capabilities of D-wave’s processor from 2016. By way provides an interesting landscape of potential solutions, see
of comparison, with today’s D-wave hybrid as well as with for instance Table V, where we show the energies as well as
our TN algorithm we optimized up to 1272 fully-connected other relevant quantities computed by the algorithm for an
qubits, and didnot hit the limit of the two approaches. From optimization of 8 assets over 53 trading steps. As shown in
our experience, these two algorithms could well handle the that table, the different figures of merit are in fact different:
full dataset of 28 relevant assets without any clustering and for minimizing the energy does not necessarily, e.g., maximize
reasonable periods of time. The algorithms are under continu- profits.
ous development, but this already shows important progress in We notice that our quantum-inspired TN solver tends to
the performance and variety of portfolio optimization strate- approach the problem’s global minimum more reliably than
gies. D-wave hybrid in some cases. In the case of the M, L, and
Concerning universal quantum processors, we observed XL datasets, for instance, our TN algorithm returns solu-
good convergence of VQE for this problem in small datasets. tions, which have a larger Sharpe ratio and/or larger profits.
As can be seen from Tables II , III, and IV, a naive application Furthermore, for the XXL dataset the solution could still
of universal quantum processors such as IBM-Q still struggle be further improved by playing with different hyperparame-
to tackle optimization problems of commercially relevant di- ters and fine-tuning the algorithm further, which is currently
mensions. We were able to obtain good performance using work in progress. In any case, it is interesting to notice that
appropriate data preparation. Note, however, that universal whereas D-wave hybrid provides the largest profits for the
quantum processors have seen a phenomenal improvement XXL dataset, the largest Sharpe ratio is however given by the
over the past decade, such that we look forward to seeing TN solver. This deserves a deeper analysis, which we leave
progress in this area in the coming years. for future works.
TABLE II. Sharpe ratios computed by the different methods for the different datasets and time periods from Table I.
Method XS S M L XL XXL
VQE 3.59
Exhaustive 6.31 8.90
VQE constrained 6.31 6.04 4.81
Gekko 5.98 8.90 8.39 15.83 20.76
D-wave hybrid 5.98 8.90 8.39 7.47 9.70 12.16
Tensor networks 5.98 8.90 9.54 16.36 15.77 15.83
013006-8
DYNAMIC PORTFOLIO OPTIMIZATION WITH REAL … PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
TABLE III. Profits (percentual) computed by the different methods for the different datasets and time periods from Table I.
Method XS S M L XL XXL
VQE 2.4%
Exhaustive 5.1% 13.9%
VQE constrained 5.1% 9.1% 7.1%
Gekko 5.8% 13.9% 13.6% 54.1% 71.6%
D-wave hybrid 5.8% 13.9% 13.6% 18.9% 29.3% 67.6%
Tensor networks 5.8% 13.9% 15.4% 38.2% 39.6% 39.7%
We anticipate that our TN results can still be largely im- with t a diagonal matrix of market impact coefficients.
proved, both in terms of accuracy and performance. Based Equation (31) can be interpreted as follows: The impact of
on our own estimations, we can reduce at least ≈100× the a trade in asset n at time t on the value of our portfolio is
runtime of our TN algorithm (see Sec. VI), as, in its present proportional to ωn,t , the amount of shares of asset n bought
version, the TN algorithm is not memory intensive. In fact, or sold, and to ωn,t , the amount of shares of asset n held at
acceleration of the TN code is possible at three levels: (i) soft- time t.
ware, (ii) hardware, and (iii) the algorithm itself. All in all, our Note that if we are buying asset n, ωn,t > 0, we expect
paper proves that TN solvers are a cheap and practical way to the asset’s value to increase. Our portfolio’s returns should
tackle large combinatorial optimization problems, compared then grow as ωn,t . The matrix t is therefore positive definite.
to other quantum and quantum-inspired approaches. Similarly, when selling, ωn,t < 0, and our portfolio’s returns
drop with ωn,t .
VI. NEXT STEPS
The resulting classical Hamiltonian including market im-
pact is therefore
Let us now discuss what would be the next steps to make
our algorithms better tailored to real-life situations, as well as
tf
γ T
to improve their efficiency. H= −μtT ωt + ω t ωt + λ(ωt )2
t=ti
2 t
A. More constraints − ωtT t ωt + ρ(uT ωt − 1)2 , (32)
As we said in the introduction, the portfolio optimization
problem is central to quantitative finance. We have discussed again in terms of normalized weigths. Note that this Hamilto-
its dynamic version, where we search for an optimal trading nian is in the form of a QUBO.
trajectory given the price history of several assets. There exist As can be inferred from Eq. (31), this term is non-
many commercially relevant variations of this problem. In negligible only when (i) we have a large amount of the asset
this section, we will discuss three: the market impact, exact being traded in our portfolio, and (ii) the traded amount is
transaction costs, and the 10 − 5 − 40 rule. large.
1. Market impact
2. Exact linear transaction costs
Intuitively, when a large order is passed, it can affect the
As discussed in Sec. II, we would expect the transaction
market. For instance, a large “buy” order may increase the
costs to be linear in the absolute value of the transaction mag-
price of an asset because it signals high demand, whereas a
nitude. We approximated these by a parabola, as polynomial
large “sell” order may instead decrease it. This, of course,
expressions find a more natural formulation as a QUBO. That
would alter the optimal trading trajectory. As discussed in
option is cheap, fast, and works quite well for the accuracies
Ref. [11] this can be implemented as
that are normally considered. It is however possible to exactly
tf implement the linear transaction costs by introducing N × Nt
Market = ωtT t ωt , (31) extra ancillary qubits yn,t . This can be done by noticing that
t=ti the sign of the difference (ωn,t+1 − ωn,t ) in Eq. (11) can be
TABLE IV. Runtimes (in seconds) estimated for the different methods for the different datasets from Table I.
Method XS S M L XL XXL
VQE 278
Exhaustive 0.005 34
VQE constrained 123 412 490
Gekko 24 27 21 221 261
D-wave hybrid 8 39 19 52 74 171
Tensor networks 0.838 51 120 26649 82698 116833
013006-9
SAMUEL MUGEL et al. PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
TABLE V. Example of landscape of computed solutions with D-wave hybrid, for an optimization of 8 assets over 53 trading steps, with
maximum holdings 15: Computed trajectory (T), energy (E), covariance (C), returns (R), transaction costs (TC), profit (P), and Sharpe ratio
(SR). The actual trajectory is not given for space reasons, but is available upon request.
T E C R TC P SR
1 –0.673 0.755 10.566 6.514 4.052 12.161
2 –0.661 0.731 19.347 6.026 4.321 12.101
3 –0.656 0.736 10.248 5.662 4.586 11.939
4 –0.621 0.741 9.841 7.366 2.475 11.428
5 –0.620 0.793 9.736 6.066 3.670 10.931
013006-10
DYNAMIC PORTFOLIO OPTIMIZATION WITH REAL … PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
at the hardware level. Moreover, at the algorithmic level, it From our results we also conclude that there seems to be no
should be possible to try different TN strategies that should clear answer as to which is the “best” algorithm and hardware
also improve the performance. The combination of all these platform to solve the dynamic portfolio optimization problem
easily mean more than 100× acceleration of the calculations. for large systems. This is because there are several figures of
Since memory is not a constraint for our algorithm, this would merit at play: profits, Sharpe ratio, time cost, and also money
also mean the ability to simulate much bigger systems than cost. The performance of the algorithms is different depending
the ones considered in this paper. And of course, this option on the figure of merit, leading us to conclude that, in practice,
would still be cheaper than other alternatives. the more options we have, the better.
We have good reasons to think that the results presented in
VII. CONCLUSION AND OUTLOOK this paper are very promising. They show how real data can
be handled by upcoming quantum computers, and also show
In this paper we have solved the problem of dynamic the potential of quantum-inspired methods such as tensor net-
portfolio optimization using a number of quantum and works. We also realize the importance of hybrid approaches,
quantum-inspired algorithms on different hardware platforms. combining quantum and classical processing. This has been
We ran our solver on the daily values of 52 assets over 8 the key to improved results, e.g., in VQE-constrained and
years. We implemented classical solvers (Gekko, exhaustive), D-wave hybrid. In fact, a hybrid approach combining quantum
D-wave hybrid quantum annealing, two different approaches processing and tensor networks should be quite successful
based on VQE on IBM-Q (one of them brand-new, which for many problems. This is a topic that we are currently
we dubbed “VQE-constrained”), and in this context also a investigating in the broad sense. We also believe that all these
quantum-inspired optimizer based on tensor networks. We developments, involving quantum and quantum-inspired tech-
also implemented a preprocessing based on clustering of as- niques, will change the way quantitative finance is done, and
sets. From our comparison, we conclude that D-wave hybrid for good.
and tensor networks are able to handle the largest possible
systems in the present implementation, i.e., those for the
XXL dataset. More specifically, with these two methods we
ACKNOWLEDGMENTS
managed to solve optimization problems up to 1272 fully-
connected qubits, for demonstrative purposes and without We thank Hossein Sadeghi for insight about D-wave,
hitting the limiting computational capabilities (we could in Mhedi Bozzo-Rey for insight about IBM-Q, as well as
fact have targeted larger systems). For comparison, previous Christophe Jurczak, Pedro Luis Uriarte, Pedro Muñoz-Baroja,
quantum dynamic portfolio optimizations involved up to 72 Creative Destruction Lab, BIC-Gipuzkoa, DIPC, Ikerbasque,
qubits (see Table VI in Ref. [11]). We observed also that and Basque Government for constant support. All authors
D-wave hybrid is remarkably fast, whereas tensor networks contributed to the generation of ideas, algorithm design, algo-
sometimes provide better portfolios at the expense of a longer rithm implementation, analysis of results, and writing of the
calculation time. To the best of our knowledge, our paper is the paper. The authors declare that there are no competing inter-
first application of VQE and TNs to solve a dynamic portfolio ests. The datasets generated during and/or analysed during the
optimization problem with real data. Moreover, our VQE- current study are available from the corresponding author on
constrained approach is also unique, as far as we know. Our a reasonable request. The code used during the current study
preprocessing of real data in order to fit the current capabilities is available from the corresponding author on a reasonable
of quantum processors is also novel in this context. request.
[1] H. Markowitz, Portfolio selection, J. Finance 7, 77 (1952). [7] R. Orús, S. Mugel, and E. Lizaso, Forecasting financial crashes
[2] R. Orús, S. Mugel, and E. Lizaso, Quantum computing for with quantum computing, Phys. Rev. A 99, 060301 (2019).
finance: Overview and prospects, Rev. Phys. 4, 100028 (2019). [8] Y. Ding, L. Lamata, J. D. Martin-Guerrero, E. Lizaso, S. Mugel,
[3] D. J. Egger, C. Gambella, J. Marecek, S. McFaddin, M. Xi Chen, R. Orús, E. Solano, and M. Sanz, Towards predic-
Mevissen, R. Raymond, A. Simonetto, S. Woerner, and E. tion of financial crashes with a D-wave quantum computer,
Yndurain, Quantum computing for finance: State-of-the-art and arXiv:1904.05808.
future prospects, IEEE Trans. Quantum Eng. 1, 1 (2020). [9] G. Rosenberg, Finding optimal arbitrage opportunities us-
[4] P. Rebentrost, B. Gupt, and T. R. Bromley, Quantum compu- ing a quantum annealer, White Paper at https://1qbit.com/
tational finance: Monte Carlo pricing of financial derivatives, whitepaper/arbitrage/.
Phys. Rev. A 98, 022321 (2018). [10] A. Milne, M. Rounds, and P. Goddard, Optimal feature selection
[5] N. Stamatopoulos, D. J. Egger, Y. Sun, C. Zoufal, R. Iten, N. in credit scoring and classification using a quantum annealer, in
Shen, and S. Woerner, Option pricing using quantum comput- High-Performance Computing in Finance: Problems, Methods,
ers, Quantum 4, 291 (2020). and Solutions (Chapman and Hall, London, 2018).
[6] A. Martin, B. Candelas, Á. Rodriguez-Rozas, J. D. Martin- [11] G. Rosenberg, P. Haghnegahdar, P. Goddard, P. Carr, K. Wu,
Guerrero, X. Chen, L. Lamata, R. Orús, E. Solano, and M. Sanz, and M. López De Prado, Solving the optimal trading trajectory
Towards pricing financial derivatives with an IBM quantum problem using a quantum annealer, IEEE J. Sel. Topics Signal
computer, Phys. Rev. Research 3, 013167 (2021). Process. 10, 1053 (2016).
013006-11
SAMUEL MUGEL et al. PHYSICAL REVIEW RESEARCH 4, 013006 (2022)
[12] M. López de Prado, Generalized optimal trading trajectories: [19] J. Preskill, Quantum computing in the NISQ era and beyond,
A financial quantum computing application, available at SSRN Quantum 2, 79 (2018).
https://ssrn.com/abstract=2575184. [20] M. Schuld, A. Bocharov, K. M. Svore, and N. Wiebe, Circuit-
[13] L. D.R. Beal, D. C. Hill, R. Abraham Martin, and J. D. centric quantum classifiers, Phys. Rev. A 101, 032308 (2020).
Hedengren, GEKKO optimization suite, Processes 6, 106 [21] V. Bergholm, J. Izaac, M. Schuld, C. Gogolin, M. S. Alam, S.
(2018),. Ahmed, J. M. Arrazola, C. Blank, A. Delgado, S. Jahangiri, et
N
[14] An obvious but nontrivial remark: imposing n=1 ω n,t K al., Pennylane: Automatic differentiation of hybrid quantum-
instead, may actually produce portfolios with higher returns. classical computations, arXiv:1811.04968.
Notice also that K is the investment, and not the value of the [22] R. Orús, A practical introduction to tensor networks: Matrix
investment, e.g., K = 3 apples, not the value (e.g., in dollars) of product states and projected entangled pair states, Ann. Phys.
those 3 apples. (NY) 349, 117 (2014).
[15] A different splitting amounts to a rescaling of the op- [23] R. Orús, Tensor networks for complex quantum systems, Nat.
timal Lagrange multiplier ρ, without changing the actual Rev. Phys. 1, 538 (2019).
solution. [24] M. Fannes, B. Nachtergaele, and R. F. Werner, Finitely corre-
[16] F. Barahona, On the computational complexity of ising lated states on quantum spin chains, Commun. Math. Phys. 144,
spin glass models, J. Phys. A: Math. Gen. 15, 3241 443 (1992).
(1982). [25] See, e.g., https://en.wikipedia.org/wiki/Rate_of_return.
[17] E. Farhi, J. Goldstone, S. Gutmann, and M. Sipser, Quantum [26] All portfolio optimizers have been developed by the Multiverse
computation by adiabatic evolution, arXiv:quant-ph/0001106. Computing© team.
[18] A. Peruzzo, J. McClean, P. Shadbolt, M.-H. Yung, X.-Q. Zhou, [27] C. McGeoch and P. Farré, The D-wave advantage
P. J. Love, A. Aspuru-Guzik, and J. L. O’Brien, A varia- system: An overview, Technical Report available at
tional eigenvalue solver on a photonic quantum processor, Nat. https://www.dwavesys.com/media/s3qbjp3s/14-1049a-
Commun. 5, 4213 (2014). a_the_d-wave_advantage_system_an_overview.pdf.
013006-12