What is CAMP? https://www.investopedia.com/terms/c/capm.asp
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
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
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
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.0500
## 2 1 2015-06-30 0.0867
## 3 1 2015-09-30 -0.0448
## 4 1 2015-12-31 -0.0321
## 5 1 2016-03-31 0.0462
## 6 1 2016-06-30 0.0534
## 7 1 2016-09-30 -0.0203
## 8 1 2016-12-30 0.0804
## 9 1 2017-03-31 0.114
## 10 1 2017-06-30 -0.000680
## 11 1 2017-09-29 0.0542
## 12 1 2017-12-29 0.145
## 13 1 2018-03-29 0.0186
## 14 1 2018-06-29 -0.0112
## 15 1 2018-09-28 0.0639
## 16 1 2018-12-31 -0.144
## 17 1 2019-03-29 0.193
## 18 1 2019-04-24 0.0195
Portfolio 1 provided a return of 5.00% for the first quarter in 2015.
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.0510
Portfolio 2 provided a return of 2.84% for the first quarter in 2015.
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.0500 0.00471
## 2 1 2015-06-30 0.0867 -0.00231
## 3 1 2015-09-30 -0.0448 -0.0694
## 4 1 2015-12-31 -0.0321 0.0645
## 5 1 2016-03-31 0.0462 0.00773
## 6 1 2016-06-30 0.0534 0.0190
## 7 1 2016-09-30 -0.0203 0.0331
## 8 1 2016-12-30 0.0804 0.0325
## 9 1 2017-03-31 0.114 0.0553
## 10 1 2017-06-30 -0.000680 0.0257
## 11 1 2017-09-29 0.0542 0.0396
## 12 1 2017-12-29 0.145 0.0612
## 13 1 2018-03-29 0.0186 -0.0122
## 14 1 2018-06-29 -0.0112 0.0293
## 15 1 2018-09-28 0.0639 0.0720
## 16 1 2018-12-31 -0.144 -0.140
## 17 1 2019-03-29 0.193 0.131
## 18 1 2019-04-24 0.0195 0.0328
tableCAMP1 <-
Portfolio_1_and_baseline %>%
tq_performance(Ra = Ra, Rb = Rb, performance_fun = table.CAPM) %>%
t()
tableCAMP1
## [,1]
## portfolio 1.0000
## ActivePremium 0.0645
## Alpha 0.0156
## AnnualizedAlpha 0.0637
## Beta 1.0197
## Beta- 1.5117
## Beta+ 1.1899
## Correlation 0.7659
## Correlationp-value 0.0002
## InformationRatio 0.6545
## R-squared 0.5867
## TrackingError 0.0985
## TreynorRatio 0.1431
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.0510 0.0328
tableCAMP2 <-
Portfolio_2_and_baseline %>%
tq_performance(Ra = Ra, Rb = Rb, performance_fun = table.CAPM) %>%
t()
tableCAMP2
## [,1]
## portfolio 1.0000
## ActivePremium 0.0090
## Alpha 0.0050
## AnnualizedAlpha 0.0200
## Beta 0.8823
## Beta- 0.6361
## Beta+ 0.8065
## Correlation 0.7832
## Correlationp-value 0.0001
## InformationRatio 0.1104
## R-squared 0.6135
## TrackingError 0.0817
## TreynorRatio 0.1025
tableCAMP1 %>%
cbind(tableCAMP2)
## [,1] [,2]
## portfolio 1.0000 1.0000
## ActivePremium 0.0645 0.0090
## Alpha 0.0156 0.0050
## AnnualizedAlpha 0.0637 0.0200
## Beta 1.0197 0.8823
## Beta- 1.5117 0.6361
## Beta+ 1.1899 0.8065
## Correlation 0.7659 0.7832
## Correlationp-value 0.0002 0.0001
## InformationRatio 0.6545 0.1104
## R-squared 0.5867 0.6135
## TrackingError 0.0985 0.0817
## TreynorRatio 0.1431 0.1025
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 is made up of well established technology companies, manufacturing companies, banking and retailing companies. This broad arrangement of industries helps diversify the Portfolio, creating less risk.
Portfolio 2 has a similar make up of companies. Portfolio 2 favors more manufacturing companies, as well as technology and retailers. This make up of companies helps spread the risk and diversify the Portfolio. There are not many distinct differences between the portfolios, but Portfolio 1 provides higher returns.
Portfolio 1 would be our choice as an investment, as it provides higher returns with similar risks.