library(dplyr)
library(tidyquant)
library(timetk)
options(max.print = 50)
# ---- HOLIDAYS & WEEKENDS ----
# Business Holiday Sequence
tk_make_holiday_sequence("2017-01-01", "2017-12-31", calendar = "NYSE")
tk_make_holiday_sequence("2017", calendar = "NYSE") # Same thing as above (just shorter)
# Weekday Sequence
tk_make_weekday_sequence("2017", "2018", remove_holidays = TRUE)
# Weekday Sequence + Removing Business Holidays
tk_make_weekday_sequence("2017", "2018", remove_holidays = TRUE)
# ---- COMBINE HOLIDAYS WITH MAKE FUTURE TIMESERIES FROM EXISTING ----
# - A common machine learning application is creating a future time series data set
# from an existing
# Create index of days that FB stock will be traded in 2017 based on 2016 + holidays
FB_tbl <- FANG %>% filter(symbol == "FB")
holidays <- tk_make_holiday_sequence(
start_date = "2016",
end_date = "2017",
calendar = "NYSE")
weekends <- tk_make_weekend_sequence(
start_date = "2016",
end_date = "2017")
# Remove holidays and weekends with skip_values
# We could also remove weekends with inspect_weekdays = TRUE
FB_tbl %>%
tk_index() %>%
tk_make_future_timeseries(length_out = 366,
skip_values = c(holidays, weekends))
Run the code above in your browser using DataLab