What is CAMP? https://www.investopedia.com/terms/c/capm.asp

Q1 Import Portfolio 1

library(tidyquant)
library(tidyverse)

portfolio_1_quarterly <- c("BA", "IBM", "AAPL", "BAC", "GOLD", "MSFT", "F", "SKX") %>%
    tq_get(get  = "stock.prices",
           from = "2015-01-02",
           to   = "2019-04-25") %>%
    group_by(symbol) %>%
    tq_transmute(select     = adjusted, 
                 mutate_fun = periodReturn, 
                 period     = "quarterly", 
                 col_rename = "Ra")
portfolio_1_quarterly
## # A tibble: 144 x 3
## # Groups:   symbol [8]
##    symbol date            Ra
##    <chr>  <date>       <dbl>
##  1 BA     2015-03-31  0.162 
##  2 BA     2015-06-30 -0.0698
##  3 BA     2015-09-30 -0.0500
##  4 BA     2015-12-31  0.111 
##  5 BA     2016-03-31 -0.114 
##  6 BA     2016-06-30  0.0314
##  7 BA     2016-09-30  0.0228
##  8 BA     2016-12-30  0.200 
##  9 BA     2017-03-31  0.146 
## 10 BA     2017-06-30  0.127 
## # ... with 134 more rows

portfolio_2_quarterly <- c("NKE", "FCAU", "GE", "PG", "DELL", "AGI", "GM", "T") %>%
    tq_get(get  = "stock.prices",
           from = "2015-01-02",
           to   = "2019-04-25") %>%
    group_by(symbol) %>%
    tq_transmute(select     = adjusted, 
                 mutate_fun = periodReturn, 
                 period     = "quarterly", 
                 col_rename = "Ra")
portfolio_2_quarterly
## # A tibble: 138 x 3
## # Groups:   symbol [8]
##    symbol date            Ra
##    <chr>  <date>       <dbl>
##  1 NKE    2015-03-31  0.0619
##  2 NKE    2015-06-30  0.0825
##  3 NKE    2015-09-30  0.144 
##  4 NKE    2015-12-31  0.0214
##  5 NKE    2016-03-31 -0.0139
##  6 NKE    2016-06-30 -0.0994
##  7 NKE    2016-09-30 -0.0409
##  8 NKE    2016-12-30 -0.0311
##  9 NKE    2017-03-31  0.0998
## 10 NKE    2017-06-30  0.0623
## # ... with 128 more rows

Q2 Aggregate Portfolios.

portfolio_1 <- portfolio_1_quarterly %>%
    tq_repeat_df(n = 1)
portfolio_1
## # A tibble: 144 x 4
## # Groups:   portfolio [1]
##    portfolio symbol date            Ra
##        <int> <chr>  <date>       <dbl>
##  1         1 BA     2015-03-31  0.162 
##  2         1 BA     2015-06-30 -0.0698
##  3         1 BA     2015-09-30 -0.0500
##  4         1 BA     2015-12-31  0.111 
##  5         1 BA     2016-03-31 -0.114 
##  6         1 BA     2016-06-30  0.0314
##  7         1 BA     2016-09-30  0.0228
##  8         1 BA     2016-12-30  0.200 
##  9         1 BA     2017-03-31  0.146 
## 10         1 BA     2017-06-30  0.127 
## # ... with 134 more rows

weights <- c(
    0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125)
stocks <- c("BA", "IBM", "AAPL", "BAC", "GOLD", "MSFT", "F", "SKX")
weights_table1 <-  tibble(stocks) %>%
    tq_repeat_df(n = 1 )%>%
    bind_cols(tibble(weights)) %>%
    group_by(portfolio)
weights_table1
## # A tibble: 8 x 3
## # Groups:   portfolio [1]
##   portfolio stocks weights
##       <int> <chr>    <dbl>
## 1         1 BA       0.125
## 2         1 IBM      0.125
## 3         1 AAPL     0.125
## 4         1 BAC      0.125
## 5         1 GOLD     0.125
## 6         1 MSFT     0.125
## 7         1 F        0.125
## 8         1 SKX      0.125

portfolio_2 <- portfolio_2_quarterly %>%
    tq_repeat_df(n = 1)
portfolio_2
## # A tibble: 138 x 4
## # Groups:   portfolio [1]
##    portfolio symbol date            Ra
##        <int> <chr>  <date>       <dbl>
##  1         1 NKE    2015-03-31  0.0619
##  2         1 NKE    2015-06-30  0.0825
##  3         1 NKE    2015-09-30  0.144 
##  4         1 NKE    2015-12-31  0.0214
##  5         1 NKE    2016-03-31 -0.0139
##  6         1 NKE    2016-06-30 -0.0994
##  7         1 NKE    2016-09-30 -0.0409
##  8         1 NKE    2016-12-30 -0.0311
##  9         1 NKE    2017-03-31  0.0998
## 10         1 NKE    2017-06-30  0.0623
## # ... with 128 more rows

weights <- c(
    0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125)
