dateGenerator

首发版本:3.00.6

语法

dateGenerator(date, period, calendar, [businessDayConvention="Following"], [endOfMonth=false])

详情

根据指定的参考日期、期限、交易日历和工作日调整规则生成新的日期。

适用于金融场景中按交易日历计算到期日、结算日、支付日等日期。函数会先基于 dateperiodcalendar 计算目标日期,再根据 businessDayConventionendOfMonth 对结果进行调整。

参数

date DATE 类型标量,表示参考日期。

period DURATION 类型标量或向量,表示推进期限,支持日、周、月、年。

calendar STRING 类型标量,表示交易日历。

businessDayConvention 可选参数,STRING 类型标量,用于指定当计算结果落在非交易日时的调整方式。可选值包括:

  • Following:默认值,调整到下一个交易日。
  • ModifiedFollowing:调整到之后的第一个交易日;若该日期跨月,则调整到之前的第一个交易日。
  • Preceding:调整到上一个交易日。
  • ModifiedPreceding:调整到之前的第一个交易日;若该日期跨月,则调整到之后的第一个交易日。
  • Unadjusted:不调整。
  • HalfMonthModifiedFollowing:调整到之后的第一个交易日;若该日期跨过当月 15 日或月末,则调整到之前的第一个交易日。
  • Nearest:调整到距离最近的交易日;若前后交易日距离相同,则默认调整到之后的交易日。

endOfMonth 可选参数,BOOL 类型标量,表示是否启用月终惯例,即当起始日是某一个月的最后工作日时,调整后的结束日也为某一个月的最后工作日。默认值为 false。

返回值

period 为标量时,返回 DATE 类型标量;当 period 为向量时,返回 DATE 类型向量。

例子

例1. 基本日期推进。

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

例2. 当计算结果落在非交易日时,通过参数 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

例3. 当 date 为月末时,使用 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

相关函数:scheduleGenerator, yearFrac