This is a portfolio optimization dashboard that aims at finding the optimal set of portfolios given a set of inputs— stock returns, holding period, objective functions, constraints, and rebalancing frequency (back-testing). We will limit our portfolio to equity positions only with exposure to all of the GICS sectors— energy, materials, industrials, utilities, healthcare, financials, consumer discretionary, consumer staples, information technology, communication services, and real estate. We begin our analysis by loading price series from Yahoo Finance and computing monthly returns for individual stocks. Take a glimpse of the first and last three months of stock returns:
| XOM | SHW | JPM | AEP | UNH | AMZN | AAPL | KO | GOOGL | GE | SBUX | PFE | MSFT | BA | AMT | DD | JNJ | TSN | CVX | SLG | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2011-01-31 | 0.1034 | 0.0117 | 0.0606 | -0.0083 | 0.1368 | -0.0576 | 0.0520 | -0.0444 | 0.0108 | 0.1011 | -0.0187 | 0.0405 | -0.0064 | 0.0647 | -0.0151 | 0.0393 | -0.0336 | -0.0447 | 0.0403 | 0.0778 |
| 2011-02-28 | 0.0657 | -0.0266 | 0.0389 | 0.0158 | 0.0373 | 0.0215 | 0.0409 | 0.0170 | 0.0217 | 0.0459 | 0.0502 | 0.0671 | -0.0358 | 0.0424 | 0.0610 | 0.0474 | 0.0372 | 0.1350 | 0.1011 | 0.0408 |
| 2011-03-31 | -0.0164 | 0.0228 | -0.0126 | -0.0179 | 0.0646 | 0.0395 | -0.0133 | 0.0454 | -0.0434 | -0.0416 | 0.1204 | 0.0556 | -0.0448 | 0.0267 | -0.0397 | 0.0200 | -0.0356 | 0.0301 | 0.0360 | -0.0056 |
| 2021-05-31 | 0.0346 | 0.0373 | 0.0678 | -0.0223 | 0.0329 | -0.0705 | -0.0505 | 0.0243 | 0.0014 | 0.0716 | -0.0014 | 0.0119 | -0.0076 | 0.0542 | 0.0027 | 0.1010 | 0.0466 | 0.0322 | 0.0193 | 0.0746 |
| 2021-06-30 | 0.0807 | -0.0391 | -0.0530 | -0.0164 | -0.0243 | 0.0674 | 0.0991 | -0.0140 | 0.0360 | -0.0419 | -0.0182 | 0.0111 | 0.0850 | -0.0302 | 0.0625 | -0.0849 | -0.0266 | -0.0722 | 0.0092 | 0.0136 |
| 2021-07-31 | -0.0873 | 0.0682 | -0.0186 | 0.0417 | 0.0294 | -0.0327 | 0.0650 | 0.0540 | 0.1035 | -0.0379 | 0.0860 | 0.1031 | 0.0517 | -0.0546 | 0.0469 | -0.0266 | 0.0453 | -0.0312 | -0.0280 | -0.0655 |
To compute some common portfolio performance metrics, we need to proxy for the rate of return of a theoretically risk-free asset over the same investment horizon as our portfolio. One choice of a relatively risk-free investment is the US Treasury bond, which can be retrieved from Federal Reserve Economic Data (FRED) database. To match the risk free rate to our portfolio returns, we will use the 1-Month Treasury Constant Maturity Rate series over the period from 2011 to 2021. This investment usually has small inflationary risk as well as default risk, making it an acceptable proxy for the risk free rate. Below are the first and last few months of data from the series:
| symbol | date | rate | |
|---|---|---|---|
| 1 | GS1M | 2011-01-01 | 0.0014 |
| 2 | GS1M | 2011-02-01 | 0.0011 |
| 3 | GS1M | 2011-03-01 | 0.0006 |
| 125 | GS1M | 2021-05-01 | 0.0001 |
| 126 | GS1M | 2021-06-01 | 0.0003 |
| 127 | GS1M | 2021-07-01 | 0.0005 |
From the series above, we obtain the monthly risk-free rate of \(0.09\%\) (the median rate of return over the same investment horizon as our portfolio). The median value is chosen over the mean value since the univariate distribution of the 1-Month Treasury Constant Maturity Rate series is positively skewed.
The portfolio optimization problem, therefore, given a universe of assets and their characteristics, deals with a method to spread the capital between them in a way that maximizes the return of the portfolio per unit of risk taken. There is no unique solution for this problem, but a set of solutions, which together define what is called an efficient frontier— the portfolios whose returns cannot be improved without increasing risk, or the portfolios where risk cannot be reduced without reducing returns as well.
The Markowitz model for the solution of the portfolio optimization problem has a twin objective of maximizing return and minimizing risk, built on the Mean-Variance framework of asset returns and holding the basic constraints, which reduces to the following:
Minimize Risk given Levels of Return
\[\begin{align*} \min_{\vec{w}} \hspace{5mm} \sqrt{\vec{w}^{T} \hat{\Sigma} \vec{w}} \end{align*}\]
subject to
\[\begin{align*} &\vec{w}^{T} \hat{\mu}=\bar{r}_{P} \\ &\vec{w}^{T} \vec{1} = 1 \hspace{5mm} (\text{Full investment}) \\ &\vec{0} \le \vec{w} \le \vec{1} \hspace{5mm} (\text{Long only}) \end{align*}\]
Maximize Return given Levels of Risk
\[\begin{align*} \max _{\vec{w}} \hspace{5mm} \vec{w}^{T} \hat{\mu} \end{align*}\]
subject to
\[\begin{align*} &\vec{w}^{T} \hat{\Sigma} \vec{w}=\bar{\sigma}_{P} \\ &\vec{w}^{T} \vec{1} = 1 \hspace{5mm} (\text{Full investment}) \\ &\vec{0} \le \vec{w} \le \vec{1} \hspace{5mm} (\text{Long only}) \end{align*}\]
In absence of other constraints, the above model is loosely referred to as the “unconstrained” portfolio optimization model. Solving the mathematical model yields a set of optimal weights representing a set of optimal portfolios. The solution set to these two problems is a hyperbola that depicts the efficient frontier in the \(\mu-\sigma\) -diagram. We can plot the efficient frontier to visualize this optimization results.
We have now obtained a set of 200 efficient portfolios that is optimized to achieve the Markowitz twin objectives and is subject to the leverage (full investment) and box (long only) constraints. For a comparison, we may wish to compute some performance metrics for each of these efficient portfolios. For the risk free rate, we will use the 1-month Treasury Constant Maturity rate. For other performance metrics, we will also employ the monthly returns of the SPDR S&P 500 Trust ETF as the benchmark. Examine some performance metrics for a small subset of 10 efficient portfolios:
| portfolio | ActivePremium | Alpha | AnnualizedAlpha | Beta | Beta- | Beta+ | Correlation | Correlationp-value | InformationRatio | R-squared | TrackingError | TreynorRatio | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 0.0463 | 0.0077 | 0.0967 | 0.5881 | 0.5646 | 0.5915 | 0.7517 | 0 | 0.5286 | 0.5651 | 0.0875 | 0.3077 |
| 2 | 2 | 0.0469 | 0.0078 | 0.0972 | 0.5886 | 0.5647 | 0.5928 | 0.7522 | 0 | 0.5359 | 0.5657 | 0.0875 | 0.3085 |
| 3 | 3 | 0.0475 | 0.0078 | 0.0977 | 0.5891 | 0.5648 | 0.5940 | 0.7526 | 0 | 0.5431 | 0.5663 | 0.0874 | 0.3092 |
| 4 | 4 | 0.0481 | 0.0078 | 0.0982 | 0.5897 | 0.5649 | 0.5953 | 0.7529 | 0 | 0.5502 | 0.5669 | 0.0873 | 0.3099 |
| 5 | 5 | 0.0487 | 0.0079 | 0.0987 | 0.5902 | 0.5650 | 0.5965 | 0.7533 | 0 | 0.5574 | 0.5675 | 0.0873 | 0.3106 |
| 196 | 196 | 0.1496 | 0.0114 | 0.1460 | 0.9595 | 0.7161 | 1.0634 | 0.7082 | 0 | 1.1786 | 0.5016 | 0.1269 | 0.2952 |
| 197 | 197 | 0.1500 | 0.0114 | 0.1461 | 0.9631 | 0.7177 | 1.0681 | 0.7058 | 0 | 1.1698 | 0.4982 | 0.1283 | 0.2946 |
| 198 | 198 | 0.1505 | 0.0114 | 0.1462 | 0.9667 | 0.7192 | 1.0728 | 0.7034 | 0 | 1.1610 | 0.4947 | 0.1296 | 0.2939 |
| 199 | 199 | 0.1509 | 0.0114 | 0.1463 | 0.9703 | 0.7207 | 1.0775 | 0.7009 | 0 | 1.1521 | 0.4912 | 0.1310 | 0.2933 |
| 200 | 200 | 0.1514 | 0.0114 | 0.1464 | 0.9739 | 0.7221 | 1.0822 | 0.6984 | 0 | 1.1433 | 0.4877 | 0.1324 | 0.2927 |
Note that a portfolio with a beta greater than one moves along with the market. Further, a beta lower than one moves less than the average; in other words, the portfolio is notionally less volatile than the market.
If we wish to select a set of efficient portfolios based on a specific performance metric, for instance, the Cornish-Fisher VaR Sharpe Ratio, then the following table displays the 5 best efficient portfolios. The other types of Sharpe Ratio calculations are also included; note that these metrics differ in the sense that different measures of risk are employed in the denominators:
| portfolio | ESSharpe(Rf=0.1%,p=99%) | StdDevSharpe(Rf=0.1%,p=99%) | VaRSharpe(Rf=0.1%,p=99%) |
|---|---|---|---|
| 102 | 0.1889 | 0.5374 | 0.2749 |
| 101 | 0.1889 | 0.5378 | 0.2749 |
| 103 | 0.1889 | 0.5370 | 0.2749 |
| 104 | 0.1889 | 0.5366 | 0.2749 |
| 100 | 0.1889 | 0.5382 | 0.2749 |
The best 5 efficient portfolios based on the Information Ratio:
| portfolio | AnnualisedTrackingError | InformationRatio | TrackingError |
|---|---|---|---|
| 160 | 0.0903 | 1.4624 | 0.0261 |
| 161 | 0.0906 | 1.4624 | 0.0262 |
| 162 | 0.0910 | 1.4623 | 0.0263 |
| 159 | 0.0900 | 1.4621 | 0.0260 |
| 163 | 0.0913 | 1.4620 | 0.0264 |
To better understand the risk of the investment, we compute higher moments of the distribution of the monthly returns for each efficient portfolio. Next, we rank the efficient portfolios based on the two measure— skewness and excess kurtosis. In particular, we aim for skewness to be as close to zero as possible (relatively symmetric distribution) and the distribution to be less leptokurtic, i.e., small positive excess kurtosis. In the context of portfolio returns, leptokurtic distributions have higher likelihood of extreme values— positive and negative returns alike— compared to the normal distribution and may be undesirable to risk-averse investors. We will impose a tolerance band of \(\pm0.1\) around the value of zero for skewness. From this subset of efficient portfolios, we select portfolios with the lowest kurtosis measures. In addition, we include measures of central tendency— the mean and the median and the standard deviation of the returns distributions. Examine the results:
| portfolio | ArithmeticMean | Median | Stdev | Skewness | Kurtosis |
|---|---|---|---|---|---|
| 169 | 0.0219 | 0.0250 | 0.0431 | 0.0960 | 1.0274 |
| 170 | 0.0220 | 0.0252 | 0.0433 | 0.0958 | 1.0310 |
| 168 | 0.0219 | 0.0251 | 0.0429 | 0.0982 | 1.0335 |
| 171 | 0.0220 | 0.0249 | 0.0436 | 0.0968 | 1.0399 |
| 172 | 0.0221 | 0.0251 | 0.0438 | 0.0977 | 1.0470 |
We compare the efficient portfolios based on the modified Cornish-Fisher VaR, which takes into account the higher moments of the returns distribution— skewness and kurtosis. The other downside measures are tabulated to provide additional measures of downside risk in the case when a tie-breaker is needed. We use a minimally monthly acceptable return (MAR) of \(0.5\%\) and a monthly risk-free rate of \(0.09%\). Examine the 5 efficient portfolios that have the smallest downside-risk according to the Modified Cornish-Fisher VaR:
| portfolio | ModifiedVaR(99%) | DownsideDeviation(0%) | DownsideDeviation(MAR=6%) | DownsideDeviation(Rf=1.08%) | GainDeviation | HistoricalES(99%) | HistoricalVaR(99%) | LossDeviation | MaximumDrawdown | ModifiedES(99%) | SemiDeviation |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 34 | -0.0634 | 0.0139 | 0.016 | 0.0143 | 0.0209 | -0.0745 | -0.0679 | 0.0184 | 0.1254 | -0.0877 | 0.0217 |
| 35 | -0.0634 | 0.0139 | 0.016 | 0.0143 | 0.0211 | -0.0745 | -0.0678 | 0.0184 | 0.1252 | -0.0878 | 0.0217 |
| 36 | -0.0634 | 0.0139 | 0.016 | 0.0143 | 0.0211 | -0.0745 | -0.0677 | 0.0184 | 0.1251 | -0.0878 | 0.0217 |
| 37 | -0.0634 | 0.0139 | 0.016 | 0.0143 | 0.0212 | -0.0744 | -0.0676 | 0.0184 | 0.1249 | -0.0879 | 0.0217 |
| 38 | -0.0634 | 0.0139 | 0.016 | 0.0143 | 0.0212 | -0.0744 | -0.0676 | 0.0185 | 0.1248 | -0.0880 | 0.0217 |
The modified VaR is interpreted as saying that, with 99% confidence, we expect that our worst monthly portfolio return will not exceed the value of the VaR. In other words, if we invest \(\$100\), we are 99% confident that our worst monthly loss will not exceed (\(\$100\) \(\times\) -VaR\(\%\)) dollars. Note that this is a probabilistic estimate based on the distribution of monthly returns and must not be taken with 100% certainty.
We can visualize the monthly returns of a portfolio over the investment horizon using a bar plot. For this visualization, we select the efficient portfolio with the smallest downside risk based on the Modified Cornish-Fisher VaR. As can be seen in the plot above, the efficient portfolio has mostly positive monthly returns over the investment horizon. Coupled with the fact that it also has small downside risk, this efficient portfolio may be considered optimal from the perspective of a risk-averse investor.
We also wish to how an initial investment of $10,000 would grow over time. For this visualization, we select four efficient portfolios— max-expected-return portfolio, max-modified-Sharpe_Ratio portfolio, min-downside-risk portfolio, and min-variance portfolio.
Examine some performance metrics of these four efficient portfolios:
| Portfolio | ArithmeticMean | Median | Stdev | Skewness | Kurtosis | VaRSharpe(Rf=0.1%,p=99%) | InformationRatio | TreynorRatio | ActivePremium | Beta |
|---|---|---|---|---|---|---|---|---|---|---|
| Minimum Variance | 0.0153 | 0.0155 | 0.0299 | -0.1433 | 1.0657 | 0.2235 | 0.5286 | 0.3077 | 0.0463 | 0.5881 |
| Minimum Downside Risk | 0.0168 | 0.0175 | 0.0306 | -0.0394 | 1.1793 | 0.2516 | 0.7962 | 0.3309 | 0.0681 | 0.6122 |
| Maximal Sharpe Ratio | 0.0186 | 0.0188 | 0.0326 | 0.0743 | 1.2583 | 0.2732 | 1.1212 | 0.3372 | 0.0920 | 0.6708 |
| Maximal Expected Return | 0.0234 | 0.0278 | 0.0534 | 0.1235 | 0.8130 | 0.2138 | 1.1433 | 0.2927 | 0.1514 | 0.9739 |
Although the maximal expected return portfolio shows the strongest growth over time, it is also the most volatile as it has the highest standard deviation among the four selected efficient portfolios. This underscore an important idea in portfolio optimization— that there is no one single optimal portfolio but a set of optimal portfolios. The criteria for optimality will be different depending on the performance metrics used in the analysis.
For instance, the minimum variance portfolio is negatively skewed, while the other portfolios are positively skewed. Still, all four portfolios have skewness that are within the tolerance band of \(\pm0.5\), indicating that their returns distributions are all relatively symmetric. In other words, we can expect most of the densities to be concentrated around the mean returns of these distributions.
The maximal Sharpe Ratio portfolio has the highest average return earned in excess of the risk free rate per unit of volatility. It also ranks first according to the information ratio, which relates the degree to which the portfolio has beaten the benchmark to the consistency with which it has beaten the benchmark. However, it only ranks third based on the Treynor Ratio, which uses the portfolio beta as the risk measure in the denominator. So which efficient portfolio is optimal in terms of risk-adjusted returns? In this example, we will choose the modified Sharpe Ratio and the information ratio over the Treynor Ratio, concluding that the maximal Sharpe Ratio is the optimal portfolio if the performance metric used for comparison is risk-adjusted returns.
The portfolio beta (\(\beta\)) or beta coefficient, also referred to as financial elasticity, is a measure of volatility or systematic risk of a portfolio, in comparison to that of the market as a whole. In a sense, \(\beta\) measures the risk of an investment that cannot be dispensed with by means of diversification. All four efficient portfolios have \(\beta > 0\), indicating that the portfolio returns tend to move in the same direction as the market. The maximal expected return portfolio has a \(\beta\) greater than one, and so it tends to move more than the average (this portfolio is notionally more volatile than the market). The \(\beta\) of the other efficient portfolios have magnitudes that are less than one, which may suggest less volatility than the market. The statistical definition of the beta coefficient is that it is the slope of the estimated regression line obtained by regressing individual portfolio returns on the market returns (the SPDR S&P 500 Trust ETF).