I am trying to replicate the momentum strategy of the study by Jegadesh and Titman (1993) onyl using data from the past 10 years.I am trying right now to calculate the formation period returns. But I think I have some mistakes. If I go further and then form the portfolios, ranking them, all 4 portfolios show the same returns for each 1-10 ranks. I have a feeling that my mistakes is already here in the formation periods but I dont get it. Maybe somebody can help me a bit. thanks a lot! (the data_subset is my original data with all variables included)
formation_periods <- c(3, 6, 9, 12)
momentum_portfolios <- list()
for (formation_period in formation_periods) {
subset <- data_subset %>%
select(PERMNO, Date, Returns, logreturns) %>%
arrange(PERMNO, Date)
subset$sumlogret <- subset %>%
group_by(PERMNO) %>%
mutate(sumlogret = rollsum(logreturns, formation_period, align = "right", fill = NA)) %>%
ungroup() %>%
pull(sumlogret)
subset <- subset %>%
rename(sumlogreturns = logreturns)
subset$cumret <- exp(subset$sumlogreturns) - 1
momentum_portfolios[[paste0("Formation_", formation_period)]] <- subset
}
here is my following code where I realized that all formation periods have the same numbers in it.
momentum_portfolio <- momentum_portfolios[[paste0("Formation_", formation_period)]]
momentum_portfolio <- momentum_portfolio[!is.na(momentum_portfolio$cumret), ]
momentum_portfolio$momr <- as.numeric(factor(momentum_portfolio$cumret, levels = unique(momentum_portfolio$cumret)))
momentum_portfolio$momr <- cut(momentum_portfolio$cumret, breaks = quantile(momentum_portfolio$cumret, probs = seq(0, 1, by = 0.1)), labels = FALSE)
cat("Formation Period:", formation_period, "\n")
cat("Examine distribution of cumret by momr:\n")
print(tapply(momentum_portfolio$cumret, momentum_portfolio$momr, mean))
}
tail(momentum_portfolio)
```