We can use the stat_density(geom = "line", alpha = 1) function to do this. Maybe we don’t want to use a histogram, but instead want to use a density line to visualize the various distributions. Let’s use facet_wrap(~asset) to break these out by asset. Theme_update(plot.title = element_text(hjust = 0.5)) # Make so all titles centered in the upcoming ggplots Because it is in long, tidy format, and it is grouped by the ‘asset’ column, we can chart the asset histograms collectively on one chart. The functionality is fine for one set of returns, but here we want to see the distribution of all of our returns series together.įor that, we will head to the tidyverse and use ggplot2 on our tidy tibble called assets_returns_long. However, highcharter is missing an easy way to chart multiple histograms, and to add density lines to those multiple histograms. Nothing wrong with that chart, and it shows us the distribution of SPY returns. Hc_title(text = "Monthly Log Returns") %>% In this case, we’ll add our columns from the xts object. Then we add each of our series to the highcharter code flow. First, we set highchart(type = "stock") to get a nice time series line. Highcharter is fantastic for visualizing a time series or many time series. First, let’s use highcharter to visualize the xts formatted returns. We now have two objects holding monthly log returns, asset_returns_xts and asset_returns_long. Mutate(returns = (log(returns) - log(lag(returns)))) Tk_tbl(preserve_index = TRUE, rename_index = "date") %>% To.monthly(indexAt = "last", OHLC = FALSE) %>% 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. + EEM (an emerging-mkts fund) weighted 20% + IJS (a small-cap value fund) weighted 20% + EFA (a non-US equities fund) weighted 25% 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.īy way of a quick reminder, our ultimate portfolio consists of the following. Today, we will visualize the returns of our individual assets that ultimately get mashed into a portfolio. In a previous post, we reviewed how to import daily prices, build a portfolio, and calculate portfolio returns.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |