calc_metrics_123: Calculate Performance Metrics for Any Combination of...

Description Usage Arguments Value Examples

View source: R/calc_metrics_123.R

Description

Integrates calc_metrics, calc_metrics_2funds, and calc_metrics_3funds into a single function, so you can compare strategies of varying complexities.

Usage

1
2
3
4
5
6
7
8
9
calc_metrics_123(
  gains = NULL,
  metrics = c("mean", "sd"),
  tickers = NULL,
  ...,
  step = 1,
  prices = NULL,
  benchmark = "SPY"
)

Arguments

gains

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

metrics

Character vector specifying metrics to calculate. See ?calc_metrics for choices.

tickers

List where each element is a character vector of ticker symbols for a particular fund combination, e.g. list("BRK-B", c("SPY", "TLT"). Each set can contain 1-3 funds.

...

Arguments to pass along with tickers to load_gains.

step

Numeric value specifying fund allocation increments.

prices

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

benchmark

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

Value

Data frame with performance metrics for each portfolio at each allocation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## Not run: 
# Calculate CAGR vs. max drawdown for BRK-B, SPY/TLT, and VWEHX/VBLTX/VFINX
df <- calc_metrics_123(
  tickers = list("BRK-B", c("SPY", "TLT"), c("VWEHX", "VBLTX", "VFINX")),
  metrics = c("cagr", "mdd")
)
head(df)

# To plot, just pipe into plot_metrics_123
df %>%
  plot_metrics_123()

# Or bypass calc_metrics_123 altogether
plot_metrics_123(
  formula = cagr ~ mdd,
  tickers = list("BRK-B", c("SPY", "TLT"), c("VWEHX", "VBLTX", "VFINX"))
)

## End(Not run)

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