| calc_rolling_correlation | R Documentation |
Computes rolling correlations between each symbol and a benchmark series
(e.g., SPY) using simple returns over a fixed lookback window.
calc_rolling_correlation(
data,
benchmark_symbol = "SPY",
lookback = 60,
min_periods = NULL,
method = c("pearson", "spearman")
)
data |
A |
benchmark_symbol |
Character, the benchmark column name (default |
lookback |
Integer window size (>= 2) for rolling correlations. |
min_periods |
Minimum number of valid observations within the window
to compute a correlation. Default is |
method |
Correlation method, |
Returns are computed as simple returns (P_t - P_{t-1})/P_{t-1}.
Windows with fewer than min_periods valid pairs are marked NA.
A data.table with Date and one column per non-benchmark symbol,
containing rolling correlations. Insufficient data yields NAs.
calc_momentum(), calc_rolling_volatility()
data(sample_prices_weekly)
corr <- calc_rolling_correlation(
data = sample_prices_weekly,
benchmark_symbol = "SPY",
lookback = 20
)
head(corr)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.