dateGenerator
First introduced in version: 3.00.6
Syntax
dateGenerator(date, period, calendar,
[businessDayConvention="Following"], [endOfMonth=false])
Details
Generates a new date based on a specified reference date, period, trading calendar, and business day adjustment rules.
This function is suitable for financial scenarios where dates such as maturity, settlement, or payment dates need to be calculated according to a trading calendar. It first calculates the target date based on date, period, and calendar, then adjusts the result according to businessDayConvention and endOfMonth.
Arguments
date is a DATE scalar representing the reference date.
period is a DURATION scalar or vector representing the forward period. It supports days, weeks, months, and years.
calendar is a STRING scalar specifying the trading calendar.
businessDayConvention (optional) is a STRING scalar specifying how to adjust the result when it falls on a non-business day. It can take the following values:
- Following: Adjusts to the next business day. This is the default value.
- ModifiedFollowing: Adjusts to the first following business day, unless it falls in a different month, in which case the first preceding business day is used.
- Preceding: Adjusts to the preceding business day.
- ModifiedPreceding: Adjusts to the first preceding business day, unless it falls in a different month, in which case the first following business day is used.
- Unadjusted: Does not adjust the date.
- HalfMonthModifiedFollowing: Adjusts to the first following business day, unless it crosses the 15th or the end of the month, in which case the first preceding business day is used.
- Nearest: Adjusts to the nearest business day. If the preceding and following business days are equally far away, the following business day is used.
endOfMonth (optional) is a BOOL scalar indicating whether to apply the end-of-month convention. If the start date is the last business day of a month, the adjusted end date will also be the last business day of a month. The default value is false.
Returns
Returns a DATE scalar when period is a scalar, or a DATE vector when period is a vector.
Examples
Example 1: Basic date advancement.
dateGenerator(date=2026.01.30, period=1d, calendar="SSE")
// output: 2026.02.02
dateGenerator(date=2026.01.30, period=[1d, 1w, 1M, 6M], calendar="SSE")
// output: [2026.02.02, 2026.02.06, 2026.03.02, 2026.07.30]
dateGenerator(date=2026.01.30, period=1d, calendar="CFET")
// output: 2026.01.31
Example 2: Adjusting non-business days using businessDayConvention.
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Following")
// output: 2026.06.01
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="ModifiedFollowing")
// output: 2026.05.29
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Preceding")
// output: 2026.05.29
dateGenerator(date=2026.07.01, period=1M, calendar="SSE", businessDayConvention="Preceding")
// output: 2026.07.31
dateGenerator(date=2026.07.01, period=1M, calendar="SSE", businessDayConvention="ModifiedPreceding")
// output: 2026.08.03
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Unadjusted")
// output: 2026.05.30
dateGenerator(date=2026.08.01, period=2w, calendar="SSE", businessDayConvention="HalfMonthModifiedFollowing")
// output: 2026.08.14
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Nearest")
// output: 2026.05.29
Example 3: Applying the end-of-month convention using endOfMonth.
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Following", endOfMonth=false)
// output: 2026.06.01
dateGenerator(date=2026.04.30, period=1M, calendar="SSE", businessDayConvention="Following", endOfMonth=true)
// output: 2026.05.29
Related functions: scheduleGenerator, yearFrac
