Skip to content

Commit 374792b

Browse files
authored
Merge pull request #479 from Nick-Lafky/nse-calendar-overhaul
Overhaul NSE calendar: holidays, era-dependent hours, Muhurat sessions, 2021 outage
2 parents 2b2dcb9 + 20cbe68 commit 374792b

7 files changed

Lines changed: 971 additions & 29 deletions

File tree

‎docs/change_log.rst‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ Change Log
33

44
Unreleased
55
~~~~~~~~~~
6-
- Update TASE calendar for the Monday-Friday trading week effective 2026-01-05
7-
- change the weekmask from Sun-Thu to Mon-Fri with the crossover handled in ``valid_days`` (last Sunday session 2026-01-04), following the NYSE pre/post-1952 pattern
8-
- add the 2026 and 2027 holiday closures (the previous list ended in 2025, so all 2026 holidays were treated as trading days)
9-
- add the Friday early close at 13:34 Asia/Jerusalem
10-
- add native TASE calendar tests (``tests/test_tase_calendar.py``)
6+
- Overhaul the NSE (India) calendar and give it its own holiday list and modules
7+
(``calendars/nse.py``, ``holidays/nse.py``; ``calendars/bse.py`` keeps
8+
backward-compatible re-exports) (#479)
9+
10+
- NSE-specific holiday list covering 1996-2026, verified against NSE circulars
11+
and observed market activity
12+
- era-dependent regular hours (9:55 AM open until 2010, 9:00 AM during the 2010
13+
pre-open pilot, 9:15 AM since 2010-10-18, plus the documented 1997-1999 changes)
14+
- weekday Muhurat trading sessions modeled as special opens/closes with the
15+
announced timings per year instead of holidays
16+
- the 2021-02-24 trading halt modeled as a special close plus an interruption
1117

1218
5.4.0 (05/25/2026)
1319
~~~~~~~~~~~~~~~~~~

‎pandas_market_calendars/calendar_registry.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from .market_calendar import MarketCalendar
66
from .calendars.asx import ASXExchangeCalendar
77
from .calendars.bmf import BMFExchangeCalendar
8-
from .calendars.bse import BSEExchangeCalendar, NSEExchangeCalendar
8+
from .calendars.bse import BSEExchangeCalendar
9+
from .calendars.nse import NSEExchangeCalendar
910
from .calendars.cboe import CFEExchangeCalendar
1011
from .calendars.cme import (
1112
CMEEquityExchangeCalendar, CMEBondExchangeCalendar, CMETradeDateCalendar

‎pandas_market_calendars/calendars/bse.py‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,6 @@
427427
Timestamp("2026-12-25", tz="UTC"), # Fri, Christmas
428428
]
429429

430-
# BSE and NSE currently share the same published closure set in this module.
431-
# Keep this as a shared object so future exchange-specific deltas are explicit.
432-
NSEClosedDay = BSEClosedDay
433-
434430

435431
class BSEExchangeCalendar(MarketCalendar):
436432
"""
@@ -466,21 +462,6 @@ def adhoc_holidays(self) -> List[Any]:
466462
return BSEClosedDay
467463

468464

469-
class NSEExchangeCalendar(BSEExchangeCalendar):
470-
"""
471-
Exchange calendar for the National Stock Exchange of India (NSE, XNSE).
472-
"""
473-
474-
aliases = ["NSE", "XNSE"]
475-
476-
@property
477-
def name(self) -> str:
478-
return "NSE"
479-
480-
@property
481-
def full_name(self) -> str:
482-
return "National Stock Exchange of India"
483-
484-
@property
485-
def adhoc_holidays(self) -> List[Any]:
486-
return NSEClosedDay
465+
# Re-exported for backward compatibility; NSE lives in calendars/nse.py.
466+
from pandas_market_calendars.calendars.nse import NSEExchangeCalendar # noqa: E402, F401
467+
from pandas_market_calendars.holidays.nse import NSEClosedDay # noqa: E402, F401
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
"""
2+
National Stock Exchange of India (NSE, XNSE).
3+
"""
4+
5+
from datetime import time
6+
from typing import Any, List
7+
8+
from zoneinfo import ZoneInfo
9+
10+
from pandas_market_calendars.holidays.nse import NSEClosedDay
11+
from pandas_market_calendars.market_calendar import MarketCalendar
12+
13+
14+
class NSEExchangeCalendar(MarketCalendar):
15+
"""
16+
Exchange calendar for the National Stock Exchange of India (NSE, XNSE).
17+
18+
Coverage is 1996 through 2026. Holidays and special sessions are curated
19+
from NSE circulars, contemporaneous press coverage of exchange
20+
announcements, and observed market activity. Outside this range no
21+
holidays or special sessions are defined and the nearest era's regular
22+
hours apply.
23+
24+
Regular hours are era-dependent: a 9:55 AM IST open until 2010, 9:00 AM
25+
during the 2010 pre-open-auction pilot, 9:15 AM since 2010-10-18, and
26+
several short-lived 1997-1999 changes. Times cover the continuous
27+
session only; the pre-open call auction and post-close session fall
28+
outside the open/close times.
29+
30+
Muhurat trading dates are not holidays: NSE holds an evening session on
31+
Diwali with times announced fresh each year, modeled as special opens
32+
and closes. Muhurat sessions falling on weekends (e.g. 2023-11-12)
33+
cannot currently be represented because sessions are generated from the
34+
Mon-Fri weekmask.
35+
36+
The 2021-02-24 telecom failure is modeled as an interruption from
37+
11:40 AM to 3:45 PM with a special close of 5:00 PM.
38+
"""
39+
40+
aliases = ["NSE", "XNSE"]
41+
regular_market_times = {
42+
"market_open": (
43+
(None, time(10, 0)),
44+
("1997-07-30", time(9, 30)),
45+
("1997-08-07", time(9, 0)),
46+
("1997-08-14", time(9, 30)),
47+
("1998-07-01", time(10, 0)),
48+
("1998-11-18", time(9, 55)),
49+
("2010-01-04", time(9, 0)),
50+
("2010-10-18", time(9, 15)),
51+
),
52+
"market_close": (
53+
(None, time(15, 30)),
54+
("1997-07-30", time(15, 0)),
55+
("1997-08-07", time(14, 30)),
56+
("1997-08-14", time(15, 0)),
57+
("1997-09-29", time(15, 30)),
58+
("1997-10-10", time(16, 0)),
59+
("1998-05-18", time(15, 30)),
60+
("1998-11-18", time(15, 45)),
61+
("1999-06-09", time(15, 30)),
62+
),
63+
}
64+
65+
@property
66+
def name(self) -> str:
67+
return "NSE"
68+
69+
@property
70+
def full_name(self) -> str:
71+
return "National Stock Exchange of India"
72+
73+
@property
74+
def tz(self) -> Any:
75+
return ZoneInfo("Asia/Calcutta")
76+
77+
@property
78+
def adhoc_holidays(self) -> List[Any]:
79+
return NSEClosedDay
80+
81+
@property
82+
def special_opens_adhoc(self) -> List[Any]:
83+
return [
84+
(time(13, 45), ["2025-10-21"]),
85+
(time(15, 45), ["2012-11-13"]),
86+
(time(16, 45), ["2011-10-26"]),
87+
(time(17, 0), ["2001-11-14", "2002-11-04"]),
88+
(time(17, 28), ["1998-10-19"]),
89+
(time(17, 30), ["2004-11-12", "2018-11-07"]),
90+
(time(17, 45), ["2015-11-11"]),
91+
(time(18, 0), ["2007-11-09", "2024-11-01"]),
92+
(time(18, 5), ["2005-11-01"]),
93+
(time(18, 15), ["2008-10-28", "2010-11-05", "2021-11-04", "2022-10-24"]),
94+
(time(18, 30), ["2000-10-26", "2014-10-23", "2017-10-19"]),
95+
]
96+
97+
@property
98+
def special_closes_adhoc(self) -> List[Any]:
99+
# Alongside Muhurat sessions, this includes 1996-1999 weekday
100+
# closes that deviate from the era schedule: ad-hoc trading-hour
101+
# extensions and early closes on weekly buy-in auction days. No
102+
# announcements survive from this period; times are the observed
103+
# continuous-session bounds. Eight further dates with early-ending
104+
# activity (1996-12-20, 1997-01-03, 1997-02-28, 1997-08-06,
105+
# 1997-09-29, 1998-03-23, 1998-03-26, 1998-06-24) are deliberately
106+
# not listed: truncated records and scheduled early closes are
107+
# indistinguishable, so the era close stands.
108+
return [
109+
(time(13, 15), ["1997-08-13"]),
110+
(time(14, 45), ["2025-10-21"]),
111+
(time(15, 29), ["1997-08-05"]),
112+
(
113+
time(15, 30),
114+
[
115+
"1997-10-15",
116+
"1997-10-22",
117+
"1997-10-29",
118+
"1997-11-06",
119+
"1997-11-12",
120+
"1997-11-20",
121+
"1997-11-26",
122+
"1997-12-03",
123+
"1997-12-10",
124+
"1997-12-17",
125+
"1997-12-24",
126+
"1997-12-31",
127+
"1998-01-07",
128+
"1998-01-14",
129+
"1998-01-21",
130+
"1998-01-29",
131+
"1998-02-05",
132+
"1998-02-11",
133+
"1998-02-18",
134+
"1998-02-25",
135+
"1998-03-05",
136+
],
137+
),
138+
(time(15, 35), ["1997-07-04"]),
139+
(time(15, 36), ["1996-07-09", "1998-10-20"]),
140+
(time(15, 39), ["1997-07-08", "1997-07-29"]),
141+
(time(15, 40), ["1997-06-13"]),
142+
(time(15, 46), ["1998-09-17"]),
143+
(time(15, 47), ["1996-01-23"]),
144+
(time(15, 57), ["1996-09-30", "1996-10-03", "1997-02-03"]),
145+
(
146+
time(15, 58),
147+
[
148+
"1996-05-21",
149+
"1996-05-30",
150+
"1996-10-01",
151+
"1996-10-04",
152+
"1996-10-07",
153+
"1996-10-08",
154+
"1998-09-25",
155+
"1998-09-28",
156+
"1998-09-29",
157+
"1998-10-05",
158+
"1998-10-06",
159+
"1998-10-07",
160+
"1998-10-08",
161+
],
162+
),
163+
(
164+
time(15, 59),
165+
[
166+
"1996-01-09",
167+
"1996-01-16",
168+
"1996-01-30",
169+
"1996-02-06",
170+
"1996-02-14",
171+
"1998-09-30",
172+
"1998-10-09",
173+
],
174+
),
175+
(
176+
time(16, 0),
177+
[
178+
"1997-03-12",
179+
"1997-03-13",
180+
"1997-03-14",
181+
"1997-03-17",
182+
"1997-03-18",
183+
],
184+
),
185+
(time(16, 13), ["1996-03-13"]),
186+
(
187+
time(16, 14),
188+
[
189+
"1996-03-08",
190+
"1996-03-11",
191+
"1996-03-12",
192+
"1996-03-14",
193+
"1996-03-15",
194+
"1996-03-18",
195+
],
196+
),
197+
(time(16, 16), ["1999-05-24"]),
198+
(time(16, 19), ["1999-04-16"]),
199+
(time(16, 23), ["1999-03-09"]),
200+
(time(16, 24), ["1999-03-10", "1999-03-11", "1999-03-12", "1999-03-18"]),
201+
(time(16, 25), ["1999-03-08", "1999-03-17", "1999-03-19"]),
202+
(time(16, 26), ["1999-02-24", "1999-03-16"]),
203+
(time(16, 27), ["1999-03-15", "1999-06-28"]),
204+
(
205+
time(16, 28),
206+
[
207+
"1996-04-25",
208+
"1996-05-01",
209+
"1996-07-11",
210+
"1996-07-31",
211+
"1996-08-01",
212+
"1998-03-16",
213+
"1998-03-18",
214+
],
215+
),
216+
(
217+
time(16, 29),
218+
[
219+
"1996-02-09",
220+
"1998-03-09",
221+
"1998-03-10",
222+
"1998-03-12",
223+
"1998-03-17",
224+
],
225+
),
226+
(time(16, 30), ["1999-05-21"]),
227+
(time(16, 35), ["1997-04-01"]),
228+
(time(16, 56), ["1998-07-13"]),
229+
(time(16, 57), ["1997-01-06"]),
230+
(time(16, 58), ["1996-08-08"]),
231+
(time(16, 59), ["1998-03-24"]),
232+
(time(17, 0), ["2012-11-13", "2021-02-24"]),
233+
(time(17, 14), ["1997-05-30"]),
234+
(time(17, 28), ["1996-05-20"]),
235+
(time(18, 0), ["2011-10-26"]),
236+
(time(18, 15), ["2001-11-14", "2002-11-04"]),
237+
(time(18, 30), ["1996-07-22", "1998-06-01", "2018-11-07"]),
238+
(time(18, 45), ["2004-11-12", "2015-11-11"]),
239+
(time(19, 0), ["2007-11-09", "2024-11-01"]),
240+
(time(19, 15), ["2008-10-28", "2010-11-05", "2021-11-04", "2022-10-24"]),
241+
(time(19, 20), ["2005-11-01"]),
242+
(time(19, 29), ["1998-10-19"]),
243+
(time(19, 30), ["2014-10-23", "2017-10-19"]),
244+
(time(19, 45), ["2000-10-26"]),
245+
]
246+
247+
@property
248+
def interruptions(self) -> List[Any]:
249+
return [
250+
("2021-02-24", time(11, 40), time(15, 45)),
251+
]

0 commit comments

Comments
 (0)