{ "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. \n", "\n" ] }, { "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", "