lagged_correlations: Lagged Correlations function

View source: R/lagged_correlations.R

lagged_correlationsR Documentation

Lagged Correlations function

Description

Calculate correlation beetwen two numeric vector x and y for lagged values of x. Both vectors need to have equal length.

Usage

lagged_correlations(x, y, max_lag = length(x) - 2, plot = TRUE)

Arguments

x

Numeric vector of asset prices or returns (to be lagged)

y

Numeric vector of asset prices or returns

max_lag

Max number of lags for vector x. Default set to lengt(x) - 2

plot

If TRUE plot correlation for each lag

Value

Numeric vector of correlations for different time lags.

Examples

tickers <- c('wig20', 'mwig40')
sapply(tickers
       ,stooq_download
       ,destination = 'datasets\\')
files <- list.files('datasets\\')
close_prices <- df_prices(files = files
                          ,source = 'datasets\\')
x <- close_prices[,2] %>%
  unlist()
y <- close_prices[,3] %>%
  unlist()
lagged_correlations(x, y, max_lag = 200)

pawel-wieczynski/PolishStock documentation built on March 23, 2022, 3:32 p.m.