Learn R Programming

PortfolioTesteR (version 0.1.4)

analyze_vs_benchmark: Benchmark-relative performance statistics

Description

Computes standard benchmark-relative metrics (e.g., correlation, beta, alpha, tracking error, information ratio) by aligning portfolio returns with benchmark returns derived from prices.

Usage

analyze_vs_benchmark(
  portfolio_returns,
  benchmark_prices,
  dates,
  benchmark_symbol = "SPY"
)

Value

A list or data frame with benchmark-relative statistics according to the package's conventions, including correlation, beta, alpha, tracking error, and information ratio.

Arguments

portfolio_returns

A numeric vector of portfolio simple returns aligned to dates.

benchmark_prices

A data frame (Date + symbols) of adjusted benchmark prices at the same cadence as dates.

dates

A vector of Date values used to align portfolio_returns with benchmark_prices.

benchmark_symbol

Character scalar giving the column name (symbol) in benchmark_prices to use as the benchmark.

Examples

Run this code
# \donttest{
  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
# }

Run the code above in your browser using DataLab