plot_efficient_portfolios: Basic plot of efficient portfolio and asset contributions

View source: R/plot_efficient_portfolios.R

plot_efficient_portfoliosR Documentation

Basic plot of efficient portfolio and asset contributions

Description

This function creates a mean-variance plot of the portfolios across possible asset weights, colour the efficient frontier, and show the contribution of the different stocks/assets. It also (invisibly) returns the values that make up the plot so you can create your own custom plots with the data. See the Returns section for more details.

Usage

plot_efficient_portfolios(
  port_vals,
  weights_matrix,
  pal,
  plot = TRUE,
  ylab_dots = "Mean of metapopulation growth rate",
  xlab_dots = "Variance of metapopulation growth rate",
  ylab_bars = "Percentage",
  xlab_bars = "Variance (multiplied by 1000)",
  port_cols = c("grey50", "red"),
  pch = 19,
  ...
)

Arguments

port_vals

A matrix of means and variances (down the two columns). This likely comes from the output of monte_carlo_portfolios.

weights_matrix

The same weight matrix that was passed to monte_carlo_portfolios.

pal

Colour palette for the stocks/assets in the barplot.

plot

Logical: should the plots be made?

ylab_dots

Y axis label for the mean-variance scatterplot.

xlab_dots

X axis label for the mean-variance scatterplot.

ylab_bars

Y axis label for the barplot.

xlab_bars

X axis label for the barplot.

port_cols

Colours for the dots. A vector of colours for the non-efficient and efficient portfolios.

pch

Dot type

...

Anything else to pass to both plot.default and barplot.

Value

A two panel plot and an (invisible) list of values calculated within the function. This list contains pv (mean, variance, and whether it was part of the efficient frontier); ef_port_ids (the portfolio IDs [run numbers] that are part of the efficient frontier; min_var_port_id (the portfolio ID for the minimum-variance portfolio); ef_weights (the weights of the portfolios on the efficient frontier).

Examples

## Not run: 
weights_matrix <- create_asset_weights(n_pop = 6, n_sims = 3000,
weight_lower_limit = 0.001)
mc_ports <- monte_carlo_portfolios(weights_matrix = weights_matrix,
 n_sims = 3000, mean_b = 1000)

col_pal <- rev(gg_color_hue(6))
ef_dat <- plot_efficient_portfolios(port_vals = mc_ports$port_vals,
 pal = col_pal, weights_matrix = weights_matrix)
names(ef_dat)

## End(Not run)

metafolio documentation built on Oct. 21, 2023, 1:06 a.m.