threefunds_graph: Graph One Performance Metric vs. Another for Three-Fund...

Description Usage Arguments Value References Examples

View source: R/threefunds_graph.R

Description

Useful for visualizing performance of three-fund portfolios, typically by plotting a measure of growth vs. a measure of volatility. Only works for one three-fund set at a time.

Usage

1
2
3
4
5
6
7
8
9
threefunds_graph(tickers = NULL, intercepts = NULL, slopes = NULL, ...,
  benchmark.tickers = NULL, reference.tickers = NULL,
  tickers.gains = NULL, benchmark.gains = NULL, reference.gains = NULL,
  step.data = 0.0025, step.points = 0.1, step.curves = 0.2,
  x.metric = "sd", y.metric = "mean", tickerlabel.offsets = NULL,
  reflabel.offsets = NULL, add.plot = FALSE, colors = NULL, lty = NULL,
  plot.list = NULL, points.list = NULL, text.list = NULL,
  pdf.list = NULL, bmp.list = NULL, jpeg.list = NULL, png.list = NULL,
  tiff.list = NULL)

Arguments

tickers

Character vector of ticker symbols that Yahoo! Finance recognizes, if you want to download data on the fly.

intercepts

Numeric vector of values to add to daily gains for each ticker.

slopes

Numeric vector of values to multiply daily gains for each ticker by. Slopes are multiplied prior to adding intercepts.

...

Arguments to pass along with tickers to load_gains.

benchmark.tickers

Character vector of length 1 or 2 indicating ticker symbols for benchmark indexes. Only used if x.metric and/or y.metric require benchmark indexes to calculate. For example, to plot correlation with SPY on the x-axis and correlation with TLT on the y-axis, set x.metric = "pearson", y.metric = "pearson2" (i.e. Pearson correlation with 2nd benchmark), and benchmark.tickers = c("SPY", "TLT").

reference.tickers

Character vector of ticker symbols to include on graph as data points for comparative purposes.

tickers.gains

Numeric matrix of gains, where each column has gains for a particular fund.

benchmark.gains

Numeric vector or matrix of gains for 1 or 2 benchmark indexes. Only used if x.metric and/or y.metric require benchmark indexes to calculate. For example, to plot correlation with SPY on the x-axis and correlation with TLT on the y-axis, set x.metric = "pearson" and y.metric = "pearson2", and input benchmark.gains as a 2-column matrix of gains for SPY and TLT.

reference.gains

Numeric vector or matrix of gains for funds to include on graph as data points for comparative purposes.

step.data

Numeric value specifying allocation increments for plotting curves.

step.points

Numeric value specifying allocation increments for adding data points on top of curves. Set to NULL to suppress data points.

step.curves

Numeric value specifying allocation increments for first fund in each set.

x.metric

Character string specifying x-axis performance metric. Choices are:

"mean" or "sd" for mean or standard deviation of gains

"growth" or "cagr" for total or annualized growth

"mdd" for maximum drawdown

"sharpe" or "sortino" for Sharpe or Sortino ratio

"alpha", "beta", or "r.squared" for those metrics from a fitted linear regression on benchmark fund

"pearson" or "spearman" for Pearson or Spearman correlation with benchmark fund

"alpha2", "beta2", "r.squared2", "pearson2", or "spearman2" for same as previously described, but using the second benchmark index

"auto.pearson" or "auto.spearman" for Pearson or Spearman autocorrelation, defined as the correlation between subsequent gains

"allocation" for allocation to first fund in each pair.

y.metric

Same as x.metric, but for the y-axis

tickerlabel.offsets

Either a numeric vector of length 2 giving the x- and y-axis offsets for all ticker labels, or a 2-column matrix where each row gives the x- and y-axis offsets for a ticker.

reflabel.offsets

Either a numeric vector of length 2 giving the x- and y-axis offsets for all reference ticker labels, or a 2-column matrix where each row gives the x- and y-axis offsets for a reference ticker.

add.plot

Logical value for whether to add plot data to current plot frame rather than open a new one.

colors

Character vector of colors for each curve.

lty

Numeric vector specifying line types for each curve.

plot.list

List of arguments to pass to plot.

points.list

List of arguments to pass to points.

text.list

List of arguments to pass to text.

pdf.list

List of arguments to pass to pdf.

bmp.list

List of arguments to pass to bmp.

jpeg.list

List of arguments to pass to jpeg.

png.list

List of arguments to pass to png.

tiff.list

List of arguments to pass to tiff.

Value

In addition to the graph, a list containing:

  1. List named portfolio.xy where each element is a two-column matrix of x- and y-axis values for a curve.

  2. Numeric vector named means with mean gains for each fund.

  3. Numeric matrix named corr.matrix with a correlation matrix for gains for each fund.

References

Ryan, J.A. and Ulrich, J.M. (2017) quantmod: Quantitative Financial Modelling Framework. R package version 0.4-12, https://CRAN.R-project.org/package=quantmod.

Examples

1
2
3
4
5
6
7
## Not run: 
# Plot mean vs. SD for UPRO/VBLTX/VWEHX portfolio, and compare to VFINX and 
# BRK-B
fig <- threefunds_graph(tickers = c("VWEHX", "VBLTX", "UPRO"), 
                        reference.tickers = c("VFINX", "BRK-B"))

## End(Not run)

vandomed/stocks documentation built on Sept. 2, 2018, 10:10 a.m.