In a previous post, we reviewed how to import daily prices, build a portfolio, and calculate portfolio returns. Today, we will visualize the returns of our individual assets that ultimately get mashed into a portfolio. The motivation here is to make sure we have scrutinized our assets before they get into our portfolio, because once the portfolio has been constructed, it is tempting to keep the analysis at the portfolio level.
By way of a quick reminder, our ultimate portfolio consists of the following.
+ SPY (S&amp;P 500 fund) weighted 25%
+ EFA (a non-US equities fund) weighted 25%
+ IJS (a small-cap value fund) weighted 20%
+ EEM (an emerging-mkts fund) weighted 20%
+ AGG (a bond fund) weighted 10%
Let’s load up our packages.
library(tidyverse)
library(tidyquant)
library(timetk)
library(tibbletime)
library(highcharter)
To get our objects into the global environment, we use the next code chunk, which should look familiar from the previous post: we will create one xts object and one tibble, in long/tidy format, of monthly log returns.
# The symbols vector holds our tickers. symbols % reduce(merge) %__%
`colnames% group_by(asset) %__% mutate(returns = (log(returns) - log(lag(returns))))
We now have two objects holding monthly log returns, asset_returns_xts and asset_returns_long. First, let’s use highcharter to visualize the xts formatted returns.
Highcharter is fantastic for visualizing a time series or many time series. First, we set highchart(type = &quot;stock&quot;) to get a nice time series line. Then we add each of our series to the highcharter code flow. In this case, we’ll add our columns from the xts object.
highchart(type = &quot;stock&quot;) %__% hc_title(text = &quot;Monthly Log Returns&quot;) %__%
hc_add_series(asset_returns_xts$SPY, name = names(asset_returns_xts$SPY)) %__%
hc_add_series(asset_returns_xts$EFA, name = names(asset_returns_xts$EFA)) %__%
hc_add_series(asset_returns_xts$IJS, name = names(asset_returns_xts$IJS)) %__%
hc_add_theme(hc_theme_flat()) %__%
hc_navigator(enabled = FALSE) %__% hc_scrollbar(enabled = FALSE)