Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions qiskit/finance/optimization/portfolio_diversification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
"<img src=\"../../../images/qiskit-heading.gif\" width=\"500 px\" align=\"left\">"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# _*Qiskit Finance: Portfolio diversification*_\n",
"\n",
"The latest version of this notebook is available on https://github.com/qiskit/qiskit-tutorial.\n",
"The latest version of this notebook is available on https://github.com/qiskit/qiskit-tutorials.\n",
"\n",
"***\n",
"### Contributors\n",
Expand All @@ -25,10 +32,10 @@
"\n",
"## Introduction \n",
"\n",
"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",
"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 assets.\n",
"This notebook illustrates a portfolio diversification problem, which has recently become popular for two reasons:\n",
"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",
"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",
"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 asset price.\n",
"\n",
"The overall workflow we demonstrate comprises:\n",
"\n",
Expand All @@ -50,10 +57,10 @@
"As discussed in [Cornuejols & Tutuncu, 2006], we describe a mathematical model that clusters assets into groups of similar ones and selects one representative asset from each group to be included in the index fund portfolio. The model is based on the following data, which we will discuss in more detail later:\n",
"\n",
"$$\n",
"\\rho_{ij} = \\textrm{similarity}\\, \\textrm{between}\\, \\textrm{stock}\\, i \\, \\textrm{and}\\, \\textrm{stock}\\, j.\n",
"\\rho_{ij} = \\textrm{similarity}\\, \\textrm{between}\\, \\textrm{asset}\\, i \\, \\textrm{and}\\, \\textrm{asset}\\, j.\n",
"$$\n",
"\n",
"For example, $\\rho_{ii} = 1$, $\\rho_{ij} \\leq 1$ for $i \\neq j$ and $\\rho_{ij}$ is larger for more similar stocks. An example of this is the correlation between the returns of stocks $i$ and $j$. But one could choose other similarity indices $\\rho_{ij}$.\n",
"For example, $\\rho_{ii} = 1$, $\\rho_{ij} \\leq 1$ for $i \\neq j$ and $\\rho_{ij}$ is larger for more similar assets. An example of this is the correlation between the returns of asset $i$ and $j$. But one could choose other similarity indices $\\rho_{ij}$.\n",
"\n",
"The problem that we are interested in solving is:\n",
"\n",
Expand Down Expand Up @@ -81,9 +88,9 @@
"\\quad x_{ij}, y_j \\in\\{0,1\\}, \\,\\textrm{ for }\\, i = 1,\\ldots, n; \\, j = 1,\\ldots, n.\n",
"$$\n",
"\n",
"The variables $y_j$ describe which stocks $j$ are in the index fund ($y_j = 1$ if $j$ is selected in the fund, $0$ otherwise). For each stock $i = 1,\\dots,n$, the variable $x_{ij}$ indicates which stock $j$ in the index fund is most similar to $i$ ($x_{ij} = 1$ if $j$ is the most similar stock in the index fund, $0$ otherwise).\n",
"The variables $y_j$ describe which assets $j$ are in the index fund ($y_j = 1$ if $j$ is selected in the fund, $0$ otherwise). For each asset $i = 1,\\dots,n$, the variable $x_{ij}$ indicates which asset $j$ in the index fund is most similar to $i$ ($x_{ij} = 1$ if $j$ is the most similar asset in the index fund, $0$ otherwise).\n",
"\n",
"The first constraint selects $q$ stocks in the fund. The second constraint imposes that each stock $i$ has exactly one representative stock $j$ in the fund. The third and fourth constraints guarantee that stock $i$ can be represented by stock $j$ only if $j$ is in the fund. The objective of the model maximizes the similarity between the $n$ stocks and their representatives in the fund. Different cost functions can also be considered. \n",
"The first constraint selects $q$ assets in the fund. The second constraint imposes that each asset $i$ has exactly one representative asset $j$ in the fund. The third and fourth constraints guarantee that asset $i$ can be represented by asset $j$ only if $j$ is in the fund. The objective of the model maximizes the similarity between the $n$ asset and their representatives in the fund. Different cost functions can also be considered. \n",
"\n",
"Let us concatenate the decision variables in one vector \n",
"\n",
Expand Down Expand Up @@ -233,7 +240,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
"Next, we download price data for two assets 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."
]
},
{
Expand Down Expand Up @@ -265,7 +272,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we decide on the number of clusters. This has to be smaller than the number of stocks we have loaded."
"Now we decide on the number of clusters. This has to be smaller than the number of assets we have loaded."
]
},
{
Expand Down Expand Up @@ -433,7 +440,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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. "
"Solution shows the selected assets via the stars and in green the links (via similarities) with other assets that are represented in the fund by the linked asset. "
]
},
{
Expand Down Expand Up @@ -677,15 +684,26 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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). "
"The plot shows the selected assets with stars; in green, it shows the links with other assets that are represented in the portfolio by the starred asset.\n",
"\n",
"Keep in mind that VQE is an heuristic working on the QP formulation of the Ising Hamiltonian. For suitable choices of A, local optima of the QP formulation will be feasible solutions to the integer programming problem. While for some small instances, as above, we can find optimal solutions of the QP formulation that coincide with optima of the integer programming problem, finding optimal solutions of the integer programming problem is harder than finding local optima of the quadratic programming formulation, in general. \n",
"\n",
"Even within the VQE, one may provide stronger guarantees, for specific variational forms (trial wave functions). Beyond VQE, one can show convergence to the global optiam using the phase estimation approach. One can, indeed, start by using VQE and moving to phase estimation subsequently, cf. https://github.com/Qiskit/qiskit-tutorials/blob/master/community/aqua/general/vqe2iqpe.ipynb"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "qiskit_master",
"display_name": "Python 3",
"language": "python",
"name": "qiskit_master"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -697,7 +715,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down
12 changes: 8 additions & 4 deletions qiskit/optimization/vehicle_routing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,11 @@
"source": [
"The plots present the depot with a star and the selected routes for the vehicles with arrows. Note that in this particular case, we can find the optimal solution of the QP formulation, which happens to coincide with the optimal solution of the ILP.\n",
"\n",
"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, which in turn is harder than finding feasible solutions of the ILP. Even within the VQE, one may provide stronger guarantees, for specific variational forms (trial wave functions). \n",
"The plot shows the selected assets with stars; in green, it shows the links with other assets that are represented in the portfolio by the starred asset.\n",
"\n",
"Keep in mind that VQE is an heuristic working on the QP formulation of the Ising Hamiltonian. For suitable choices of A, local optima of the QP formulation will be feasible solutions to the integer programming problem. While for some small instances, as above, we can find optimal solutions of the QP formulation that coincide with optima of the integer programming problem, finding optimal solutions of the integer programming problem is harder than finding local optima of the quadratic programming formulation, in general. \n",
"\n",
"Even within the VQE, one may provide stronger guarantees, for specific variational forms. Beyond VQE, one can show convergence to the global optiam using the phase estimation approach. One can, indeed, start by using VQE and moving to phase estimation subsequently, cf. https://github.com/Qiskit/qiskit-tutorials/blob/master/community/aqua/general/vqe2iqpe.ipynb\n",
"\n",
"Last but not least, you may be pleased to learn that the above has been packaged in Qiskit Aqua."
]
Expand Down Expand Up @@ -922,9 +926,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "qiskit_master",
"display_name": "Python 3",
"language": "python",
"name": "qiskit_master"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -936,7 +940,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down