For each fund–index pair in fund_index_map, computes rolling, annualized
tracking differences over a backward-looking window of n_days calendar
days. Both log-return and CAGR forms are returned.
Arguments
- df
Data frame containing a date column, fund columns, and benchmark/index columns referenced in
fund_index_map.- n_days
Rolling lookback window in calendar days.
- fund_index_map
Named character vector mapping fund column names to their corresponding benchmark/index base column names.
- date_col
Name of the date column in
df. Defaults to"date". Must be of classDateand sorted in ascending order.- index_level
Which index level to use, one of
"net"or"gross". If"gross",gross_suffixis appended to the mapped index base name before lookup indf. Defaults to"net".- annual_days
Number of days used for annualization. Defaults to
365.- messages
Character vector controlling emitted messages. Any of
"roll"(per-pair progress) and"skip"(skip reasons). Usemessages = "roll"to show only progress,messages = "skip"to show only skip reasons, ormessages = character()orNULLto silence all messages. Defaults toc("roll", "skip").- gross_suffix
Suffix appended to the mapped index base name when
index_level = "gross". Defaults to"-GR".
Value
A named list with two data frames, log and cagr. Each data frame
contains date_col followed by one column per fund (named as in
fund_index_map), holding the rolling annualized tracking differences.
Details
For each date \(t\), an anchor date \(t_0\) is chosen as the last available observation at or before \(t - n\_days\) where both fund and index values are present. Let \(\Delta = t - t_0\) in calendar days.
The annualized tracking differences are:
Log-return difference: $$\left[\ln\left(\frac{f_t}{f_{t_0}}\right) - \ln\left(\frac{i_t}{i_{t_0}}\right)\right] \times \frac{annual\_days}{\Delta}$$
CAGR difference: $$\left(\frac{f_t}{f_{t_0}}\right)^{annual\_days/\Delta} - \left(\frac{i_t}{i_{t_0}}\right)^{annual\_days/\Delta}$$
Values are NA when an anchor cannot be found, required inputs are missing,
\(\Delta \le 0\), or values are invalid for the chosen formula (e.g.
non-positive inputs for log returns).