calc_metrics: Calculate Performance Metrics

Description Usage Arguments Value Examples

View source: R/calc_metrics.R

Description

Useful for comparing funds on one or more metrics.

Usage

1
2
3
4
5
6
7
8
calc_metrics(
  gains = NULL,
  metrics = c("cagr", "mdd", "mean", "sd", "sharpe", "alpha.annualized", "beta", "r"),
  prices = NULL,
  tickers = NULL,
  ...,
  benchmark = "SPY"
)

Arguments

gains

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

metrics

Character vector specifying metrics to calculate. Choices are "cagr" for compound annualized growth rate, "mdd" for max drawdown, "mean", "sd", "sharpe", "growth.x" for growth of $x where x is the initial value, "growth" for percent growth, "sortino", "alpha", "alpha.annualized", "beta", "r.squared", "pearson" or "spearman" for Pearson/Spearman correlation with benchmark, and "auto.pearson" or "auto.spearman" for Pearson/Spearman autocorrelation.

prices

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

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.

benchmark

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

Value

Data frame with performance metrics for each investment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Not run: 
# Calculate performance metrics for FANG stocks since the beginning of 2019
calc_metrics(tickers = fang, from = "2019-01-01")

# Repeat, but use step-by-step approach with piping (need SPY to calculate
# alpha and beta)
c("SPY", fang) %>%
  load_gains(from = "2019-01-01") %>%
  calc_metrics()

## End(Not run)

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