Last updated: 2023-03-16.
tf_quant_finance.datetime.HolidayCalendar#
Represents a holiday calendar.
Provides methods for manipulating the dates taking into account the holidays, and the business day roll conventions. Weekends are treated as holidays.
Methods#
add_business_days
add_business_days(
date_tensor, num_days,
roll_convention=tf_quant_finance.datetime.BusinessDayConvention.NONE
)
Adds given number of business days to given dates.
Note that this is different from calling add_period_and_roll with
PeriodType.DAY. For example, adding 5 business days to Monday gives the next
Monday (unless there are holidays on this week or next Monday). Adding 5
days and rolling means landing on Saturday and then rolling either to next
Monday or to Friday of the same week, depending on the roll convention.
If any of the dates in date_tensor are not business days, they will be
rolled to business days before doing the addition. If roll_convention is
NONE, and any dates are not business days, an exception is raised.
Args:#
date_tensor: DateTensor of dates to advance from.num_days: Tensor of int32 type broadcastable todate_tensor.roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday.
Returns:#
The resulting DateTensor.
add_period_and_roll
add_period_and_roll(
date_tensor, period_tensor,
roll_convention=tf_quant_finance.datetime.BusinessDayConvention.NONE
)
Adds given periods to given dates and rolls to business days.
The original dates are not rolled prior to addition.
Args:#
date_tensor: DateTensor of dates to add to.period_tensor: PeriodTensor broadcastable todate_tensor.roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday.
Returns:#
The resulting DateTensor.
business_days_between
business_days_between(
from_dates, to_dates
)
Calculates number of business between pairs of dates.
For each pair, the initial date is included in the difference, and the final date is excluded. If the final date is the same or earlier than the initial date, zero is returned.
Args:#
from_dates: DateTensor of initial dates.to_dates: DateTensor of final dates, should be broadcastable tofrom_dates.
Returns:#
An int32 Tensor with the number of business days between the corresponding pairs of dates.
business_days_in_period
business_days_in_period(
date_tensor, period_tensor
)
Calculates number of business days in a period.
Includes the dates in date_tensor, but excludes final dates resulting from
addition of period_tensor.
Args:#
date_tensor: DateTensor of starting dates.period_tensor: PeriodTensor, should be broadcastable todate_tensor.
Returns:#
An int32 Tensor with the number of business days in given periods that start at given dates.
is_business_day
is_business_day(
date_tensor
)
Returns a tensor of bools for whether given dates are business days.
roll_to_business_day
roll_to_business_day(
date_tensor, roll_convention
)
Rolls the given dates to business dates according to given convention.
Args:#
date_tensor: DateTensor of dates to roll from.roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday.
Returns:#
The resulting DateTensor.
subtract_business_days
subtract_business_days(
date_tensor, num_days,
roll_convention=tf_quant_finance.datetime.BusinessDayConvention.NONE
)
Adds given number of business days to given dates.
Note that this is different from calling subtract_period_and_roll with
PeriodType.DAY. For example, subtracting 5 business days from Friday gives
the previous Friday (unless there are holidays on this week or previous
Friday). Subtracting 5 days and rolling means landing on Sunday and then
rolling either to Monday or to Friday, depending on the roll convention.
If any of the dates in date_tensor are not business days, they will be
rolled to business days before doing the subtraction. If roll_convention
is NONE, and any dates are not business days, an exception is raised.
Args:#
date_tensor: DateTensor of dates to advance from.num_days: Tensor of int32 type broadcastable todate_tensor.roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday.
Returns:#
The resulting DateTensor.
subtract_period_and_roll
subtract_period_and_roll(
date_tensor, period_tensor,
roll_convention=tf_quant_finance.datetime.BusinessDayConvention.NONE
)
Subtracts given periods from given dates and rolls to business days.
The original dates are not rolled prior to subtraction.
Args:#
date_tensor: DateTensor of dates to subtract from.period_tensor: PeriodTensor broadcastable todate_tensor.roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday.
Returns:#
The resulting DateTensor.