Volatility measures the uncertainty of the return of an asset when it is considered taken in isolation. When this asset belongs to a portfolio, however, what matters is its contribution to the portfolio risk.
The effect of the small changes in a part of the portfolio to the portfolio VaR is measured by marginal value at risk (MVaR).
The contribution of a position or a sub portfolio to the total VaR is measured by value at risk contribution (VaRC).
VaRC is the additive decomposition of the total portfolio VaR and is calculated and reported both at portfolio level as well as single deal level.
This small task consists in finding the contributions to the VaR of the five components of a portfolio built whit the FAANG, which are the most important companies in the Standard & Poor’s 500 Index (S&P 500):
Several R packages for Financial Analytics are used, this analysis is mainly supported by the PerformanceAnalytics package. Of course, quantmod is used to download financial data from yahoo! Finance. Some values are computed with fPortfolio package, which is maintained by the Rmetrics Foundation with HQ in Zurich, Switzerland.
Yahoo! Finance is used to download OHLC (Open-High-Low-Close) data for the last five years of trading of the mentioned companies (indeed, yahoo! Finance provides six columns, being the last two the Volume and the Adjusted close price. The last is the one that is used for this analysis.
Next table shows the first and last dates of the adjusted close prices for each of the five components:
## FB AAPL AMZN NFLX GOOG
## 2015-11-17 105.13 26.11879 643.30 117.10 725.30
## 2015-11-18 107.77 26.94584 663.54 120.63 740.00
## 2015-11-19 106.26 27.28815 661.27 120.22 738.41
## 2015-11-20 107.32 27.40762 668.45 123.84 756.60
## 2015-11-23 106.95 27.05152 678.99 125.03 755.98
## 2015-11-24 105.74 27.31112 671.15 123.31 748.28
## FB AAPL AMZN NFLX GOOG
## 2020-11-12 275.08 119.21 3110.28 486.77 1749.84
## 2020-11-13 276.95 119.26 3128.81 482.84 1777.02
## 2020-11-16 278.96 120.30 3131.06 479.10 1781.38
## 2020-11-17 275.00 119.39 3135.66 480.63 1770.15
## 2020-11-18 271.97 118.03 3105.46 481.79 1746.78
## 2020-11-19 272.94 118.64 3117.02 484.67 1763.92
Next, the returns are computed with the ROC() command, the vector is transformed to a timeSeries data type which is the one proposed by Rmetrics. The results for the first and last dates of the vector are shown in the table bellow:
## GMT
## FB AAPL AMZN NFLX GOOG
## 2015-11-18 0.025111767 0.031665060 0.031462755 0.030145167 0.0202674924
## 2015-11-19 -0.014011274 0.012703556 -0.003420982 -0.003398790 -0.0021486851
## 2015-11-20 0.009975513 0.004377981 0.010857882 0.030111420 0.0246340159
## 2015-11-23 -0.003447661 -0.012992702 0.015767788 0.009609198 -0.0008194502
## 2015-11-24 -0.011313689 0.009596726 -0.011546512 -0.013756707 -0.0101853901
## 2015-11-25 -0.003120806 -0.007150127 0.006243020 0.006893245 -0.0001737384
## GMT
## FB AAPL AMZN NFLX GOOG
## 2020-11-12 -0.005063744 -0.0023432840 -0.0086408973 -0.008130290 -0.001637461
## 2020-11-13 0.006798114 0.0004194531 0.0059576726 -0.008073614 0.015532880
## 2020-11-16 0.007257552 0.0087204510 0.0007191232 -0.007745816 0.002453537
## 2020-11-17 -0.014195552 -0.0075644553 0.0014691040 0.003193486 -0.006304091
## 2020-11-18 -0.011018178 -0.0113912389 -0.0096311309 0.002413507 -0.013202268
## 2020-11-19 0.003566574 0.0051681776 0.0037224949 0.005977716 0.009812349
For Financial analytics, specifically for Portfolio Analytics, it is important to obtain the Variance-Covariance matrix and the Correlation matrix, in R this is quite easy once we have computed the returns of all assets in the portfolio.
Both matrices are shown below.
## Variance-Covariance Matrix
## FB AAPL AMZN NFLX GOOG
## FB 1.0000000 0.5823726 0.6279566 0.4700959 0.6957429
## AAPL 0.5823726 1.0000000 0.5949537 0.4584578 0.6566849
## AMZN 0.6279566 0.5949537 1.0000000 0.5843226 0.6711339
## NFLX 0.4700959 0.4584578 0.5843226 1.0000000 0.5179767
## GOOG 0.6957429 0.6566849 0.6711339 0.5179767 1.0000000
##
## Correlation Matrix
## FB AAPL AMZN NFLX GOOG
## FB 0.0004301419 0.0002290865 0.0002502398 0.0002497967 0.0002401967
## AAPL 0.0002290865 0.0003597374 0.0002168188 0.0002227852 0.0002073300
## AMZN 0.0002502398 0.0002168188 0.0003691831 0.0002876523 0.0002146557
## NFLX 0.0002497967 0.0002227852 0.0002876523 0.0006564302 0.0002209108
## GOOG 0.0002401967 0.0002073300 0.0002146557 0.0002209108 0.0002770925
With the returns data, the efficient frontier is computed and plotted with the aid of the portfolioFrontier() command.
Several options for plotting the efficient frontier are available, for example, the next plot shows a simple portfolio frontier:
The next plot shows all options included in the portfolioFrontier() command as follows:
Next plot shows the weights and the assets involved in every zone of the efficient frontier.
By means of minvariancePortfolio() command, it is possible to compute the portfolio with the FAANG assets that represents the minimum overall risk.
##
## Title:
## MV Minimum Variance Portfolio
## Estimator: covEstimator
## Solver: solveRquadprog
## Optimize: minRisk
## Constraints: LongOnly
##
## Portfolio Weights:
## FB AAPL AMZN NFLX GOOG
## 0.0356 0.2372 0.1809 0.0274 0.5189
##
## Covariance Risk Budgets:
## FB AAPL AMZN NFLX GOOG
## 0.0356 0.2372 0.1809 0.0274 0.5189
##
## Target Returns and Risks:
## mean Cov CVaR VaR
## 0.0011 0.0157 0.0390 0.0254
##
## Description:
## Fri Nov 20 20:46:21 2020 by user: carlos
## Weights of the Minimum Variance Prtfolio
## FB AAPL AMZN NFLX GOOG
## 0.03555634 0.23720207 0.18094363 0.02740758 0.51889038
The next plot shows the optimal weights of each asset that must be part of the portfolio with the minimum risk:
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.