Steps 1-4: Rebuild the Portfolio (from Code Along 5)

symbols <- c("SPY", "EFA", "IJS", "EEM", "AGG")

prices <- tq_get(
  x    = symbols,
  get  = "stock.prices",
  from = "2012-01-01",
  to   = "2017-01-01"
)

asset_returns_tbl <- prices %>%
  group_by(symbol) %>%
  tq_transmute(
    select     = adjusted,
    mutate_fun = periodReturn,
    period     = "monthly",
    type       = "log"
  ) %>%
  slice(-1) %>%
  ungroup() %>%
  set_names(c("asset", "date", "returns"))

symbols_vec <- asset_returns_tbl %>%
  distinct(asset) %>%
  pull()

weights <- c(0.25, 0.25, 0.20, 0.20, 0.10)

w_tbl <- tibble(symbols_vec, weights) %>%
  set_names(c("asset", "weights"))

portfolio_returns_tbl <- asset_returns_tbl %>%
  tq_portfolio(
    assets_col   = asset,
    returns_col  = returns,
    weights      = w_tbl,
    col_rename   = "returns",
    rebalance_on = "months"
  )
## Warning in check_weights(weights, assets_col, map, x): Sum of weights does not
## equal 1.

Step 5: Skewness of the Portfolio

portfolio_skew_tbl <- portfolio_returns_tbl %>%
  summarise(skew = skewness(returns)) %>%
  mutate(asset = "Portfolio")

portfolio_skew_tbl
## # A tibble: 1 × 2
##     skew asset    
##    <dbl> <chr>    
## 1 -0.312 Portfolio

Step 6: Skewness of Each Asset

asset_skew_tbl <- asset_returns_tbl %>%
  group_by(asset) %>%
  summarise(skew = skewness(returns)) %>%
  ungroup()

asset_skew_tbl
## # A tibble: 5 × 2
##   asset    skew
##   <chr>   <dbl>
## 1 AGG   -0.509 
## 2 EEM   -0.0610
## 3 EFA   -0.472 
## 4 IJS   -0.0184
## 5 SPY   -0.334

Step 7: Combine Assets and Portfolio

skew_tbl <- bind_rows(asset_skew_tbl, portfolio_skew_tbl)
skew_tbl
## # A tibble: 6 × 2
##   asset        skew
##   <chr>       <dbl>
## 1 AGG       -0.509 
## 2 EEM       -0.0610
## 3 EFA       -0.472 
## 4 IJS       -0.0184
## 5 SPY       -0.334 
## 6 Portfolio -0.312

Step 8: Skewness Comparison Plot

skew_tbl %>%
  ggplot(aes(x = asset, y = skew, color = asset)) +
  geom_point(size = 3) +
  geom_text_repel(aes(label = asset), show.legend = FALSE) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  labs(title = "Skewness Comparison: Assets vs. Portfolio",
       x = "", y = "Skewness") +
  theme(legend.position = "none")

Return Distributions (for context)

asset_returns_tbl %>%
  ggplot(aes(x = returns, fill = asset)) +
  geom_histogram(bins = 30, alpha = 0.7) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  facet_wrap(~asset) +
  theme(legend.position = "none")

Question: Is any asset more likely to return extreme positive returns than the portfolio?

Draft answer (auto-generated from the results above; edit it in your own words after checking the histograms).

The portfolio’s skewness is -0.31. The asset(s) with higher skewness than the portfolio: EEM (skewness -0.06, median monthly return -0.003); IJS (skewness -0.02, median monthly return 0.013).

Positive skewness means a longer tail to the right, which suggests the possibility of large gains. However, skewness describes the shape of the distribution, not where its center is. If an asset’s distribution is centered below zero (see its histogram), its right tail may still sit near zero, so a higher skewness does not by itself mean a higher likelihood of large positive returns. Compare each asset’s histogram center to zero before concluding that it is more likely than the portfolio to produce extreme positive returns.