barplotPortfolioRisk: Create portfolio barplots with the capital allocation and the...

Description Usage Arguments Author(s) Examples

View source: R/plotting.R

Description

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.

Usage

1
barplotPortfolioRisk(w, Sigma, type = c("ggplot2", "simple"), colors = NULL)

Arguments

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: "ggplot2", "simple". Default is "ggplot2" (the packages ggplot2 and gridExtra must be installed).

colors

Vector of colors for the portfolios (optional).

Author(s)

Daniel P. Palomar and Ze Vinicius

Examples

 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()

riskParityPortfolio documentation built on June 1, 2021, 9:07 a.m.