{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Portfolio optimization on Dirac\n", "#### Device: Dirac-1\n", "\n", "\n", "## Introduction\n", "\n", "This approach seeks to identify a sub-portfolio of stocks that have superior risk-return profiles compared to the full portfolio. This identifies opportunities for an investor to simplify their investment strategy without sacrificing (and potentially enhancing) the risk-adjusted return. While the expected return on a portfolio is relatively straightforward to optimize by itself, optimizing against risk is more subtle when choosing a set of assets that individually have high returns. The reason that optimizing against risk is more challenging is because asset performances can be correlated. Intuitively, one can see that investing in two highly-correlated assets is more risky than if they are uncorrelated or even anti-correlated. If one of a highly correlated asset is performing poorly, the other in the pair is likely to do so as well. Thus, the variance of a portfolio with both assets can be significantly higher than it would be if they were uncorrelated. Minimizing the overall variance for the return of a portfolio therefore needs to take into account the covariance between the assets, making this a fundamentally quadratic problem, ideal for our Dirac-1 solver.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importance\n", "\n", "Investments need not only give a good return on average, but also need to balance the potential risks. This balance will depend on the goal of the investor. For example, someone investing their retirement fund is likely to favor modest returns with low risks because the consequences of major losses are severe. On the other hand, someone who is day-trading in the hopes of having more money for entertainment might be willing to take more risks. There are of course many other scenarios with other risk levels. In general, the portfolio optimization problem is viewed as being a multi-objective problem. The goal is to balance the objective of maximizing return with the objective of minimizing risk. Even with multiple objectives there is still a sense of optimality, a portfolio is said to be \"efficient\" or \"[Pareto optimal](https://en.wikipedia.org/wiki/Multi-objective_optimizationy)\" if the only ways to decrease risk would be to also decrease return. Regardless of one's appetite for risk, it never makes sense to invest in a non-Pareto-Optimal portfolio, so our goal is to find those that are Pareto optimal and match the appetite for risk which is parameterized by a term $\\xi$ in our description. It is worth noting that this tutorial is based on a relatively simplified but still commonly used model of portfolio optimization. Various efforts exist to take into account more complex structure in the distribution of expected returns, in particular [the failure to capture extreme events](http://math.bu.edu/people/murad/pub/hist11-posted.pdf)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Applications\n", "\n", "Portfolios diversification is necessary to achieve satisfactory outcomes for investors, making the kind of portfolio optimization discussed here (and potentially more complex variants) highly important. In spite of its simplicity, the model of diversification presented here, often referred to as [modern portfolio](https://www.britannica.com/money/modern-portfolio-theory-explained) theory, is [still used](https://www.nutmeg.com/nutmegonomics/markowitzs-legacy-why-modern-portfolio-theory-still). Improvements of the models presented here comprise a subject known as [post-modern portfolio theory](http://actuaries.org/AFIR/Colloquia/Orlando/Ferguson_Rom.pdf). One improvement is to consider a quantity known as [downside risk](https://www.lehigh.edu/~xuy219/research/Downside.pdf) instead of variance. Downside risk only takes into account the risk of portfolio elements underperforming a goal, rather than their total variation. Since the goal of diversification is to protect from risk, this approach can yield better performance." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Methodology\n", "\n", "Let K be the total number of available stocks to choose from (here $K = 253$), that is the size of the stock pool. We want to choose a subset of $K^\\prime$ ($K^\\prime < K$) stocks such that the portfolio risk is minimized, while the portfolio expected return is maximized, that is\n", "\n", "$\\min_{\\{x_{i}\\}_{i \\in \\{1, 2,..., K\\}}} [-E(R)^2 + \\xi VAR(R)]$\n", "\n", "where $R$ is the daily returns of the portfolio over some period of time, $VAR(R)$ and $E(R)$ are the variance and expectation of daily returns, $\\xi$ is a hyper-parameter, and $\\{x_{i}\\}$ are binary variables representing inclusion or exclusion of a stock. A large value means the focus of optimization is to increase return, whereas a small value indicates the reduction of risk is more important. As we can take both long and short positions on stocks, we assume that $x_1, x_2, ..., x_K$ corresponds to long positions on stocks 1 to $K$. \n", "\n", "As we are choosing a subset of $K^\\prime$ stocks, we also need the following constraint,\n", "\n", "$\\sum_{i=1}^{K} x_i = K^\\prime$\n", "\n", "Assuming that the same amount is invested on each of the K' selected stocks, the portfolio daily return at time t over a time period denoted by m can be expanded as follows,\n", "\n", "$R^{(m)}(t) =\\frac{1}{K^\\prime} \\sum_{i=1}^{K} x_i r^{(m)}_i(t)$\n", "\n", "where $r^{(m)}_i(t)$ is the daily return of stock i at time $t$ in time period $m$. The expectation of portfolio daily return over time period $m$ can thus be expanded as,\n", "\n", "$E(R^{(m)}) = \\frac{1}{K^\\prime} \\sum_{i=1}^{K} x_i E(r^{(m)}_i)$\n", "\n", "and the variance portfolio daily return over time period m is expanded as,\n", "\n", "$VAR(R^{(m)}) = \\frac{1}{K^{\\prime 2}} \\sum_{i=1}^{K} \\sum_{j=1}^{K} x_i x_j COV(r^{(m)}_i, r^{(m)}_j)$\n", "\n", "where $COV$ is the covariant function. \n", "\n", "The problem then reduces to\n", "\n", "$\\min_{\\{x_i\\}} {\\bf{x}^T} \\frac{1}{K^{\\prime 2}} [ Q^{(m)} - \\xi P^{(m)}] {\\bf{x}}$\n", "\n", "where\n", "\n", "$Q^{(m)}_{ij} = COV(r^{(m)}_{i}, r^{(m)}_{j})$\n", "\n", "$P^{(m)}_{ij}= E(r_i^{(m)}) \\delta_{ij}$\n", "\n", "To avoid an over-fit on the portfolio data, we can minimize the average of the cost function over $M$ overlapping time periods, that is $m=1,2,...,M$. The problem becomes,\n", "\n", "$\\min_{\\{x_i\\}} {\\bf{x}^T} \\frac{1}{MK^{\\prime 2}} \\sum_{m=1}^{M}[ Q^{(m)} - \\xi P^{(m)}] {\\bf{x}}$\n", "\n", "subject to,\n", "\n", "$\\sum_{i=1}^{K} x_i = K^\\prime$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Implementation\n", "\n", "The above-mentioned approach was used to construct an optimal portfolio based on the constituents of the Nasdaq-100 index. The following constituents were used," ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Company | \n", "Symbol | \n", "
---|---|---|
0 | \n", "Microsoft Corp | \n", "MSFT | \n", "
1 | \n", "Apple Inc | \n", "AAPL | \n", "
2 | \n", "Amazon.com Inc | \n", "AMZN | \n", "
3 | \n", "Alphabet Inc | \n", "GOOG | \n", "
4 | \n", "Alphabet Inc | \n", "GOOGL | \n", "
5 | \n", "NVIDIA Corp | \n", "NVDA | \n", "
6 | \n", "Tesla Inc | \n", "TSLA | \n", "
7 | \n", "Meta Platforms Inc | \n", "META | \n", "
8 | \n", "PepsiCo Inc | \n", "PEP | \n", "
9 | \n", "Broadcom Inc | \n", "AVGO | \n", "
10 | \n", "Costco Wholesale Corp | \n", "COST | \n", "
11 | \n", "Cisco Systems Inc | \n", "CSCO | \n", "
12 | \n", "T-Mobile US Inc | \n", "TMUS | \n", "
13 | \n", "Adobe Inc | \n", "ADBE | \n", "
14 | \n", "Texas Instruments Inc | \n", "TXN | \n", "
15 | \n", "Comcast Corp | \n", "CMCSA | \n", "
16 | \n", "Honeywell International Inc | \n", "HON | \n", "
17 | \n", "Amgen Inc | \n", "AMGN | \n", "
18 | \n", "Netflix Inc | \n", "NFLX | \n", "
19 | \n", "QUALCOMM Inc | \n", "QCOM | \n", "
20 | \n", "Starbucks Corp | \n", "SBUX | \n", "
21 | \n", "Intel Corp | \n", "INTC | \n", "
22 | \n", "Intuit Inc | \n", "INTU | \n", "
23 | \n", "Gilead Sciences Inc | \n", "GILD | \n", "
24 | \n", "Advanced Micro Devices Inc | \n", "AMD | \n", "
25 | \n", "Automatic Data Processing Inc | \n", "ADP | \n", "
26 | \n", "Intuitive Surgical Inc | \n", "ISRG | \n", "
27 | \n", "Mondelez International Inc | \n", "MDLZ | \n", "
28 | \n", "Applied Materials Inc | \n", "AMAT | \n", "
29 | \n", "Analog Devices Inc | \n", "ADI | \n", "
30 | \n", "Regeneron Pharmaceuticals Inc | \n", "REGN | \n", "
31 | \n", "PayPal Holdings Inc | \n", "PYPL | \n", "
32 | \n", "Moderna Inc | \n", "MRNA | \n", "
33 | \n", "Booking Holdings Inc | \n", "BKNG | \n", "
34 | \n", "Vertex Pharmaceuticals Inc | \n", "VRTX | \n", "
35 | \n", "CSX Corp | \n", "CSX | \n", "
36 | \n", "Fiserv Inc | \n", "FISV | \n", "
37 | \n", "Lam Research Corp | \n", "LRCX | \n", "
38 | \n", "Activision Blizzard Inc | \n", "ATVI | \n", "
39 | \n", "Micron Technology Inc | \n", "MU | \n", "
40 | \n", "KLA Corp | \n", "KLAC | \n", "
41 | \n", "Monster Beverage Corp | \n", "MNST | \n", "
42 | \n", "O'Reilly Automotive Inc | \n", "ORLY | \n", "
43 | \n", "Keurig Dr Pepper Inc | \n", "KDP | \n", "
44 | \n", "ASML Holding NV | \n", "ASML | \n", "
45 | \n", "Synopsys Inc | \n", "SNPS | \n", "
46 | \n", "Kraft Heinz Co/The | \n", "KHC | \n", "
47 | \n", "Charter Communications Inc | \n", "CHTR | \n", "
48 | \n", "American Electric Power Co Inc | \n", "AEP | \n", "
49 | \n", "Marriott International Inc/MD | \n", "MAR | \n", "
50 | \n", "Palo Alto Networks Inc | \n", "PANW | \n", "
51 | \n", "Cintas Corp | \n", "CTAS | \n", "
52 | \n", "Cadence Design Systems Inc | \n", "CDNS | \n", "
53 | \n", "MercadoLibre Inc | \n", "MELI | \n", "
54 | \n", "Dexcom Inc | \n", "DXCM | \n", "
55 | \n", "Exelon Corp | \n", "EXC | \n", "
56 | \n", "Biogen Inc | \n", "BIIB | \n", "
57 | \n", "AstraZeneca PLC ADR | \n", "AZN | \n", "
58 | \n", "NXP Semiconductors NV | \n", "NXPI | \n", "
59 | \n", "Paychex Inc | \n", "PAYX | \n", "
60 | \n", "Enphase Energy Inc | \n", "ENPH | \n", "
61 | \n", "Autodesk Inc | \n", "ADSK | \n", "
62 | \n", "Pinduoduo Inc ADR | \n", "PDD | \n", "
63 | \n", "Ross Stores Inc | \n", "ROST | \n", "
64 | \n", "Fortinet Inc | \n", "FTNT | \n", "
65 | \n", "Microchip Technology Inc | \n", "MCHP | \n", "
66 | \n", "Xcel Energy Inc | \n", "XEL | \n", "
67 | \n", "Lululemon Athletica Inc | \n", "LULU | \n", "
68 | \n", "Airbnb Inc | \n", "ABNB | \n", "
69 | \n", "Workday Inc | \n", "WDAY | \n", "
70 | \n", "PACCAR Inc | \n", "PCAR | \n", "
71 | \n", "Walgreens Boots Alliance Inc | \n", "WBA | \n", "
72 | \n", "IDEXX Laboratories Inc | \n", "IDXX | \n", "
73 | \n", "Electronic Arts Inc | \n", "EA | \n", "
74 | \n", "Marvell Technology Inc | \n", "MRVL | \n", "
75 | \n", "Old Dominion Freight Line Inc | \n", "ODFL | \n", "
76 | \n", "GLOBALFOUNDRIES Inc | \n", "GFS | \n", "
77 | \n", "CoStar Group Inc | \n", "CSGP | \n", "
78 | \n", "Dollar Tree Inc | \n", "DLTR | \n", "
79 | \n", "Illumina Inc | \n", "ILMN | \n", "
80 | \n", "Baker Hughes Co | \n", "BKR | \n", "
81 | \n", "Copart Inc | \n", "CPRT | \n", "
82 | \n", "Constellation Energy Corp | \n", "CEG | \n", "
83 | \n", "Cognizant Technology Solutions Corp | \n", "CTSH | \n", "
84 | \n", "JD.com Inc ADR | \n", "JD | \n", "
85 | \n", "Fastenal Co | \n", "FAST | \n", "
86 | \n", "Verisk Analytics Inc | \n", "VRSK | \n", "
87 | \n", "Seagen Inc | \n", "SGEN | \n", "
88 | \n", "Crowdstrike Holdings Inc | \n", "CRWD | \n", "
89 | \n", "Diamondback Energy Inc | \n", "FANG | \n", "
90 | \n", "Sirius XM Holdings Inc | \n", "SIRI | \n", "
91 | \n", "eBay Inc | \n", "EBAY | \n", "
92 | \n", "Datadog Inc | \n", "DDOG | \n", "
93 | \n", "Warner Bros Discovery Inc | \n", "WBD | \n", "
94 | \n", "ANSYS Inc | \n", "ANSS | \n", "
95 | \n", "Atlassian Corp | \n", "TEAM | \n", "
96 | \n", "Rivian Automotive Inc | \n", "RIVN | \n", "
97 | \n", "Zoom Video Communications Inc | \n", "ZM | \n", "
98 | \n", "Zscaler Inc | \n", "ZS | \n", "
99 | \n", "Align Technology Inc | \n", "ALGN | \n", "
100 | \n", "Lucid Group Inc | \n", "LCID | \n", "