|
25 | 25 | "\n", |
26 | 26 | "## Introduction \n", |
27 | 27 | "\n", |
28 | | - "In asset management, there are broadly two approaches: active and passive investment management. Within passive investment management, there are index-tracking funds and there are approaches based on portfolio diversification, which aim at representing a portfolio with large number of assets by a smaller number of representative stocks.\n", |
| 28 | + "In asset management, there are broadly two approaches: active and passive investment management. Within passive investment management, there are index-tracking funds and there are approaches based on portfolio diversification, which aim at representing a portfolio with a large number of assets by a smaller number of representative stocks.\n", |
29 | 29 | "This notebook illustrates a portfolio diversification problem, which has recently become popular for two reasons:\n", |
30 | | - "1. it makes it possible to mimick the performance of an index (or a similarly large set of assets) with a limited budget, at limited transaction costs. That is: traditional index-tracking may purchase all assets in the index, ideally with the same weights as in the index. This may be impractical for a number of reasons: the total of even a single round lot per asset may amount to more than the assets under management, the large scale of the index-tracking problem with integrality constraints may render the optimisation problem difficult, and the transaction costs of the frequent rebalancing to adjust the positions to the weights in the index may render the approach expensive. Thus, a popular approach is to select a portfolio of $q$ assets that represent the market with $n$ assets, where $q$ is significantly smaller than $n$, but where the portfolio replicates the behaviour of the underlying market. To determine how to group assets into $q$ clusters and how to determine which $q$ assets should represent the $q$ clusters amounts to solving a large-scale optimization problem. In the following we describe the mathematical model for the portfolio diversification problem as introduced in [Cornuejols & Tutuncu, 2006] \n", |
31 | | - "2. it allows for similarity measures between time-series beyond the covariance matrix. Notice that traditionally, modern portfolio theory considers the covariance matrix as measure of similarity between the assets. As such, however, covariance matrix is imperfect. Consider, for instance, a company listed both in London and New York. Although both listings should be very similar, only parts of the time series of the prices of the two listings will overlap, because of the partial overlap of the times the markets open. Instead of covariance, one can consider, for example, dynamic time warping of [Berndt and Clifford, 1994] as a measure of similarity between two time series, which allows for the fact that for some time periods, the data are captured by only one of the time series, while for others, both time series exhibit the similarity due to the parallel evolution of the stock price.\n", |
| 30 | + "1. it makes it possible to mimic the performance of an index (or a similarly large set of assets) with a limited budget, at limited transaction costs. That is: traditional index-tracking may purchase all assets in the index, ideally with the same weights as in the index. This may be impractical for a number of reasons: the total of even a single round lot per asset may amount to more than the assets under management, the large scale of the index-tracking problem with integrality constraints may render the optimization problem difficult, and the transaction costs of the frequent rebalancing to adjust the positions to the weights in the index may render the approach expensive. Thus, a popular approach is to select a portfolio of $q$ assets that represent the market with $n$ assets, where $q$ is significantly smaller than $n$, but where the portfolio replicates the behavior of the underlying market. To determine how to group assets into $q$ clusters and how to determine which $q$ assets should represent the $q$ clusters amounts to solving a large-scale optimization problem. In the following we describe the mathematical model for the portfolio diversification problem as introduced in [Cornuejols & Tutuncu, 2006] \n", |
| 31 | + "2. it allows for similarity measures between time-series beyond the covariance matrix. Notice that traditionally, modern portfolio theory considers the covariance matrix as a measure of similarity between the assets. As such, however, the covariance matrix is imperfect. Consider, for instance, a company listed both in London and New York. Although both listings should be very similar, only parts of the time series of the prices of the two listings will overlap, because of the partial overlap of the times the markets open. Instead of covariance, one can consider, for example, dynamic time warping of [Berndt and Clifford, 1994] as a measure of similarity between two time series, which allows for the fact that for some time periods, the data are captured by only one of the time series, while for others, both time series exhibit the similarity due to the parallel evolution of the stock price.\n", |
32 | 32 | "\n", |
33 | 33 | "The overall workflow we demonstrate comprises:\n", |
34 | 34 | "\n", |
35 | 35 | "1. pick the ground set of assets. In our case, this is a small number of US stocks.\n", |
36 | 36 | "\n", |
37 | | - "2. load the time series capturing the evolution of the prices of assets. In our case, this is an simplistic load of adjusted daily closing price data from Wikipedia or Nasdaq or LSE or EuroNext, whereas in a real asset management, a much higher frequency may be considered.\n", |
| 37 | + "2. load the time series capturing the evolution of the prices of assets. In our case, this is a simplistic load of adjusted daily closing price data from Wikipedia or Nasdaq or LSE or EuroNext, whereas in a real asset management, a much higher frequency may be considered.\n", |
38 | 38 | "\n", |
39 | 39 | "3. compute the pair-wise similarity among the time series. In our case, we run a linear-time approximation of the dynamic time warping, still on the classical computer.\n", |
40 | 40 | "\n", |
41 | 41 | "4. compute the actual portfolio of $q$ representative assets, based on the similarity measure. This step is run twice, actually. First, we obtain a reference value by a run of an IBM solver (IBM ILOG CPLEX or the Exact Eigensolver) on the classical computer. Second, we run an alternative, hybrid algorithm partly on the quantum computer.\n", |
42 | 42 | "\n", |
43 | | - "5. visualisation of the results. In our case, this is again a simplistic plot.\n", |
| 43 | + "5. visualization of the results. In our case, this is again a simplistic plot.\n", |
44 | 44 | "\n", |
45 | 45 | "In the following, we first explain the model used in (4) above, before we proceed with the installation of the pre-requisites and the data loading.\n", |
46 | 46 | "\n", |
|
106 | 106 | "(BPO) \\quad f = \\max_{x_{ij}, y_{j}} \\,\\, \\sum_{i=1}^n \\sum_{j=1}^n \\rho_{ij} x_{ij}\n", |
107 | 107 | "$$\n", |
108 | 108 | "\n", |
109 | | - "subject to the clustering constrain, the integral constraints, and the following modified consistency constraints:\n", |
| 109 | + "subject to the clustering constraint, the integral constraints, and the following modified consistency constraints:\n", |
110 | 110 | "\n", |
111 | 111 | "$$\\sum_{j=1}^n x_{ij} = 1, \\,\\textrm{ for }\\, i = 1,\\ldots, n,$$\n", |
112 | 112 | "$$\\quad x_{ij} (1- y_j) = 0,\\,\\textrm{ for }\\, i = 1,\\ldots, n; \\, j = 1,\\ldots, n,$$\n", |
113 | 113 | "$$\\quad x_{jj} = y_j,\\,\\textrm{ for }\\, j = 1,\\ldots, n.$$\n", |
114 | 114 | "\n", |
115 | 115 | "### Construct the Ising Hamiltonian\n", |
116 | 116 | "\n", |
117 | | - "We can now construct the Ising Hamiltonian (QUBO) by penalty methods (introducting a penalty coefficient $A$ for each equality constraint) as\n", |
| 117 | + "We can now construct the Ising Hamiltonian (QUBO) by penalty methods (introducing a penalty coefficient $A$ for each equality constraint) as\n", |
118 | 118 | "\n", |
119 | 119 | "$$\n", |
120 | 120 | "(IH) \\quad H = \\sum_{i=1}^n \\sum_{j=1}^n \\rho_{ij} x_{ij} + A\\Big( \\sum_{j=1}^n y_j - q\\Big)^2 + \\sum_{i=1}^n A\\Big( \\sum_{j=1}^n x_{ij} - 1\\Big)^2 + \\sum_{j=1}^n A (x_{jj}-y_j)^2 +\\sum_{i=1}^n \\sum_{j=1}^n A \\left(x_{ij} (1- y_j)\\right).\n", |
|
164 | 164 | "$$\n", |
165 | 165 | "(IH-QP)\\quad \\max_{{\\bf z}\\in\\{0,1\\}^{n(n+1)}} \\, {\\bf z}^T ({\\bf Q}_0+{\\bf Q}_1+ {\\bf Q}_2 + {\\bf Q}_3 ){\\bf z} + ({\\bf c}_0+{\\bf c}_1+{\\bf c}_2+{\\bf c}_3)^T {\\bf z} +r_0+r_1+r_2$$\n", |
166 | 166 | "\n", |
167 | | - "which can be passed to variational quantum eigensolver. \n", |
| 167 | + "which can be passed to the variational quantum eigensolver. \n", |
168 | 168 | "\n", |
169 | 169 | "\n", |
170 | 170 | "\n", |
|
233 | 233 | "cell_type": "markdown", |
234 | 234 | "metadata": {}, |
235 | 235 | "source": [ |
236 | | - "Next, we download price data for two stocks and compute their pair-wise similarity matrix (<a target=\"_blank\" href=\"https://en.wikipedia.org/wiki/Dynamic_time_warping\">dynamic time warping</a> distance normalised to (0,1] by taking the reciprocal). If this fails, e.g., due to your being offline or exeeding the daily limit for accesses to the stock-market data, we consider a constant matrix instead." |
| 236 | + "Next, we download price data for two stocks and compute their pair-wise similarity matrix (<a target=\"_blank\" href=\"https://en.wikipedia.org/wiki/Dynamic_time_warping\">dynamic time warping</a> distance normalized to (0,1] by taking the reciprocal). If this fails, e.g., due to you being offline or exceeding the daily limit for accesses to the stock-market data, we consider a constant matrix instead." |
237 | 237 | ] |
238 | 238 | }, |
239 | 239 | { |
|
444 | 444 | "\n", |
445 | 445 | "For the quantum solution, we use Qiskit. We first define a class QuantumOptimizer that encodes the quantum approach to solve the problem and then we instantiate it and solve it. We define the following methods inside the class:\n", |
446 | 446 | "\n", |
447 | | - "- `exact_solution` : to make sure that the Ising Hamiltonian is correctly encoded in the $Z$ basis, we can compute its eigendecomposition classicaly, i.e., considering a symmetric matrix of dimension $2^N \\times 2^N$. For the problem at hand $n=3$, that is $N = 12$ seems the limit for many laptops; \n", |
| 447 | + "- `exact_solution` : to make sure that the Ising Hamiltonian is correctly encoded in the $Z$ basis, we can compute its eigendecomposition classically, i.e., considering a symmetric matrix of dimension $2^N \\times 2^N$. For the problem at hand $n=3$, that is $N = 12$, seems to be the limit for many laptops; \n", |
448 | 448 | "- `vqe_solution` : solves the problem $(M)$ via the variational quantum eigensolver (VQE);\n", |
449 | 449 | "- `qaoa_solution` : solves the problem $(M)$ via a Quantum Approximate Optimization Algorithm (QAOA)." |
450 | 450 | ] |
|
677 | 677 | "cell_type": "markdown", |
678 | 678 | "metadata": {}, |
679 | 679 | "source": [ |
680 | | - "Solution shows the selected stocks via the stars and in green the links (via similarities) with other stocks that are represented in the fund by the linked stock. Keep in mind that VQE is an heuristic working on the QP formulation of the Ising Hamiltonian, though. For suitable choices of A, local optima of the QP formulation will be feasible solutions to the ILP. While for some small instances, as above, we can find optimal solutions of the QP formulation which coincide with optima of the ILP, finding optimal solutions of the ILP is harder than finding local optima of the QP formulation, in general. Even within the VQE, one may provide stronger guarantees, for specific variational forms (trial wave functions). " |
| 680 | + "Solution shows the selected stocks via the stars and in green the links (via similarities) with other stocks that are represented in the fund by the linked stock. Keep in mind that VQE is a heuristic working on the QP formulation of the Ising Hamiltonian, though. For suitable choices of A, local optima of the QP formulation will be feasible solutions to the ILP. While for some small instances, as above, we can find optimal solutions of the QP formulation which coincide with optima of the ILP, finding optimal solutions of the ILP is harder than finding local optima of the QP formulation, in general. Even within the VQE, one may provide stronger guarantees, for specific variational forms (trial wave functions). " |
681 | 681 | ] |
682 | 682 | }, |
683 | 683 | { |
|
0 commit comments