## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.3.0      ✔ stringr 1.5.0 
## ✔ readr   2.1.3      ✔ forcats 1.0.0 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## Loading required package: lubridate
## 
## 
## Attaching package: 'lubridate'
## 
## 
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
## 
## 
## Loading required package: PerformanceAnalytics
## 
## Loading required package: xts
## 
## Loading required package: zoo
## 
## 
## Attaching package: 'zoo'
## 
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## 
## Attaching package: 'xts'
## 
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## 
## 
## Attaching package: 'PerformanceAnalytics'
## 
## 
## The following object is masked from 'package:graphics':
## 
##     legend
## 
## 
## Loading required package: quantmod
## 
## Loading required package: TTR
## 
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

1 Get stock prices and convert to returns

## # A tibble: 70 × 3
## # Groups:   symbol [5]
##    symbol date            Ra
##    <chr>  <date>       <dbl>
##  1 TSLA   2022-01-31 -0.219 
##  2 TSLA   2022-02-28 -0.0708
##  3 TSLA   2022-03-31  0.238 
##  4 TSLA   2022-04-29 -0.192 
##  5 TSLA   2022-05-31 -0.129 
##  6 TSLA   2022-06-30 -0.112 
##  7 TSLA   2022-07-29  0.324 
##  8 TSLA   2022-08-31 -0.0725
##  9 TSLA   2022-09-30 -0.0376
## 10 TSLA   2022-10-31 -0.142 
## # … with 60 more rows

2 Get baseline and convert to returns

## # A tibble: 14 × 2
##    date            Rb
##    <date>       <dbl>
##  1 2022-01-31 -0.101 
##  2 2022-02-28 -0.0343
##  3 2022-03-31  0.0341
##  4 2022-04-29 -0.133 
##  5 2022-05-31 -0.0205
##  6 2022-06-30 -0.0871
##  7 2022-07-29  0.123 
##  8 2022-08-31 -0.0464
##  9 2022-09-30 -0.105 
## 10 2022-10-31  0.0390
## 11 2022-11-30  0.0437
## 12 2022-12-30 -0.0873
## 13 2023-01-31  0.107 
## 14 2023-02-10  0.0115

3 Join the two tables

## # A tibble: 70 × 4
## # Groups:   symbol [5]
##    symbol date            Ra      Rb
##    <chr>  <date>       <dbl>   <dbl>
##  1 TSLA   2022-01-31 -0.219  -0.101 
##  2 TSLA   2022-02-28 -0.0708 -0.0343
##  3 TSLA   2022-03-31  0.238   0.0341
##  4 TSLA   2022-04-29 -0.192  -0.133 
##  5 TSLA   2022-05-31 -0.129  -0.0205
##  6 TSLA   2022-06-30 -0.112  -0.0871
##  7 TSLA   2022-07-29  0.324   0.123 
##  8 TSLA   2022-08-31 -0.0725 -0.0464
##  9 TSLA   2022-09-30 -0.0376 -0.105 
## 10 TSLA   2022-10-31 -0.142   0.0390
## # … with 60 more rows

4 Calculate CAPM

## # A tibble: 5 × 13
## # Groups:   symbol [5]
##   symbol ActiveP…¹   Alpha Annua…²  Beta `Beta-` `Beta+` Corre…³ Corre…⁴ Infor…⁵
##   <chr>      <dbl>   <dbl>   <dbl> <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1 TSLA     -0.228   0.0107  0.136  2.08    0.908   3.25    0.759  0.0016  -0.390
## 2 GM       -0.055   0.007   0.0871 1.41    1.60    1.10    0.834  0.0002  -0.194
## 3 F        -0.0888  0.0132  0.171  1.77    1.44    2.41    0.871  0.0001  -0.253
## 4 VWAGY    -0.0578 -0.0042 -0.049  1.02    1.22    0.895   0.815  0.0004  -0.285
## 5 HMC       0.138   0.006   0.0743 0.610   0.834   0.683   0.668  0.009    0.632
## # … with 3 more variables: `R-squared` <dbl>, TrackingError <dbl>,
## #   TreynorRatio <dbl>, and abbreviated variable names ¹​ActivePremium,
## #   ²​AnnualizedAlpha, ³​Correlation, ⁴​`Correlationp-value`, ⁵​InformationRatio

Which stock has a positively skewed distribution of returns?

## # A tibble: 5 × 2
## # Groups:   symbol [5]
##   symbol VolatilitySkewness.1
##   <chr>                 <dbl>
## 1 TSLA                  2.51 
## 2 GM                    3.21 
## 3 F                     1.57 
## 4 VWAGY                 0.749
## 5 HMC                   5.21