Goal

Visualize expected returns and risk to make it easier to compare the performance of multiple assets and portfolios.

Choose your stocks.

from 2012-12-31 to 2017-12-31

1 Import stock prices

## # A tibble: 6,300 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 AAPL   2012-12-31  18.2  19.1  18.2  19.0 659492400     16.1
##  2 AAPL   2013-01-02  19.8  19.8  19.3  19.6 560518000     16.6
##  3 AAPL   2013-01-03  19.6  19.6  19.3  19.4 352965200     16.4
##  4 AAPL   2013-01-04  19.2  19.2  18.8  18.8 594333600     15.9
##  5 AAPL   2013-01-07  18.6  18.9  18.4  18.7 484156400     15.8
##  6 AAPL   2013-01-08  18.9  19.0  18.6  18.8 458707200     15.9
##  7 AAPL   2013-01-09  18.7  18.8  18.4  18.5 407604400     15.6
##  8 AAPL   2013-01-10  18.9  18.9  18.4  18.7 601146000     15.8
##  9 AAPL   2013-01-11  18.6  18.8  18.5  18.6 350506800     15.7
## 10 AAPL   2013-01-14  18.0  18.1  17.8  17.9 734207600     15.1
## # ℹ 6,290 more rows

2 Convert prices to returns (monthly)

## # A tibble: 305 × 3
## # Groups:   symbol [5]
##    symbol date              Ra
##    <chr>  <date>         <dbl>
##  1 AAPL   2012-12-31  0       
##  2 AAPL   2013-01-31 -0.144   
##  3 AAPL   2013-02-28 -0.0253  
##  4 AAPL   2013-03-28  0.00285 
##  5 AAPL   2013-04-30  0.000271
##  6 AAPL   2013-05-31  0.0224  
##  7 AAPL   2013-06-28 -0.118   
##  8 AAPL   2013-07-31  0.141   
##  9 AAPL   2013-08-30  0.0838  
## 10 AAPL   2013-09-30 -0.0215  
## # ℹ 295 more rows

3 Assign a weight to each asset (change the weigting scheme)

## [1] 0.20 0.20 0.25 0.15 0.20

4 Build a portfolio

## # A tibble: 61 × 2
##    date            Rp
##    <date>       <dbl>
##  1 2012-12-31  0     
##  2 2013-01-31  0.0120
##  3 2013-02-28  0.0101
##  4 2013-03-28  0.0220
##  5 2013-04-30  0.0122
##  6 2013-05-31  0.0196
##  7 2013-06-28 -0.0126
##  8 2013-07-31  0.0478
##  9 2013-08-30 -0.0362
## 10 2013-09-30  0.0231
## # ℹ 51 more rows

5 Compute Standard Deviation

## # A tibble: 1 × 2
##    Stdev  tq_sd
##    <dbl>  <dbl>
## 1 0.0373 0.0373
## [1] 0.01675302

6 Plot: Expected Returns versus Risk

## # A tibble: 6 × 3
##   symbol      mean  Stdev
##   <chr>      <dbl>  <dbl>
## 1 AAPL      0.0172 0.0689
## 2 AMZN      0.0283 0.0761
## 3 KO        0.0071 0.0362
## 4 XOM       0.0029 0.0402
## 5 HD        0.0213 0.0454
## 6 Portfolio 0.0168 0.0373

24 Months Rolling Volatility

## # A tibble: 38 × 2
##    date       rolling_sd
##    <date>          <dbl>
##  1 2014-11-28     0.0369
##  2 2014-12-31     0.0379
##  3 2015-01-30     0.0379
##  4 2015-02-27     0.0398
##  5 2015-03-31     0.0409
##  6 2015-04-30     0.0409
##  7 2015-05-29     0.0409
##  8 2015-06-30     0.0410
##  9 2015-07-31     0.0417
## 10 2015-08-31     0.0418
## # ℹ 28 more rows

How should you expect your portfolio to perform relative to its assets in the portfolio? Would you invest all your money in any of the individual stocks instead of the portfolio? Discuss both in terms of expected return and risk.

Based on the historical results, my portfolio has an estimated expected monthly return of 1.68% and a monthly standard deviation of 3.73%. The average return estimates the portfolio’s monthly performance, while standard deviation measures how much returns vary around that average. A higher standard deviation means greater uncertainty and larger potential fluctuations. The portfolio’s return is lower than AAPL, AMZN, and HD, but higher than KO and XOM. Its standard deviation is lower than every individual stock except KO, showing that diversification reduced volatility without requiring me to choose only the lowest-return stocks.

However, the average alone does not tell me what to expect in any particular month. I would also examine the full return distribution, including how often losses occur, the size of extreme losses, and whether returns are concentrated near the average. Two investments can have similar average returns but very different risks. For example, AAPL’s average monthly return of 1.72% is close to the portfolio’s 1.68%, but its standard deviation of 6.89% is much higher than the portfolio’s 3.73%. The rolling volatility plot also shows that the portfolio’s risk changes over time, so one standard deviation does not describe every period equally well.

I would invest in the portfolio instead of putting all my money into one stock because I prefer balancing return with risk. AMZN had the highest average monthly return at 2.83%, but also the highest standard deviation at 7.61%. A risk-loving investor might accept those larger fluctuations for the possibility of higher returns. A risk-averse investor might favor KO, which had the lowest standard deviation at 3.62%, but its average return was only 0.71%. For my preference, the portfolio provides a higher historical return than KO with only slightly more volatility, while reducing dependence on one company. Diversification does not eliminate losses, and historical performance does not guarantee future results.