Suppose that you consider investing in two stocks: S&P500 and NASDAQ. As a prudent investor, you analyze the historical performance of the stocks for the past 20 years.

Q1 Import stock prices of Dow Jones Industrial Avarege and NASDAQ Compsite Index for the last 20 years.

## # A tibble: 10,064 x 8
## # Groups:   symbol [2]
##    symbol date        open  high   low close     volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>      <dbl>    <dbl>
##  1 ^GSPC  1999-11-01 1363. 1367. 1354. 1354.  861000000    1354.
##  2 ^GSPC  1999-11-02 1354. 1369. 1346. 1348.  904500000    1348.
##  3 ^GSPC  1999-11-03 1348. 1360. 1348. 1355.  914400000    1355.
##  4 ^GSPC  1999-11-04 1355. 1369. 1355. 1363.  981700000    1363.
##  5 ^GSPC  1999-11-05 1363. 1387. 1363. 1370. 1007300000    1370.
##  6 ^GSPC  1999-11-08 1370. 1381. 1366. 1377.  806800000    1377.
##  7 ^GSPC  1999-11-09 1377. 1384. 1361. 1365.  854300000    1365.
##  8 ^GSPC  1999-11-10 1365. 1379. 1360. 1373.  984700000    1373.
##  9 ^GSPC  1999-11-11 1373. 1382. 1372. 1381.  891300000    1381.
## 10 ^GSPC  1999-11-12 1381. 1396. 1369. 1396.  900200000    1396.
## # … with 10,054 more rows

Q2 Calculate monthly returns, and save the result under returns_monthly.

## # A tibble: 480 x 3
## # Groups:   symbol [2]
##    symbol date       monthly.returns
##    <chr>  <date>               <dbl>
##  1 ^GSPC  1999-11-30          0.0257
##  2 ^GSPC  1999-12-31          0.0578
##  3 ^GSPC  2000-01-31         -0.0509
##  4 ^GSPC  2000-02-29         -0.0201
##  5 ^GSPC  2000-03-31          0.0967
##  6 ^GSPC  2000-04-28         -0.0308
##  7 ^GSPC  2000-05-31         -0.0219
##  8 ^GSPC  2000-06-30          0.0239
##  9 ^GSPC  2000-07-31         -0.0163
## 10 ^GSPC  2000-08-31          0.0607
## # … with 470 more rows

Q3 Which of the two stocks have higher expected monthly return?

## # A tibble: 2 x 2
##   symbol returns_avg
##   <chr>        <dbl>
## 1 ^GSPC      0.00427
## 2 ^IXIC      0.00643

NASDAQ had a higher monthly return at 0.64% compared to S&P 500 monthly return at 0.42%.

Q4 Which of the two stocks is riskier?

## # A tibble: 2 x 2
## # Groups:   symbol [2]
##   symbol   sd.1
##   <chr>   <dbl>
## 1 ^GSPC  0.0419
## 2 ^IXIC  0.0649

NASDAQ is a riskier stock because it has a higher standard deviation than S&P 500, sd of 0.065 compared to 0.042.

Q5 Are the returns normally distributed?

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_monthly and pipe it to tidyquant::tq_performance. Use the performance_fun argument to compute skewness. Do the same for kurtosis.

Both S&P500 and NASDAQ have a negative skewness and a positive kurtusis, indicating a large negative return is likelier than a large positive return.

## # A tibble: 2 x 2
## # Groups:   symbol [2]
##   symbol skewness.1
##   <chr>       <dbl>
## 1 ^GSPC      -0.595
## 2 ^IXIC      -0.365
## # A tibble: 2 x 2
## # Groups:   symbol [2]
##   symbol kurtosis.1
##   <chr>       <dbl>
## 1 ^GSPC        1.08
## 2 ^IXIC        1.55

Q6 Calculate the downside risk measures by revising the code below. Which of the two stocks has greater downside risks? Discuss HistoricalES(95%), HistoricalVaR(95%), and SemiDeviation.

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

##                            [,1]      [,2]     
## symbol                     "^GSPC"   "^IXIC"  
## DownsideDeviation(0%)      "0.0299"  "0.0450" 
## DownsideDeviation(MAR=10%) "0.034"   "0.049"  
## DownsideDeviation(Rf=0%)   "0.0299"  "0.0450" 
## GainDeviation              "0.0236"  "0.0396" 
## HistoricalES(95%)          "-0.0966" "-0.1491"
## HistoricalVaR(95%)         "-0.0751" "-0.1049"
## LossDeviation              "0.0318"  "0.0482" 
## MaximumDrawdown            "0.5256"  "0.7504" 
## ModifiedES(95%)            "-0.1012" "-0.1572"
## ModifiedVaR(95%)           "-0.0704" "-0.1046"
## SemiDeviation              "0.0319"  "0.0481"

Q7 Which of the two stocks would you choose?

Hint: Calculate Sharep Ratio and discuss your answer based on calculated Sharp Ratios.

##                           [,1]         [,2]        
## symbol                    "^GSPC"      "^IXIC"     
## ESSharpe(Rf=0%,p=95%)     "0.04221294" "0.04090118"
## StdDevSharpe(Rf=0%,p=95%) "0.10190974" "0.09910439"
## VaRSharpe(Rf=0%,p=95%)    "0.06066905" "0.06146953"

Using the sharpe ratio, S&P 500 would be a better investment due to having a higher sharpe ratios than NASDAQ.

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.