Our project is based on analyzing of a custom portfolio, compared to the market.
For out portfolio we will be using Johnson and Johnson, On Deck Capital, Starbucks, Bed Bath and Beyond, a cyber security ETF, Meet Group Inc, AEYE (a software company), Stitch Fix, Omega Healthcare, and Best Buy.
## # A tibble: 556 x 3
## # Groups: symbol [10]
## symbol date Ra
## <chr> <date> <dbl>
## 1 JNJ 2013-01-31 0.0435
## 2 JNJ 2013-02-28 0.0379
## 3 JNJ 2013-03-28 0.0712
## 4 JNJ 2013-04-30 0.0454
## 5 JNJ 2013-05-31 -0.00489
## 6 JNJ 2013-06-28 0.0200
## 7 JNJ 2013-07-31 0.0890
## 8 JNJ 2013-08-30 -0.0689
## 9 JNJ 2013-09-30 0.00324
## 10 JNJ 2013-10-31 0.0683
## # ... with 546 more rows
These are the monthly returns for our portfolio stocks, starting with JNJ.
As you can see we have an initial profit of 4.3% for JNJ.
# Baseline Period Returns
baseline_returns_monthly <- "^GSPC" %>%
tq_get(get = "stock.prices",
from = "2013-01-01",
to = "2018-12-31") %>%
tq_transmute(select = adjusted,
mutate_fun = periodReturn,
period = "monthly",
col_rename = "Rb")
baseline_returns_monthly
## # A tibble: 72 x 2
## date Rb
## <date> <dbl>
## 1 2013-01-31 0.0244
## 2 2013-02-28 0.0111
## 3 2013-03-28 0.0360
## 4 2013-04-30 0.0181
## 5 2013-05-31 0.0208
## 6 2013-06-28 -0.0150
## 7 2013-07-31 0.0495
## 8 2013-08-30 -0.0313
## 9 2013-09-30 0.0297
## 10 2013-10-31 0.0446
## # ... with 62 more rows
These are the returns for the S&P500.
## # A tibble: 556 x 4
## # Groups: portfolio [1]
## portfolio symbol date Ra
## <int> <chr> <date> <dbl>
## 1 1 JNJ 2013-01-31 0.0435
## 2 1 JNJ 2013-02-28 0.0379
## 3 1 JNJ 2013-03-28 0.0712
## 4 1 JNJ 2013-04-30 0.0454
## 5 1 JNJ 2013-05-31 -0.00489
## 6 1 JNJ 2013-06-28 0.0200
## 7 1 JNJ 2013-07-31 0.0890
## 8 1 JNJ 2013-08-30 -0.0689
## 9 1 JNJ 2013-09-30 0.00324
## 10 1 JNJ 2013-10-31 0.0683
## # ... with 546 more rows
# Create Vector of Weights
# not all symbols need to be specified. Any symbol not specified by default gets a weight of zero.
weights <- c(
0.147, 0.175, 0.24, 0.084, 0.043, 0.058, 0.045, 0.056, 0.037, 0.115
)
stocks <- c("JNJ", "ONDK", "SBUX", "BBBY", "HACK", "MEET", "AEYE", "SFIX", "OHI", "BBY")
weights_table <- tibble(stocks) %>%
tq_repeat_df(n = 1) %>%
bind_cols(tibble(weights)) %>%
group_by(portfolio)
weights_table
## # A tibble: 10 x 3
## # Groups: portfolio [1]
## portfolio stocks weights
## <int> <chr> <dbl>
## 1 1 JNJ 0.147
## 2 1 ONDK 0.175
## 3 1 SBUX 0.24
## 4 1 BBBY 0.084
## 5 1 HACK 0.043
## 6 1 MEET 0.058
## 7 1 AEYE 0.045
## 8 1 SFIX 0.056
## 9 1 OHI 0.037
## 10 1 BBY 0.115
# Aggregate a Portfolio using Vector of Weights
portfolio_returns_monthly_multi <-
stock_returns_monthly_multi %>%
tq_portfolio(assets_col = symbol,
returns_col = Ra,
weights = weights_table,
col_rename = "Ra")
portfolio_returns_monthly_multi
## # A tibble: 74 x 3
## # Groups: portfolio [1]
## portfolio date Ra
## <int> <date> <dbl>
## 1 1 2013-01-31 0.0610
## 2 1 2013-02-28 0.00413
## 3 1 2013-03-28 0.0876
## 4 1 2013-04-30 0.0695
## 5 1 2013-05-31 0.000949
## 6 1 2013-06-28 0.00269
## 7 1 2013-07-31 0.0621
## 8 1 2013-08-30 0.0285
## 9 1 2013-09-30 0.0377
## 10 1 2013-10-31 0.0634
## # ... with 64 more rows
For our porfolio, we have weights, which are decided by amount invested of the overall amount invested.
## # A tibble: 74 x 4
## # Groups: portfolio [?]
## portfolio date Ra Rb
## <int> <date> <dbl> <dbl>
## 1 1 2013-01-31 0.0610 0.0244
## 2 1 2013-02-28 0.00413 0.0111
## 3 1 2013-03-28 0.0876 0.0360
## 4 1 2013-04-30 0.0695 0.0181
## 5 1 2013-05-31 0.000949 0.0208
## 6 1 2013-06-28 0.00269 -0.0150
## 7 1 2013-07-31 0.0621 0.0495
## 8 1 2013-08-30 0.0285 -0.0313
## 9 1 2013-09-30 0.0377 0.0297
## 10 1 2013-10-31 0.0634 0.0446
## # ... with 64 more rows
RaRb_single_portfolio %>%
tq_performance(Ra = Ra, Rb = Rb, performance_fun = table.CAPM) %>%
t()
## [,1]
## portfolio 1.0000
## ActivePremium 0.0176
## Alpha 0.0027
## AnnualizedAlpha 0.0324
## Beta 0.8882
## Beta- 1.2697
## Beta+ 0.7363
## Correlation 0.6454
## Correlationp-value 0.0000
## InformationRatio 0.1563
## R-squared 0.4165
## TrackingError 0.1124
## TreynorRatio 0.1203
When we look at Beta, we can see our portfolio equaling .8882, which means it is less volitile when compared to the S&P. When looking at Alpha we can see our portfolio having .27% better return than that of the S&P. Annually we see a 3.24% better return than that of the S&P.
RaRb_single_portfolio %>%
ggplot(aes(x = Ra, fill = portfolio)) +
geom_density(alpha = .3)
For our density plot for our portfolio, we see higher, more common positive returns than negative. Also, overall you see much more density on the positive returns side, than the negative.
RaRb_single_portfolio %>%
ggplot(aes(x = Rb, fill = portfolio)) +
geom_density(alpha = .3)
For the S&P we see similar consistent positive returns, but it being higher means it is more risky.
When comparing them it seems as though our portfolio is outperforming the market, and is less risky when comparing the two plots. Although, we feel there could be an increase in profit in our portfolio. Also when comparing them it is important to note that our portfolio is both more likely to have higher negative returns, but also much more likely to have higher positive returns. (shown by the bigger tails at both ends)
RaRb_single_portfolio %>%
gather(type, value, - portfolio, - date) %>%
ggplot(aes(x = value, fill = type)) +
geom_density(alpha = .3)