alma_step {almanac}R Documentation

Step relative to an rschedule

Description

alma_step() is useful for shifting dates by "n business days".

alma_step() steps over a sequence of dates 1 day at a time, for n days. After each step, an adjustment is applied to shift to the next non-event date.

Usage

alma_step(x, n, rschedule)

Arguments

x

[Date]

A vector of dates.

n

[integer]

The number of days to step. Can be negative to step backwards.

rschedule

[rschedule]

An rschedule, such as an rrule or rbundle.

Details

Imagine you are on a Friday and want to shift forward 2 days using an rrule that marks weekends as events. alma_step() works like this:

This lends itself naturally to business logic. Two business days from Friday is Tuesday.

Value

A Date vector the same size as x shifted by n steps.

Examples

# Make a rrule for weekends
on_weekends <- weekly() %>%
  recur_on_weekends()

# "Step forward by 2 business days"
# 2019-09-13 is a Friday.
# Here we:
# - Step 1 day to Saturday
# - Adjust to Monday
# - Step 1 day to Tuesday
alma_step("2019-09-13", 2, on_weekends)

# If Monday, 2019-09-16, was a recurring holiday, we could create
# a custom runion and step over that too.
on_09_16 <- yearly() %>%
  recur_on_ymonth(9) %>%
  recur_on_mday(16)

rb <- runion() %>%
  add_rschedule(on_09_16) %>%
  add_rschedule(on_weekends)

alma_step("2019-09-13", 2, rb)

[Package almanac version 0.1.1 Index]