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: Calculate Kurtosis

portfolio_kurt_tbl <- portfolio_returns_tbl %>%
  tq_performance(Ra = returns, Rb = NULL, performance_fun = table.Stats) %>%
  select(Kurtosis)

portfolio_kurt_tbl
## # A tibble: 1 × 1
##   Kurtosis
##      <dbl>
## 1    0.430

Note: this is excess kurtosis (normal = 0).

Skewness Check (does the portfolio have a negatively skewed distribution?)

portfolio_skew <- skewness(portfolio_returns_tbl$returns)
portfolio_skew
## [1] -0.3115368

Plot: Rolling Kurtosis

window <- 24

rolling_kurt_table <- portfolio_returns_tbl %>%
  tq_mutate(
    select     = returns,
    mutate_fun = rollapply,
    width      = window,
    FUN        = kurtosis,
    col_rename = "kurt"
  ) %>%
  na.omit() %>%
  select(-returns)

rolling_kurt_table %>%
  ggplot(aes(x = date, y = kurt)) +
  geom_line(color = "cornflowerblue") +
  scale_y_continuous(breaks = seq(-2, 4, 0.5)) +
  scale_x_date(breaks = scales::pretty_breaks(n = 7)) +
  labs(x = "", y = "Kurtosis",
       title = paste0("Rolling ", window, " Month Kurtosis")) +
  theme(plot.title = element_text(hjust = 0.5))

Discussion: Has the portfolio’s downside risk changed over time?

Draft (auto-generated from the results above; check it against your plot and rewrite in your own words).

The portfolio’s returns are negatively skewed (a longer left tail), with skewness of -0.31. Because the distribution is negatively skewed, it is reasonable to treat kurtosis (fat tails) as a measure of downside risk: large losses are more likely than large gains.

The 24-month rolling kurtosis moved from 0.9 (January 2014) to 0.31 (December 2016), so tail risk has overall decreased over the period. It peaked at 1.14 in April 2014 and was lowest at -0.65 in April 2015.

Higher kurtosis means more of the returns fall in the tails (more extreme outcomes), and lower or negative values mean returns are concentrated near the center and are more predictable. Add one or two sentences describing the shape you see in the line (steady, sharp rise, spike, decline) and what that implies for the portfolio’s risk.