plot_metrics: Plot One Performance Metric (Sorted Bar Plot) or One vs....

Description Usage Arguments Value References Examples

View source: R/plot_metrics.R

Description

Useful for visualizing the performance of individual funds. For 2- and 3-fund portfolios, see plot_metrics_2funds and plot_metrics_3funds. To visualize any combination of single funds and 2- and 3-fund portfolios, see link{plot_metrics_123}.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
plot_metrics(
  metrics = NULL,
  formula = cagr ~ mdd,
  tickers = NULL,
  ...,
  gains = NULL,
  prices = NULL,
  benchmark = "SPY",
  y.benchmark = benchmark,
  x.benchmark = benchmark,
  plotly = FALSE,
  title = NULL,
  base_size = 16,
  label_size = 5,
  ticklabel_size = 8,
  return = "plot"
)

Arguments

metrics

"Long" data frame with Fund column and column for each metric you want to plot. Typically the result of a prior call to calc_metrics.

formula

Formula specifying what to plot, e.g. cagr ~ mdd for CAGR vs. MDD, cagr ~ . for just CAGR, or . ~ mdd for just MDD. See ?calc_metrics for list of metrics to choose from.

tickers

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

...

Arguments to pass along with tickers to load_gains.

gains

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

prices

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

benchmark

Character string specifying which fund to use as a benchmark for metrics that require one.

y.benchmark

Character string specifying which fund to use as benchmark for y-axis metric.

x.benchmark

Character string specifying which fund to use as benchmark for x-axis metric.

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.

ticklabel_size

Numeric value.

return

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

Value

Depending on return, a ggplot, a data frame with the source data, or a list containing both.

References

Jeffrey A. Ryan and Joshua M. Ulrich (2019). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-15. https://CRAN.R-project.org/package=quantmod

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
# Plot Sharpe ratio for FANG stocks
plot_metrics(formula = sharpe ~ ., tickers = fang)

# Create previous plot in step-by-step process with pipes
fang %>%
  load_gains() %>%
  calc_metrics("sharpe") %>%
  plot_metrics(. ~ sharpe)

# Plot CAGR vs. max drawdown for SPY and BRK-B
plot_metrics(formula = cagr ~ mdd, tickers = c("SPY", "BRK-B"))

# Create previous plot in step-by-step process with pipes
c("SPY", "BRK-B") %>%
  load_gains() %>%
  calc_metrics("cagr", "mdd") %>%
  plot_metrics(cagr ~ mdd)

## End(Not run)

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