Description Usage Arguments Author(s) Examples
Creates a barplot on top with the portfolio capital allocation and another
at the bottom with the risk contribution allocation whose profile is the target of the
risk parity portfolio design with riskParityPortfolio
.
By default the plot is based on the package ggplot2
, but the user
can also specify a simple base plot.
1 | barplotPortfolioRisk(w, Sigma, type = c("ggplot2", "simple"), colors = NULL)
|
w |
Vector or matrix containing the portfolio(s) weights. For multiple portfolios, they should be columnwise and named for the legend. |
Sigma |
Covariance matrix of the assets. |
type |
Type of plot. Valid options: |
colors |
Vector of colors for the portfolios (optional). |
Daniel P. Palomar and Ze Vinicius
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | library(riskParityPortfolio)
# generate random covariance matrix
set.seed(42)
N <- 10
V <- matrix(rnorm(N^2), nrow = N)
Sigma <- cov(V)
# generate random portfolio vectors
w_single <- runif(N)
w_single <- w_single/sum(w_single) # normalize
names(w_single) <- LETTERS[1:N]
w_multiple <- matrix(runif(4*N), ncol = 4)
w_multiple <- sweep(w_multiple, # normalize each column
MARGIN = 2,
STATS = colSums(w_multiple), FUN = "/")
rownames(w_multiple) <- LETTERS[1:N]
# plot
barplotPortfolioRisk(w_single, Sigma)
barplotPortfolioRisk(w_multiple, Sigma)
barplotPortfolioRisk(w_multiple, Sigma, colors = viridisLite::viridis(4))
barplotPortfolioRisk(w_multiple, Sigma) + ggplot2::scale_fill_viridis_d()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.