stocks <- c("NKE", "FCAU", "GE", "PG", "DELL", "AGI", "GM", "T")
weights_table2 <-  tibble(stocks) %>%
    tq_repeat_df(n = 1 )%>%
    bind_cols(tibble(weights)) %>%
    group_by(portfolio)
weights_table2
## # A tibble: 8 x 3
## # Groups:   portfolio [1]
##   portfolio stocks weights
##       <int> <chr>    <dbl>
## 1         1 NKE      0.125
## 2         1 FCAU     0.125
## 3         1 GE       0.125
## 4         1 PG       0.125
## 5         1 DELL     0.125
## 6         1 AGI      0.125
## 7         1 GM       0.125
## 8         1 T        0.125

Q3 Import S&P500 as a baseline index fund and calculate monthly returns.

baseline_returns_quarterly <- "^GSPC" %>%
    tq_get(get  = "stock.prices",
           from = "2015-01-02",
           to   = "2019-04-25") %>%
    tq_transmute(select     = adjusted, 
                 mutate_fun = periodReturn, 
                 period     = "quarterly", 
                 col_rename = "Rb")
baseline_returns_quarterly
## # A tibble: 18 x 2
##    date             Rb
##    <date>        <dbl>
##  1 2015-03-31  0.00471
##  2 2015-06-30 -0.00231
##  3 2015-09-30 -0.0694 
##  4 2015-12-31  0.0645 
##  5 2016-03-31  0.00773
##  6 2016-06-30  0.0190 
##  7 2016-09-30  0.0331 
##  8 2016-12-30  0.0325 
##  9 2017-03-31  0.0553 
## 10 2017-06-30  0.0257 
## 11 2017-09-29  0.0396 
## 12 2017-12-29  0.0612 
## 13 2018-03-29 -0.0122 
## 14 2018-06-29  0.0293 
## 15 2018-09-28  0.0720 
## 16 2018-12-31 -0.140  
## 17 2019-03-29  0.131  
## 18 2019-04-24  0.0328

Q4 What is the portfolio 1’s return on the first period?

portfolio_1_returns <-
  portfolio_1 %>%
    tq_portfolio(assets_col  = symbol, 
                 returns_col = Ra, 
                 weights     = weights_table1, 
                 col_rename  = "Ra")
portfolio_1_returns
## # A tibble: 18 x 3
## # Groups:   portfolio [1]
##    portfolio date              Ra
##        <int> <date>         <dbl>
##  1         1 2015-03-31  0.0495  
##  2         1 2015-06-30  0.0863  
##  3         1 2015-09-30 -0.0446  
##  4         1 2015-12-31 -0.0324  
##  5         1 2016-03-31  0.0451  
##  6         1 2016-06-30  0.0520  
##  7         1 2016-09-30 -0.0199  
##  8         1 2016-12-30  0.0807  
##  9         1 2017-03-31  0.113   
## 10         1 2017-06-30 -0.000393
## 11         1 2017-09-29  0.0541  
## 12         1 2017-12-29  0.146   
## 13         1 2018-03-29  0.0188  
## 14         1 2018-06-29 -0.0116  
## 15         1 2018-09-28  0.0643  
## 16         1 2018-12-31 -0.145   
## 17         1 2019-03-29  0.194   
## 18         1 2019-04-24  0.0198

Portfolio 1 provided a return of 4.95% for the first quarter in 2015.

Q5 What is the portfolio 2’s return on the first period?

portfolio_2_returns <-
  portfolio_2 %>%
    tq_portfolio(assets_col  = symbol, 
                 returns_col = Ra, 
                 weights     = weights_table2, 
                 col_rename  = "Ra")
portfolio_2_returns
## # A tibble: 18 x 3
## # Groups:   portfolio [1]
##    portfolio date             Ra
##        <int> <date>        <dbl>
##  1         1 2015-03-31  0.0284 
##  2         1 2015-06-30 -0.00630
##  3         1 2015-09-30 -0.0596 
##  4         1 2015-12-31  0.0764 
##  5         1 2016-03-31  0.0346 
##  6         1 2016-06-30  0.0191 
##  7         1 2016-09-30  0.0107 
##  8         1 2016-12-30  0.0592 
##  9         1 2017-03-31  0.0795 
## 10         1 2017-06-30 -0.0381 
## 11         1 2017-09-29  0.136  
## 12         1 2017-12-29  0.00582
## 13         1 2018-03-29 -0.0435 
## 14         1 2018-06-29  0.0405 
## 15         1 2018-09-28 -0.00520
## 16         1 2018-12-31 -0.108  
## 17         1 2019-03-29  0.148  
## 18         1 2019-04-24  0.0519

Portfolio 2 provided a return of 2.83% for the first quarter in 2015.

Q6a Merge Portfolio 1 and baseline index

Portfolio_1_and_baseline <- left_join(portfolio_1_returns, 
                                   baseline_returns_quarterly,
                                   by = "date")
Portfolio_1_and_baseline
## # A tibble: 18 x 4
## # Groups:   portfolio [?]
##    portfolio date              Ra       Rb
##        <int> <date>         <dbl>    <dbl>
##  1         1 2015-03-31  0.0495    0.00471
##  2         1 2015-06-30  0.0863   -0.00231
##  3         1 2015-09-30 -0.0446   -0.0694 
##  4         1 2015-12-31 -0.0324    0.0645 
##  5         1 2016-03-31  0.0451    0.00773
##  6         1 2016-06-30  0.0520    0.0190 
##  7         1 2016-09-30 -0.0199    0.0331 
##  8         1 2016-12-30  0.0807    0.0325 
##  9         1 2017-03-31  0.113     0.0553 
## 10         1 2017-06-30 -0.000393  0.0257 
## 11         1 2017-09-29  0.0541    0.0396 
## 12         1 2017-12-29  0.146     0.0612 
## 13         1 2018-03-29  0.0188   -0.0122 
## 14         1 2018-06-29 -0.0116    0.0293 
## 15         1 2018-09-28  0.0643    0.0720 
## 16         1 2018-12-31 -0.145    -0.140  
## 17         1 2019-03-29  0.194     0.131  
## 18         1 2019-04-24  0.0198    0.0328

Q6b Compute the CAPM Table for Portfolio 1

Portfolio_1_and_baseline %>%
    tq_performance(Ra = Ra, Rb = Rb, performance_fun = table.CAPM) %>%
  t()
##                      [,1]
## portfolio          1.0000
## ActivePremium      0.0636
## Alpha              0.0153
## AnnualizedAlpha    0.0624
## Beta               1.0264
## Beta-              1.5214
## Beta+              1.2016
## Correlation        0.7680
## Correlationp-value 0.0002
## InformationRatio   0.6456
## R-squared          0.5898
## TrackingError      0.0985
## TreynorRatio       0.1413

Q7a Merge Portfolio 2 and baseline index

Portfolio_2_and_baseline <- left_join(portfolio_2_returns, 
                                   baseline_returns_quarterly,
                                   by = "date")
Portfolio_2_and_baseline
## # A tibble: 18 x 4
## # Groups:   portfolio [?]
##    portfolio date             Ra       Rb
##        <int> <date>        <dbl>    <dbl>
##  1         1 2015-03-31  0.0284   0.00471
##  2         1 2015-06-30 -0.00630 -0.00231
##  3         1 2015-09-30 -0.0596  -0.0694 
##  4         1 2015-12-31  0.0764   0.0645 
##  5         1 2016-03-31  0.0346   0.00773
##  6         1 2016-06-30  0.0191   0.0190 
##  7         1 2016-09-30  0.0107   0.0331 
##  8         1 2016-12-30  0.0592   0.0325 
##  9         1 2017-03-31  0.0795   0.0553 
## 10         1 2017-06-30 -0.0381   0.0257 
## 11         1 2017-09-29  0.136    0.0396 
## 12         1 2017-12-29  0.00582  0.0612 
## 13         1 2018-03-29 -0.0435  -0.0122 
## 14         1 2018-06-29  0.0405   0.0293 
## 15         1 2018-09-28 -0.00520  0.0720 
## 16         1 2018-12-31 -0.108   -0.140  
## 17         1 2019-03-29  0.148    0.131  
## 18         1 2019-04-24  0.0519   0.0328

Q7b Compute the CAPM Table for Portfolio 2

Portfolio_2_and_baseline %>%
    tq_performance(Ra = Ra, Rb = Rb, performance_fun = table.CAPM) %>%
  t()
##                      [,1]
## portfolio          1.0000
## ActivePremium      0.0092
## Alpha              0.0050
## AnnualizedAlpha    0.0202
## Beta               0.8825
## Beta-              0.6361
## Beta+              0.8057
## Correlation        0.7831
## Correlationp-value 0.0001
## InformationRatio   0.1130
## R-squared          0.6133
## TrackingError      0.0818
## TreynorRatio       0.1027

Q8 Compare Portfolio 1 and 2 in terms of Beta and Alpha

Portfolio 1 Beta: 1.0264 Portfolio 2 Beta: 0.8825

Beta is the volatility of a stock, or how much a stock’s return would be expected to change. Beta is way to measure the risk of a stock in terms of its expected returns. The higher the Beta, the more risky the stock is. Portfolio 1 had a higher Beta than Portfolio 2, meaning that Portfolio 1 is more volatile and Portfolio 2 is less volatile.

Portfolio 1 Alpha: 0.0153 Portfolio 2 Alpha: 0.0050

When looking at Alpha, you can see how much better the portfolio did than the market benchmark. Portfolio 1 had a higher Alpha than Portfolio 2 at .0153, meaning that Portfolio 1 outperformed the S&P by 1.53%. Portfolio 2 had an Alpha of .0050, meaning that it outperformed the S&P 500 by 0.50%. Portfolio 1 outperformed Portfolio 2 by a greater amount.

Portfolio 1 would be our choice as an investment, as it provides higher returns with similar risks.