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.
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)
Character vector of ticker symbols that Yahoo! Finance recognizes, if you want to download data on the fly.
Numeric vector of values to add to daily gains for each ticker.
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
.
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")
.
Character vector of ticker symbols to include on graph as data points for comparative purposes.
Numeric matrix of gains, where each column has gains for a particular fund.
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.
Numeric vector or matrix of gains for funds to include on graph as data points for comparative purposes.
Numeric value specifying allocation increments for plotting curves.
Numeric value specifying allocation increments for adding
data points on top of curves. Set to NULL
to suppress data points.
Numeric value specifying allocation increments for first fund in each set.
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.
Same as x.metric
, but for the y-axis
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.
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.
Logical value for whether to add plot data to current plot frame rather than open a new one.
Character vector of colors for each curve.
Numeric vector specifying line types for each curve.
List of arguments to pass to plot
.
List of arguments to pass to
points
.
List of arguments to pass to text
.
List of arguments to pass to pdf
.
List of arguments to pass to bmp
.
List of arguments to pass to jpeg
.
List of arguments to pass to png
.
List of arguments to pass to tiff
.
In addition to the graph, a list containing:
List named portfolio.xy
where each element is a two-column
matrix of x- and y-axis values for a curve.
Numeric vector named means
with mean gains for each fund.
Numeric matrix named corr.matrix
with a correlation matrix for
gains for each fund.
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.
# 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"))
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab