I have a table with two columns in which values are stored and a column with a specified time horizon next to it. For this table I need a code that calculates the correlation between the first two columns for each row and the time horizon next to it is always to be used as the data length. I have already written this procedure for the standard deviation, I now need this type of code for the correlation.
Standardabweichung Anleihenrendite berechnen
data_new <- x8
Funktion zur Berechnung rollierenden Standardabweichung
calculate_rolling_sd <- function(data_new) {
data_new$Rolling_SD <- rollapply(data_new$exc_ret, width = data_new$window_size_1y, FUN = sd, fill = NA, align = "right")
return(data_new)
}
Berechnung rollierende Standardabweichung
bond_data <- calculate_rolling_sd(data_new)