library(dplyr)
# Single Column | Multiple Rolling Windows
FANG %>%
select(symbol, date, adjusted) %>%
group_by(symbol) %>%
tk_augment_slidify(
.value = contains("adjust"),
# Multiple rolling windows
.period = c(10, 30, 60, 90),
.f = mean,
.partial = TRUE,
.names = stringr::str_c("MA_", c(10, 30, 60, 90))
) %>%
ungroup()
# Multiple Columns | Multiple Rolling Windows
FANG %>%
select(symbol, date, adjusted, volume) %>%
group_by(symbol) %>%
tk_augment_slidify(
.value = c(adjusted, volume),
.period = c(10, 30, 60, 90),
.f = mean,
.partial = TRUE
) %>%
ungroup()
Run the code above in your browser using DataLab