Q1 Import stock prices of NASDAQ Compsite Index, Microsoft and Walmart for the last 30 years.

## # 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 MSFT   1989-11-07 0.538 0.572 0.536 0.562 131542400    0.363
##  2 MSFT   1989-11-08 0.570 0.587 0.569 0.578 106486400    0.373
##  3 MSFT   1989-11-09 0.583 0.587 0.573 0.582 111526400    0.375
##  4 MSFT   1989-11-10 0.583 0.590 0.582 0.587  59168000    0.379
##  5 MSFT   1989-11-13 0.587 0.613 0.582 0.612 178905600    0.395
##  6 MSFT   1989-11-14 0.616 0.620 0.597 0.601  95241600    0.388
##  7 MSFT   1989-11-15 0.602 0.620 0.599 0.615  94492800    0.397
##  8 MSFT   1989-11-16 0.618 0.620 0.599 0.608  68054400    0.392
##  9 MSFT   1989-11-17 0.609 0.613 0.602 0.603  31651200    0.389
## 10 MSFT   1989-11-20 0.602 0.602 0.587 0.601  56937600    0.388
## # … with 22,667 more rows

Q2 Calculate yearly returns.

## # A tibble: 93 x 3
## # Groups:   symbol [3]
##    symbol date       yearly.returns
##    <chr>  <date>              <dbl>
##  1 MSFT   1989-12-29         0.0741
##  2 MSFT   1990-12-31         0.730 
##  3 MSFT   1991-12-31         1.22  
##  4 MSFT   1992-12-31         0.151 
##  5 MSFT   1993-12-31        -0.0556
##  6 MSFT   1994-12-30         0.516 
##  7 MSFT   1995-12-29         0.436 
##  8 MSFT   1996-12-31         0.883 
##  9 MSFT   1997-12-31         0.564 
## 10 MSFT   1998-12-31         1.15  
## # … with 83 more rows

Q3 Which of the three stocks has the highest expected yearly return?

## # A tibble: 3 x 2
##   symbol returns_avg
##   <chr>        <dbl>
## 1 ^IXIC        0.134
## 2 MSFT         0.284
## 3 WMT          0.159

Microsoft has the highest expected yearly return of about 28% whereas NASDAQ’s expected return is 13% and Walmart’s expected return is 16%.

Q4 Calculate standard deviation of the yearly returns. Which of the three stocks is the riskiest in terms of standard deviation?

## # A tibble: 3 x 2
## # Groups:   symbol [3]
##   symbol  sd.1
##   <chr>  <dbl>
## 1 MSFT   0.408
## 2 ^IXIC  0.277
## 3 WMT    0.326

In terms of standard deviation, Microsoft is the riskiest with the highest sd of 0.41, NASDAQ being the least risky with the lowest sd of 0.28, and Walmart in the middle in terms of riskiness at 0.33.

Q5 Is the standard deviation appropriate measure of risk for the three stocks? Calculate skewness and kurtosis, and make your argument using them.

## # A tibble: 3 x 2
## # Groups:   symbol [3]
##   symbol skewness.1
##   <chr>       <dbl>
## 1 MSFT        0.228
## 2 ^IXIC       0.181
## 3 WMT         1.36
## # A tibble: 3 x 2
## # Groups:   symbol [3]
##   symbol kurtosis.1
##   <chr>       <dbl>
## 1 MSFT        0.249
## 2 ^IXIC       0.362
## 3 WMT         1.35

Standard deviation as a measure when considering downside risk, underestimates it. For skewness, all stocks are positive, indicating that they all have extreme positive returns more likely than extreme negative returns. Walmart has a much higher skewness than the others being more on the positive side. In terms of kurtosis, Walmart has the fattest tail and Microsoft has the smallest tail, meaning Microsoft is less risky. Standard deviation wasn’t the best measurement of risk is this case.

Q6 Calculate VaR, a downside risk measure, with a confidence interval of 0.99. Which of the three stocks has the greatest downside risk in terms of VaR?

Hint: This is not to be confused with HistoricalVaR you calculated in class. Look for the right code, using tq_performance_fun_options().

##        [,1]         [,2]         [,3]        
## symbol "MSFT"       "^IXIC"      "WMT"       
## VaR    "-0.5991879" "-0.4842999" "-0.1414682"

Microsoft has the greatest downside risk in terms of VaR because it has the largest loss one could expect within the 99% confidence of -0.599 compared to NASDAQ’s -0.48 amd Walmart’s -0.14.

Q7 Calculate Sharpe ratios with an annualized risk-free rate of 2% and a confidence interval of 0.99. Which of the three stocks would you choose?

Hint: Make your argument based on the three calculated Sharpe Ratios.

## # A tibble: 3 x 4
## # Groups:   symbol [3]
##   symbol `ESSharpe(Rf=2%,p=99… `StdDevSharpe(Rf=2%,p=… `VaRSharpe(Rf=2%,p=…
##   <chr>                  <dbl>                   <dbl>                <dbl>
## 1 MSFT                   0.373                   0.646                0.440
## 2 ^IXIC                  0.196                   0.410                0.235
## 3 WMT                    0.139                   0.428                0.985

I would choose Microsoft because it has higher sharpe ratios for the majority, a higher ES sharpe and SD sharpe than the other two stocks. Walmart only has a higher VaR sharpe.

Q8 Hide the messages and the code, but display results of the code from the webpage.

Hint: Use message, echo and results in the chunk options. Refer to the RMarkdown Reference Guide.

Q9 Display the title and your name correctly at the top of the webpage.

Q10 Use the correct slug.