Hint: Add group_by(symbol) at the end of the code so that calculations below will be done per stock.
## Warning in system("timedatectl", intern = TRUE): running command 'timedatectl'
## had status 1
## # A tibble: 22,677 x 8
## # Groups: symbol [3]
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 WMT 1990-04-24 6.09 6.12 6.03 6.03 2812000 3.64
## 2 WMT 1990-04-25 6.06 6.19 6.06 6.17 3591200 3.72
## 3 WMT 1990-04-26 6.19 6.20 6.09 6.14 4599200 3.70
## 4 WMT 1990-04-27 6.14 6.17 6 6.03 3448800 3.64
## 5 WMT 1990-04-30 6.03 6.22 6 6.20 5861600 3.74
## 6 WMT 1990-05-01 6.25 6.34 6.25 6.28 5718400 3.79
## 7 WMT 1990-05-02 6.28 6.41 6.28 6.41 6201600 3.86
## 8 WMT 1990-05-03 6.41 6.45 6.20 6.22 12880000 3.75
## 9 WMT 1990-05-04 6.28 6.34 6.22 6.33 5635200 3.82
## 10 WMT 1990-05-07 6.33 6.41 6.30 6.41 5196800 3.86
## # … with 22,667 more rows
Hint: Take the adjusted variable from Stocks, and calculate yearly returns using ***tq_transmute().
## # A tibble: 93 x 3
## # Groups: symbol [3]
## symbol date yearly.returns
## <chr> <date> <dbl>
## 1 WMT 1990-12-31 0.278
## 2 WMT 1991-12-31 0.977
## 3 WMT 1992-12-31 0.103
## 4 WMT 1993-12-31 -0.212
## 5 WMT 1994-12-30 -0.138
## 6 WMT 1995-12-29 0.0640
## 7 WMT 1996-12-31 0.0398
## 8 WMT 1997-12-31 0.761
## 9 WMT 1998-12-31 1.09
## 10 WMT 1999-12-31 0.706
## # … with 83 more rows
Hint: Take returns_yearly and pipe it to summarise. Calculate the mean yearly returns.
## # A tibble: 3 x 2
## symbol returns_avg
## <chr> <dbl>
## 1 ^IXIC 0.137
## 2 MSFT 0.275
## 3 WMT 0.160
This would make it so Microsfoft has the highest yearly return.
Hint: Take returns_yearly and pipe it to tidyquant::tq_performance. Use the performance_fun argument to compute sd (standard deviation).
## # A tibble: 3 x 2
## # Groups: symbol [3]
## symbol sd.1
## <chr> <dbl>
## 1 WMT 0.328
## 2 MSFT 0.403
## 3 ^IXIC 0.278
Microsoft has the highest standard deviaton which in turn makes it the most riskiest.
Hint: when the return distribution is not normal, the standard deviation is not an appropriate measure of risk. One can use skewness and kurtosis to detect non-normal returns. Take returns_yearly and pipe it to tidyquant::tq_performance. Use the performance_fun argument to compute skewness. Do the same for kurtosis.
## # A tibble: 3 x 2
## # Groups: symbol [3]
## symbol skewness.1
## <chr> <dbl>
## 1 WMT 1.42
## 2 MSFT 0.272
## 3 ^IXIC 0.179
## # A tibble: 3 x 2
## # Groups: symbol [3]
## symbol kurtosis.1
## <chr> <dbl>
## 1 WMT 1.52
## 2 MSFT 0.424
## 3 ^IXIC 0.304
I don’t beleive standard deviation is a good measure of this because they are all in different markets you are comparing apples to oranges. I think if you were comparing similiar things it would be good to use. There is also a lot more factors to look at too.
Hint: Take returns_yearly and pipe it to tidyquant::tq_performance. Use the performance_fun argument to compute table.DownsideRisk.
## [,1] [,2] [,3]
## symbol "WMT" "MSFT" "^IXIC"
## DownsideDeviation(0%) "0.0829" "0.1448" "0.1244"
## DownsideDeviation(MAR=0.833333333333333%) "0.0866" "0.1475" "0.1279"
## DownsideDeviation(Rf=0%) "0.0829" "0.1448" "0.1244"
## GainDeviation "0.3157" "0.3227" "0.2050"
## HistoricalES(95%) "-0.2471" "-0.5362" "-0.3991"
## HistoricalVaR(95%) "-0.2197" "-0.3317" "-0.3541"
## LossDeviation "0.0885" "0.2388" "0.1599"
## MaximumDrawdown "0.3206" "0.6285" "0.6718"
## ModifiedES(95%) "-0.5226" "-0.4907" "-0.4068"
## ModifiedVaR(95%) "-0.2183" "-0.3419" "-0.2974"
## SemiDeviation "0.1707" "0.2663" "0.1891"
Microsoft’s downside risk is greater. It has more uneasy on yearly returns below the mean than Walmart and NASDAQ, the largest loss one would expect with 95% confidence is larger for NASDAQ and Walmart, but with the largest loss could come the largest profit if your a gambling man.
Hint: Make your argument based on the three Sharpe Ratios.
## # A tibble: 3 x 4
## # Groups: symbol [3]
## symbol `ESSharpe(Rf=2%,p=95%… `StdDevSharpe(Rf=2%,p=95… `VaRSharpe(Rf=2%,p=95…
## <chr> <dbl> <dbl> <dbl>
## 1 WMT 0.267 0.426 0.639
## 2 MSFT 0.519 0.633 0.745
## 3 ^IXIC 0.287 0.420 0.392
For me I could go more risky at my point in life living at home no bills no kids so I would go with microsoft but some people like more stable stocks.
Hint: Make your argument based on the three Sharpe Ratios.
## # A tibble: 3 x 4
## # Groups: symbol [3]
## symbol `ESSharpe(Rf=2%,p=99%… `StdDevSharpe(Rf=2%,p=99… `VaRSharpe(Rf=2%,p=99…
## <chr> <dbl> <dbl> <dbl>
## 1 WMT 0.140 0.426 1.13
## 2 MSFT 0.364 0.633 0.428
## 3 ^IXIC 0.205 0.420 0.243
It changed some of microsofts standerd deviation and other components but for me I like microsoft and beleive I would stay with them.
Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.