Last updated: 2023-03-16.
tf_quant_finance.datetime.random_dates#
Generates random dates between the supplied start and end dates.
tf_quant_finance.datetime.random_dates(
*, start_date, end_date, size=1, seed=None, name=None
)
Generates specified number of random dates between the given start and end
dates. The start and end dates are supplied as DateTensor objects. The dates
uniformly distributed between the start date (inclusive) and end date
(exclusive). Note that the dates are uniformly distributed over the calendar
range, i.e. no holiday calendar is taken into account.
Args:#
start_date: DateTensor of arbitrary shape. The start dates of the range from which to sample. The start dates are themselves included in the range.end_date: DateTensor of shape compatible with thestart_date. The end date of the range from which to sample. The end dates are excluded from the range.size: Positive scalar int32 Tensor. The number of dates to draw between the start and end date. Default value: 1.seed: Optional seed for the random generation.name: Optional str. The name to give to the ops created by this function. Default value: ‘random_dates’.
Returns:#
A DateTensor of shape [size] + dates_shape where dates_shape is the common broadcast shape for (start_date, end_date).
Example#
# Note that the start and end dates need to be of broadcastable shape (though
# not necessarily the same shape).
# In this example, the start dates are of shape [2] and the end dates are
# of a compatible but non-identical shape [1].
start_dates = tff.datetime.dates_from_tuples([
(2020, 5, 16),
(2020, 6, 13)
])
end_dates = tff.datetime.dates_from_tuples([(2021, 5, 21)])
size = 3 # Generate 3 dates for each pair of (start, end date).
sample = tff.datetime.random_dates(start_date=start_dates, end_date=end_dates,
size=size)
# sample is a DateTensor of shape [3, 2]. The [3] is from the size and [2] is
# the common broadcast shape of start and end date.