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

Hint: Add group_by(symbol) at the end of the code so that calculations below will be done per stock.

## # A tibble: 22,671 x 8
## # Groups:   symbol [3]
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 ^IXIC  1990-04-30  418.  420.  417   420. 105790000     420.
##  2 ^IXIC  1990-05-01  422   422.  421.  422. 124130000     422.
##  3 ^IXIC  1990-05-02  423.  424.  422.  424. 143260000     424.
##  4 ^IXIC  1990-05-03  425   427.  424.  425. 160850000     425.
##  5 ^IXIC  1990-05-04  427.  429.  426.  429. 136810000     429.
##  6 ^IXIC  1990-05-07  429.  432.  429.  431. 122690000     431.
##  7 ^IXIC  1990-05-08  431.  432.  431.  432. 133840000     432.
##  8 ^IXIC  1990-05-09  431.  432.  430.  431. 146630000     431.
##  9 ^IXIC  1990-05-10  432.  434.  431.  433. 142490000     433.
## 10 ^IXIC  1990-05-11  434.  438.  434.  438. 167560000     438.
## # … with 22,661 more rows

Q2 Calculate yearly returns.

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 ^IXIC  1990-12-31        -0.110 
##  2 ^IXIC  1991-12-31         0.569 
##  3 ^IXIC  1992-12-31         0.155 
##  4 ^IXIC  1993-12-31         0.147 
##  5 ^IXIC  1994-12-30        -0.0320
##  6 ^IXIC  1995-12-29         0.399 
##  7 ^IXIC  1996-12-31         0.227 
##  8 ^IXIC  1997-12-31         0.216 
##  9 ^IXIC  1998-12-31         0.396 
## 10 ^IXIC  1999-12-31         0.856 
## # … with 83 more rows

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

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.158

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

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 ^IXIC  0.277
## 2 MSFT   0.402
## 3 WMT    0.327

Microsoft is the riskiest because its standard deviation is 0.402.

Q5 Is the standard deviation appropriate measure of risk for the three stocks? Calculate skewness and kurtosis, and discuss them in your answer.

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 ^IXIC       0.174
## 2 MSFT        0.269
## 3 WMT         1.43
## # A tibble: 3 x 2
## # Groups:   symbol [3]
##   symbol kurtosis.1
##   <chr>       <dbl>
## 1 ^IXIC       0.323
## 2 MSFT        0.430
## 3 WMT         1.56

Downside risk is underestimated when you use standard deviation.

Q6 Which of the three stocks poses greater downside risk? Calculate HistoricalES(95%), HistoricalVaR(95%), and SemiDeviation, and discuss them in your answer.

Hint: Take returns_yearly and pipe it to tidyquant::tq_performance. Use the performance_fun argument to compute table.DownsideRisk.

##        [,1]         [,2]         [,3]        
## symbol "^IXIC"      "MSFT"       "WMT"       
## VaR    "-0.4800674" "-0.5959328" "-0.1186033"

Microsoft has the greatest downside risk at 0.595.

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

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

##                           [,1]        [,2]        [,3]       
## symbol                    "^IXIC"     "MSFT"      "WMT"      
## ESSharpe(Rf=2%,p=99%)     "0.2049757" "0.3633767" "0.1384021"
## StdDevSharpe(Rf=2%,p=99%) "0.4231380" "0.6349531" "0.4229101"
## VaRSharpe(Rf=2%,p=99%)    "0.2445546" "0.4286016" "1.1669326"

Q7.a Repeat Q7 but at a confidence interval of 0.99. Does it change your answer in Q7?

Hint: Make your argument based on the three Sharpe Ratios. I would choose Microsoft as it has the highest expected return.

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.