calc_metrics_overtime: Calculate Performance Metrics over Time

Description Usage Arguments Value Examples

View source: R/calc_metrics_overtime.R

Description

Useful for assessing how one or two performance metrics vary over time, for one or several funds. Supports fixed-width rolling windows, fixed-width disjoint windows, and disjoint windows on per-month or per-year basis.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
calc_metrics_overtime(
  gains = NULL,
  metrics = c("mean", "sd"),
  tickers = NULL,
  ...,
  type = "hop.year",
  minimum.n = 3,
  prices = 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. See ?calc_metrics for choices.

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.

type

Character string or vector specifying type of calculation. Choices are (1) "roll.n" where n is a positive integer; (2) "hop.n" where n is a positive integer; (3) "hop.month"; (4) "hop.year"; and (5) vector of break-point dates, e.g. c("2019-01-01", "2019-06-01") for 3 periods. The "roll" and "hop" options correspond to rolling and disjoint windows, respectively.

minimum.n

Integer value specifying the minimum number of observations per period, e.g. if you want to exclude short partial months at the beginning or end of the analysis period.

prices

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

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
## Not run: 
# Calculate annual CAGR's, MDD's, and Sharpe ratios for FANG stocks
calc_metrics_overtime(
  tickers = c("FB", "AAPL", "NFLX", "GOOG"),
  metrics = c("cagr", "mdd", "sharpe"),
  type = "hop.year"
)

## End(Not run)

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