Skip to main content

Rule syntax

Calendar rules are plain English, but they follow a grammar: an ANTLR 4 grammar for holiday rules (HolidayRule.g4) and one for expiry and delivery rules (ExpiryRule.g4). The Syntax guide tab of the Calendar Manager has this page's tables, examples you can add to the open calendar, and both grammars.

The Syntax guide tab with holiday rules on the left and expiry rules on the right

Write one rule a line. Grammar words are in small letters; month and day names can start with a capital or a small letter.


Holiday rules​

KindFormExample
Fixed date (actual)DAY with st, nd, rd or th, of MONTH25th of December named 'Christmas Day'
Nth weekday (ordinal)First, Second, Third or Fourth WEEKDAY in MONTHFirst Monday in May named 'Early May Bank Holiday'
Last weekdayLast WEEKDAY in MONTHLast Monday in August named 'Summer Bank Holiday'
Last but one weekdayPenultimate WEEKDAY in MONTHPenultimate Friday in November named 'Staff day'
Weekly closureEvery WEEKDAYEvery Saturday
Easter and related (named)Easter Sunday, Easter Monday, Good Friday, Maundy Thursday, Ascension Day, Pentecost, Whit Monday, Corpus Christi, Victoria DayGood Friday

A fixed date, nth, last or penultimate rule can have a name: named and the name in single quotes. The name ends at the next single quote, so write an apostrophe as a typographic apostrophe (U+2019).

Options​

Add options after the rule, separated by spaces or and.

OptionMeaningExample
on Saturday shift N daysWhen it falls on a Saturday, move it N days (also Sunday, Monday, Tuesday, Wednesday, Thursday, Friday)on Saturday shift 2 days and on Sunday shift 1 day
shift N daysAlways move it, for example a day a fixed number of days from EasterEaster Sunday shift 49 days
from YEAROnly from this yearfrom 2027
to YEAROnly up to this year. A one-off holiday is from and to the same year.8th of May named 'VE Day 75' from 2020 to 2020
repeating every N yearsOnly every N yearsrepeating every 4 years starting 2024
starting YEARThe first year of a repeating holiday

Expiry and delivery rules​

An expiry rule starts at the first day of the contract's period and moves to the last trading day, one step at a time, with then between steps. A delivery rule says when delivery starts or ends.

STEP then STEP ... (except if | unless CONDITION then STEP ...) (for TENOR) (before | after yyyy-mm-dd)
delivery starts | ends on the PLACE then STEP ... (for TENOR)

Steps​

StepMeaningExample
go to the PLACE of the previous, current or next PERIODPLACE is beginning, end, a day such as 15th, last WEEKDAY, penultimate WEEKDAY or last trading day. Add using calendar to move back to a business day.go to the end of the previous month
go back or go forward N PERIODSMove by N periods. With days using calendar, N business days of the trading calendar. From a date that is not a business day, the count starts from the business day before it (after it, going forward); add without aligning to count from the date itself.go back 2 days using calendar without aligning
alignMove back to the nearest business day; align forwards moves forwardgo to the 15th of the previous month then align

PERIOD is one of day, calendar day, week, weekend, month, quarter, season, halfyear, year, hour, half hour, quarter hour, first halfmonth, second halfmonth, with an s for more than one.

tip

Write days in the plural with using calendar to count business days, even for one day: go back 1 days using calendar. With the singular, the date moves one calendar day and is then aligned, which is not always the same.

caution

Mind where the count starts. For the TTF rule two business days before the first day of the delivery month, go to the beginning of the current month then go back 2 days using calendar gives 23 December 2026 for the January 2027 contract when 1 January, 31 December and 28 December are closed: it first moves back to the business day before 1 January (30 December) and counts from there. ... go back 2 days using calendar without aligning counts from 1 January itself and gives 29 December. The trace shows which one a rule does.

Exceptions​

ConditionTrue whenExample
there is a holiday within N days before or afterA holiday is within N days of the date reachedexcept if there is a holiday within 1 days after then go back 1 days using calendar
there is a non-business day within N days before or afterAny non-business day is within N days
the last day of the PERIOD is a WEEKDAYAlso the first day of theunless the last day of the month is a Saturday then ...
the month is NThe contract's month (1 to 12)unless the month is 12 then go back 5 days using calendar

except if carries on from the date reached and adds the steps after then. unless goes back to the start of the contract and uses the steps after then instead.

Tenors and time limits​

EndingMeaning
for monthsThe rule is for month contracts only. Also for days, for weekends, for weeks, for quarters, for seasons, for halfyears, for years, for balance and for all. A rule with no for is for every tenor.
before 2026-01-01Only for contracts that start before this date
after 2025-12-31Only for contracts that start after this date

A pair of rules with before and after the same date lets a calendar follow a market that changed its expiry rule.

note

There is no for hours. Hour, half hour and quarter hour contracts use the rules with no for. The grammar accepts for hours, but the platform reads it as every tenor, so the rule details under it show applies to all tenors. Give an intraday calendar a rule with no for, such as go back 1 hours, and put for months and so on on the rules of the longer tenors.

Examples​

RuleWhat it gives
go to the beginning of the current month then go back 2 days using calendar without aligning for monthsTwo business days before delivery starts, counted from the 1st (TTF month contracts)
go to the end of the previous month then go back 1 days using calendarOne business day before the end of the month before delivery
go to the last Friday of the previous month then alignThe last Friday of the month before, or the business day before it
go to the end of the previous quarter then go back 2 days using calendar for quartersQuarter contracts
go back 1 hoursHour contracts: an hour before delivery starts. Also go back 2 half hours, go back 3 quarter hours.
go back 1 days using calendar for daysDay contracts: the business day before
delivery starts on the 1st of the current monthDelivery starts on the first of the month
delivery ends on the last trading day of the current monthDelivery ends on the contract's expiry

The grammars​

The grammars are part of the platform's calendar module (odsl-calendar, in src/main/resources). The Syntax guide tab shows the version the extension was published with, under The holiday rule grammar and The expiry rule grammar.