|
| 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