Learn R Programming

timetk (version 2.8.1)

tk_make_holiday_sequence: Make daily Holiday and Weekend date sequences

Description

Make daily Holiday and Weekend date sequences

Usage

tk_make_holiday_sequence(
  start_date,
  end_date,
  calendar = c("NYSE", "LONDON", "NERC", "TSX", "ZURICH"),
  skip_values = NULL,
  insert_values = NULL
)

tk_make_weekend_sequence(start_date, end_date)

tk_make_weekday_sequence( start_date, end_date, remove_weekends = TRUE, remove_holidays = FALSE, calendar = c("NYSE", "LONDON", "NERC", "TSX", "ZURICH"), skip_values = NULL, insert_values = NULL )

Value

A vector containing future dates

Arguments

start_date

Used to define the starting date for date sequence generation. Provide in "YYYY-MM-DD" format.

end_date

Used to define the ending date for date sequence generation. Provide in "YYYY-MM-DD" format.

calendar

The calendar to be used in Date Sequence calculations for Holidays from the timeDate package. Acceptable values are: "NYSE", "LONDON", "NERC", "TSX", "ZURICH".

skip_values

A daily date sequence to skip

insert_values

A daily date sequence to insert

remove_weekends

A logical value indicating whether or not to remove weekends (Saturday and Sunday) from the date sequence

remove_holidays

A logical value indicating whether or not to remove common holidays from the date sequence

Details

Start and End Date Specification

  • Accept shorthand notation (i.e. tk_make_timeseries() specifications apply)

  • Only available in Daily Periods.

Holiday Sequences

tk_make_holiday_sequence() is a wrapper for various holiday calendars from the timeDate package, making it easy to generate holiday sequences for common business calendars:

  • New York Stock Exchange: calendar = "NYSE"

  • Londo Stock Exchange: "LONDON"

  • North American Reliability Council: "NERC"

  • Toronto Stock Exchange: "TSX"

  • Zurich Stock Exchange: "ZURICH"

Weekend and Weekday Sequences

These simply populate

See Also

  • Intelligent date or date-time sequence creation: tk_make_timeseries()

  • Holidays and weekends: tk_make_holiday_sequence(), tk_make_weekend_sequence(), tk_make_weekday_sequence()

  • Make future index from existing: tk_make_future_timeseries()

Examples

Run this code
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