Disclaimer: The content of this RMarkdown note came from a course (chapter 2) called Introduction to Portfolio Analysis in R in datacamp.
A risk-averse investor would prefer an investment that has the highest average return with the lowest volatility.
Non-normality of the return distribution
Two metrics key to understanding the distribution of non-normal returns:
Skewness
Kurtosis
# Load packages
library(PerformanceAnalytics)
library(quantmod)
library(xts)
data.GSPC <- getSymbols("MSFT", from = "1985-12-31", to = "2016-08-01", auto.assign = FALSE)
sp500_monthly <- to.monthly(data.GSPC, indexAt = "startof")
# to.monthly documentation https://www.rdocumentation.org/packages/xts/versions/0.10-0/topics/to.period
sp500_monthly <- sp500_monthly[, "data.GSPC.Adjusted"]
head(sp500_monthly)
## data.GSPC.Adjusted
## 1986-03-13 0.063419
## 1986-04-01 0.074373
## 1986-05-01 0.080715
## 1986-06-02 0.070914
## 1986-07-01 0.065725
## 1986-08-01 0.065725
# Calcuate net returns
sp500_monthly <- Return.calculate(sp500_monthly)
sp500_monthly <- sp500_monthly[-1, ]
colnames(sp500_monthly) <- "sp500"
head(sp500_monthly)
## sp500
## 1986-04-01 0.172724262
## 1986-05-01 0.085272881
## 1986-06-02 -0.121427244
## 1986-07-01 -0.073173139
## 1986-08-01 0.000000000
## 1986-09-02 -0.008763789
# Compute the skewness
skewness(sp500_monthly)
## [1] 0.67842
# Compute the excess kurtois
kurtosis(sp500_monthly)
## [1] 2.413123
Interpreation
When the return distribution is asymmetric (skewed), investors use additional risk measures that focus on describing the potential losses.
# Calculate the SemiDeviation
SemiDeviation(sp500_monthly)
## sp500
## Semi-Deviation 0.06663768
# Calculate the value at risk
VaR(sp500_monthly, p = 0.025)
## sp500
## VaR -0.1534668
VaR(sp500_monthly, p = 0.05)
## sp500
## VaR -0.1185257
# Calculate the expected shortfall
ES(sp500_monthly, p = 0.025)
## sp500
## ES -0.1534668
ES(sp500_monthly, p = 0.05)
## sp500
## ES -0.1431922
Interpreation
The volatility, semi-deviation, value-at-risk, and expected shortfall are all measures that describe risk over 1 period. These metrics do not do a great job at describing the worst case risk of buying at a peak, and selling at a trough. This sort of risk can be quantified by analyzing the portfolio’s drawdowns, or peak-to-trough decline in cumulative returns.
The function table.Drawdowns()
in PerformanceAnalytics reports the five largest drawdown episodes over a sample period. The package also has another function chart.Drawdown()
to visualize the evolution of the drawdowns from each peak over time.
# Table of drawdowns
table.Drawdowns(sp500_monthly)
## From Trough To Depth Length To Trough Recovery
## 1 2000-01-03 2009-02-02 2014-07-01 -0.6670 175 110 65
## 2 1987-10-01 1987-11-02 1988-06-01 -0.3245 9 2 7
## 3 1988-07-01 1988-11-01 1989-09-01 -0.2948 15 5 10
## 4 1992-12-01 1993-07-01 1994-05-02 -0.2054 18 8 10
## 5 1986-06-02 1986-09-02 1986-10-01 -0.1929 5 4 1
# Plot of drawdowns
chart.Drawdown(sp500_monthly)
Interpreation
Compared to the S&P 500, MSFT had both a postiive skewness and positive kurtosis, making a large positive return more likely than a large negative return, whereas S&P 500 had a negative skewness and a positive kurtosis, which means a large negative return is more likely than a large postive return.
However, Microsoft appears to present greater downside risk than S&P 500. For example, monthly returns are more volatile below the mean for Microsoft (semideviation of 0.067) than S&P 500 (semideviation of 0.033); the largest loss one could expect with 95% confidence is larger for Microsoft (VaR of -0.119 at 5%) than S&P 500 (VaR of -0.072 at 5%); and the average of the 5% most negative monthly returns is larger for Microsoft (ES of -0.143 at 5%) than S&P 500 (ES of -0.118 at 5%).
In addition, drawdowns show that the worst cumulative loss would have been much more severe if you had invested in Microsoft than in S&P 500 during the period of December 31, 1985 – August 1, 2016. For Microsoft, the peak to trough period would have been much longer; the size of loss would have been greater; and the longer it would have taken to return to the previous peak.