View source: R/performance_analytics.R
| analyze_vs_benchmark | R Documentation |
Computes standard benchmark-relative metrics (e.g., correlation, beta, alpha, tracking error, information ratio) by aligning portfolio returns with benchmark returns derived from prices.
analyze_vs_benchmark(
portfolio_returns,
benchmark_prices,
dates,
benchmark_symbol = "SPY"
)
portfolio_returns |
A numeric vector of portfolio simple returns aligned to |
benchmark_prices |
A data frame (Date + symbols) of adjusted benchmark prices at the
same cadence as |
dates |
A vector of |
benchmark_symbol |
Character scalar giving the column name (symbol) in |
A list or data frame with benchmark-relative statistics according to the package's conventions, including correlation, beta, alpha, tracking error, and information ratio.
data(sample_prices_weekly)
mom12 <- PortfolioTesteR::calc_momentum(sample_prices_weekly, lookback = 12)
sel10 <- PortfolioTesteR::filter_top_n(mom12, n = 5)
w_eq <- PortfolioTesteR::weight_equally(sel10)
pr <- PortfolioTesteR::portfolio_returns(w_eq, sample_prices_weekly)
# Use SPY as the benchmark
bench <- sample_prices_weekly[, c("Date", "SPY")]
res <- analyze_vs_benchmark(
pr$portfolio_return,
bench,
dates = pr$Date,
benchmark_symbol = "SPY"
)
res
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.