Exchange calendar
All plugins

Plugin libraryCalendar

Plugin

Exchange calendar

Holidays, early closes, the days around a holiday, the turn of the month and expiry days for NYSE, LSE, Xetra, Tokyo and FX, as feeds.

Data sourceNo networkDesktop onlyv1.0.0

About

Calendar effects are some of the oldest ideas in trading: the day before a holiday, the turn of the month, the week of an expiry. This plugin gives a strategy the calendar to test them, without any network: it computes each exchange's days from the published holiday rules, year by year, plus a dated list of one-off closures (11 September 2001, the funerals of presidents and of Queen Elizabeth II, Hurricane Sandy, the Tokyo system failure of October 2020).

Before a run it writes one feed per calendar: calendar_nyse, calendar_lse, calendar_xetra, calendar_jpx and calendar_fx. Each day holds an object:

  • open: whether the exchange trades that day; holiday: the name of the holiday on a closed weekday.
  • early_close and early_close_utc: the local and UTC time of a shortened session (NYSE 13:00, LSE 12:30), else None.
  • before_holiday, after_holiday: the last trading day before and the first after a holiday.
  • days_to_holiday, days_from_holiday: trading days in between (0 on the day before or after).
  • month_day, month_days_left: the trading day of the month counted from the start and the trading days still to come, for turn of month rules.
  • expiry, quarterly_expiry: the monthly index options expiry, the third Friday (the second Friday for Tokyo), moved to the trading day before when that Friday is a holiday.

calendar_fx has no exchange behind it: weekends, Christmas Day and New Year's Day are closed, and thin with a reason marks the days most of the market is away (24, 26 and 31 December, Good Friday, Easter Monday, US Thanksgiving and Independence Day).

The CME is not included: its holiday sessions differ by product and year. For US equity index futures, the NYSE calendar is a close guide to trade dates; the CME's shortened holiday sessions are not modelled.

Configuration

FieldTypeDefaultDescription
exchangesCalendars (nyse, lse, xetra, jpx, fx)string"nyse, lse, xetra, jpx, fx"Which calendars to write, separated by commas: nyse, lse, xetra, jpx, fx.
first_yearFirst yearnumbermin 2000, max 21002000The first year written. Xetra starts in 2012 whatever is set here, the first year of the official lists the plugin follows.

Use it in a strategy

pythonbars = ctx.bars(1)
if bars:
    day = ctx.data("calendar_nyse", bars[-1].ts)
    if day is not None and day["before_holiday"]:
        ctx.signal("EXIT")
    elif day is not None and day["month_days_left"] == 0:
        ctx.signal("LONG")

The calendars are written before a run whose strategy reads ctx.data, or when "Fetch external data (news and plugin feeds)" is ticked, and again only when the year or the plugin's rules change. No network is used. A run on the server never writes them.

What it provides

calendar_<exchange>FeedOne feed per calendar (calendar_nyse, calendar_lse, calendar_xetra, calendar_jpx), every calendar day from the first year to the end of next year, each an object with the fields above.
calendar_fxFeedThe FX days by UTC date: open, thin, reason, the holiday fields and the turn of the month; no expiry fields.

Data source and terms

When values are known

Each value sits under the day it describes, unlike the other feeds: holiday rules are published a year or more ahead, so the calendar of a day and the weeks after it was known before the day began. One-off closures (11 September 2001, a funeral, a storm) carry the day they were announced, and the forward looking fields (before_holiday, days_to_holiday, month_days_left, expiry) of a day count only the closures announced by then. On 10 September 2001 the feed does not know that the next day is closed. Where an exchange's own notice could not be dated, the announcement is taken as the day after the government order, or the day itself.

Limits

  • NYSE, LSE and Tokyo from 2000, Xetra from 2012. The rules were checked against the NYSE notices, gov.uk and the Japanese Cabinet Office list; a closure missing from the dated list would show as a trading day.
  • Next year's one-off closures cannot be known yet, and Xetra's list for a new year follows the usual eight days until Eurex publishes it.
  • Early closes only for NYSE (13:00 New York) and LSE (12:30 London); Tokyo's old half days and Xetra's shortened year end sessions are not included, nor are trading halts during a day.
  • The days are the exchange's own dates; a bar is matched by its UTC date, which is the same date during the regular session of all four exchanges, not for an evening futures session.
  • The FX thin days are a market convention, not a rule; brokers differ on which days they close.
OrionQuant