metrics {stocks} | R Documentation |
Calculates any or all of the following: mean and standard deviation of gains; total growth and compound annualized growth rate; maximum drawdown; Sharpe ratio and Sortino ratio; alpha, beta, Pearson correlation, and Spearman correlation, using first investment as the benchmark; and Pearson and Spearman autocorrelation, defined as the correlation between subsequent gains for each investment.
metrics(tickers = NULL, ..., gains = NULL, prices = NULL, perf.metrics = c("mean", "sd", "growth", "cagr", "mdd", "sharpe", "sortino", "alpha", "beta", "r.squared", "pearson", "spearman", "auto.pearson", "auto.spearman"))
tickers |
Character vector of ticker symbols. |
... |
Arguments to pass along with tickers to |
gains |
Numeric matrix of gains (daily or otherwise), where each column has gains for a particular investment. |
prices |
Numeric matrix of prices (daily or otherwise), where each column has prices for a particular investment. |
perf.metrics |
Character vector indicating what metrics should be calculated. If it includes
|
If tickers input is specified, it gets passed to load.gains
to
load historical prices from Yahoo! Finance using the quantmod package
[1]. If gains
or prices
are specified, performance metrics are
calculated directly from that information.
A list containing a data frame with the performance metrics and a correlation matrix for gains for the various investments.
NA
Dane R. Van Domelen
1. Jeffrey A. Ryan (2016). quantmod: Quantitative Financial Modelling Framework. R package version 0.4-6, https://cran.r-project.org/package=quantmod.
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
gains.rate
, prices.rate
, sharpe.ratio
,
sortino.ratio
, rrr
# Calculate performance metrics for leveraged ETFs SSO and UPRO, using SPY # as benchmark for alpha and beta - "on the fly" method #metrics1 <- metrics(tickers = c("SPY", "SSO", "UPRO")) # Calculate same performance metrics, but specify gains input #gains <- load.gains(tickers = c("SPY", "SSO", "UPRO")) #metrics2 <- metrics(gains = gains) # Results are identical #all(metrics1$perf.metrics == metrics2$perf.metrics)