plot_metrics_3funds: Plot One Performance Metric vs. Another for 3-Fund Portfolios

Description Usage Arguments Value Examples

View source: R/plot_metrics_3funds.R

Description

Useful for visualizing the behavior of one or several 3-fund portfolios, e.g. by plotting a measure of growth vs. a measure of volatility.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
plot_metrics_3funds(
  metrics = NULL,
  formula = mean ~ sd,
  tickers = NULL,
  ...,
  step = 2.5,
  gains = NULL,
  prices = NULL,
  benchmark = "SPY",
  y.benchmark = benchmark,
  x.benchmark = benchmark,
  ref.tickers = NULL,
  plotly = FALSE,
  title = NULL,
  base_size = 16,
  label_size = 5,
  return = "plot"
)

Arguments

metrics

Data frame with Fund column and column for each metric you want to plot. Typically the result of a prior call to calc_metrics_3funds.

formula

Formula specifying what to plot, e.g. mean ~ sd, cagr ~ mdd, or sharpe ~ allocation. See ?calc_metrics for list of metrics to choose from ("allocation" is an extra option here). If you specify metrics, default behavior is to use mean ~ sd unless either is not available, in which case the first two performance metrics that appear as columns in metrics are used.

tickers

Character vector of ticker symbols, where the first three are are a 3-fund set, the next three are another, and so on.

...

Arguments to pass along with tickers to load_gains.

step

Numeric value specifying fund allocation increments.

gains

Data frame with a date variable named Date and one column of gains for each fund.

prices

Data frame with a date variable named Date and one column of prices for each fund.

benchmark, y.benchmark, x.benchmark

Character string specifying which fund to use as benchmark for metrics (if you request alpha, alpha.annualized, beta, or r.squared).

ref.tickers

Character vector of ticker symbols to include on the graph.

plotly

Logical value for whether to convert the ggplot to a plotly object internally.

title

Character string.

base_size

Numeric value.

label_size

Numeric value.

return

Character string specifying what to return. Choices are "plot", "data", and "both".

Value

Depending on return, a ggplot object, a data frame, or a list containing both.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# Plot mean vs. SD for UPRO/VBLTX/VWEHX
plot_metrics_3funds(
  formula = mean ~ sd,
  tickers = c("UPRO", "VBLTX", "VWEHX")
)

# Plot CAGR vs. max drawdown for FB/AAPL/NFLX and SPY/TLT/JNK
plot_metrics_3funds(
  formula = cagr ~ mdd,
  tickers = c("FB", "AAPL", "NFLX", "SPY", "TLT", "JNK")
)

# Plot Sharpe ratio vs. allocation for the same sets
plot_metrics_3funds(
  formula = sharpe ~ allocation,
  tickers = c("FB", "AAPL", "NFLX", "SPY", "TLT", "JNK")
)

## End(Not run)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.