Hi,
Can you please explain me why with monthly returns I have Look Ahead Bias even with using a lag , and not with daily returns, following code snippet is just example to reproduce my problem ?
###########################################
# Daily returns DO NOT generate Look Ahead Bias #
###########################################
slideFunct <- function(rets, window, step){
sd_data <- na.omit(rollapply(rets, width = window, FUN = sd, na.rm = TRUE, align = “right”))
final <- sd_data
final$TYa <- sd_data$TYa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
final$USHYa <- sd_data$USHYa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
final$BNKa <- sd_data$BNKa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
return(na.omit(final))
}
portfolioPayout = function(rets){
weights = slideFunct(rets, window = 3, step = 1)
return(weights)
}
portStrat = portfolio(list(“TYa”,“USHYa”,“BNKa”)) %>%
payout(portfolioPayout) %>%
evaluate()
analyse(portStrat)
stressTest(portStrat)
#########################################
# Monthly returns GENERATE Look Ahead Bias #
#########################################
slideFunct <- function(rets, window, step){
data <- to.monthly(rets, indexAt = “last”, OHLC = FALSE)
data <- na.omit(lag(data))
sd_data <- na.omit(rollapply(data, width = window, FUN = sd, na.rm = TRUE, align = “right”))
final <- sd_data
final$TYa <- sd_data$TYa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
final$USHYa <- sd_data$USHYa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
final$BNKa <- sd_data$BNKa / (sd_data$TYa + sd_data$USHYa + sd_data$BNKa)
return(na.omit(final))
}
portfolioPayout = function(rets){
weights = slideFunct(rets, window = 3, step = 1)
return(weights)
}
portStrat = portfolio(list(“TYa”,“USHYa”,“BNKa”)) %>%
payout(portfolioPayout) %>%
evaluate()
analyse(portStrat)
stressTest(portStrat)