1 Import stock prices of your choice

## # A tibble: 1,092 × 8
##    symbol date        open  high   low close    volume adjusted
##    <chr>  <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>    <dbl>
##  1 AAPL   2021-12-01  167.  170.  165.  165. 152052500     161.
##  2 AAPL   2021-12-02  159.  164.  158.  164. 136739200     160.
##  3 AAPL   2021-12-03  164.  165.  160.  162. 118023100     158.
##  4 AAPL   2021-12-06  164.  168.  164.  165. 107497000     161.
##  5 AAPL   2021-12-07  169.  172.  168.  171. 120405400     167.
##  6 AAPL   2021-12-08  172.  176.  171.  175. 116998900     171.
##  7 AAPL   2021-12-09  175.  177.  174.  175. 108923700     171.
##  8 AAPL   2021-12-10  175.  180.  175.  179. 115402700     175.
##  9 AAPL   2021-12-13  181.  182.  176.  176. 153237000     172.
## 10 AAPL   2021-12-14  175.  178.  172.  174. 139380400     170.
## # ℹ 1,082 more rows

2 Convert prices to returns by quarterly

## # A tibble: 16 × 3
##    asset date       returns
##    <chr> <date>       <dbl>
##  1 AAPL  2022-03-31 -0.0155
##  2 AAPL  2022-06-30 -0.243 
##  3 AAPL  2022-09-30  0.0122
##  4 AAPL  2022-12-30 -0.0600
##  5 MSFT  2022-03-31 -0.0849
##  6 MSFT  2022-06-30 -0.180 
##  7 MSFT  2022-09-30 -0.0957
##  8 MSFT  2022-12-30  0.0321
##  9 WMT   2022-03-31  0.0327
## 10 WMT   2022-06-30 -0.199 
## 11 WMT   2022-09-30  0.0690
## 12 WMT   2022-12-30  0.0929
## 13 SPY   2022-03-31 -0.0472
## 14 SPY   2022-06-30 -0.176 
## 15 SPY   2022-09-30 -0.0506
## 16 SPY   2022-12-30  0.0729

3 Make plot

4 Interpret the plot

## # A tibble: 4 × 2
##   asset annual_return
##   <chr>         <dbl>
## 1 AAPL         -26.4 
## 2 MSFT         -28.0 
## 3 SPY          -18.2 
## 4 WMT           -0.46
## # A tibble: 4 × 2
##   asset     n
##   <chr> <int>
## 1 AAPL      4
## 2 MSFT      4
## 3 SPY       4
## 4 WMT       4

The graph compares the quarterly returns of Apple, Microsoft, and Walmart against SPY, which represents the S&P 500. In 2022, Walmart performed the best of my three stocks, losing only 0.46% compared to SPY’s 18.2% loss. Apple lost 26.4%, and Microsoft lost 28%. Walmart was the only one of my stocks that beat the market.

5 Change the global chunk options

The global chunk options hide the code, messages, and warnings in the final HTML report.