QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
india.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011 StatPro Italia srl
5 Copyright (C) 2023, 2024 Skandinaviska Enskilda Banken AB (publ)
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
22
23namespace QuantLib {
24
26 // all calendar instances share the same implementation instance
27 static ext::shared_ptr<Calendar::Impl> impl(new India::NseImpl);
28 impl_ = impl;
29 }
30
31 bool India::NseImpl::isBusinessDay(const Date& date) const {
32 Weekday w = date.weekday();
33 Day d = date.dayOfMonth();
34 Month m = date.month();
35 Year y = date.year();
36 Day dd = date.dayOfYear();
37 Day em = easterMonday(y);
38
39 if (isWeekend(w)
40 // Republic Day
41 || (d == 26 && m == January)
42 // Good Friday
43 || (dd == em-3)
44 // Ambedkar Jayanti
45 || (d == 14 && m == April)
46 // May Day
47 || (d == 1 && m == May)
48 // Independence Day
49 || (d == 15 && m == August)
50 // Gandhi Jayanti
51 || (d == 2 && m == October)
52 // Christmas
53 || (d == 25 && m == December)
54 )
55 return false;
56
57 if (y == 2005) {
58 // Moharram, Holi, Maharashtra Day, and Ramzan Id fall
59 // on Saturday or Sunday in 2005
60 if (// Bakri Id
61 (d == 21 && m == January)
62 // Ganesh Chaturthi
63 || (d == 7 && m == September)
64 // Dasara
65 || (d == 12 && m == October)
66 // Laxmi Puja
67 || (d == 1 && m == November)
68 // Bhaubeej
69 || (d == 3 && m == November)
70 // Guru Nanak Jayanti
71 || (d == 15 && m == November)
72 )
73 return false;
74 }
75
76 if (y == 2006) {
77 if (// Bakri Id
78 (d == 11 && m == January)
79 // Moharram
80 || (d == 9 && m == February)
81 // Holi
82 || (d == 15 && m == March)
83 // Ram Navami
84 || (d == 6 && m == April)
85 // Mahavir Jayanti
86 || (d == 11 && m == April)
87 // Maharashtra Day
88 || (d == 1 && m == May)
89 // Bhaubeej
90 || (d == 24 && m == October)
91 // Ramzan Id
92 || (d == 25 && m == October)
93 )
94 return false;
95 }
96
97 if (y == 2007) {
98 if (// Bakri Id
99 (d == 1 && m == January)
100 // Moharram
101 || (d == 30 && m == January)
102 // Mahashivratri
103 || (d == 16 && m == February)
104 // Ram Navami
105 || (d == 27 && m == March)
106 // Maharashtra Day
107 || (d == 1 && m == May)
108 // Buddha Pournima
109 || (d == 2 && m == May)
110 // Laxmi Puja
111 || (d == 9 && m == November)
112 // Bakri Id (again)
113 || (d == 21 && m == December)
114 )
115 return false;
116 }
117
118 if (y == 2008) {
119 if (// Mahashivratri
120 (d == 6 && m == March)
121 // Id-E-Milad
122 || (d == 20 && m == March)
123 // Mahavir Jayanti
124 || (d == 18 && m == April)
125 // Maharashtra Day
126 || (d == 1 && m == May)
127 // Buddha Pournima
128 || (d == 19 && m == May)
129 // Ganesh Chaturthi
130 || (d == 3 && m == September)
131 // Ramzan Id
132 || (d == 2 && m == October)
133 // Dasara
134 || (d == 9 && m == October)
135 // Laxmi Puja
136 || (d == 28 && m == October)
137 // Bhau bhij
138 || (d == 30 && m == October)
139 // Gurunanak Jayanti
140 || (d == 13 && m == November)
141 // Bakri Id
142 || (d == 9 && m == December)
143 )
144 return false;
145 }
146
147 if (y == 2009) {
148 if (// Moharram
149 (d == 8 && m == January)
150 // Mahashivratri
151 || (d == 23 && m == February)
152 // Id-E-Milad
153 || (d == 10 && m == March)
154 // Holi
155 || (d == 11 && m == March)
156 // Ram Navmi
157 || (d == 3 && m == April)
158 // Mahavir Jayanti
159 || (d == 7 && m == April)
160 // Maharashtra Day
161 || (d == 1 && m == May)
162 // Ramzan Id
163 || (d == 21 && m == September)
164 // Dasara
165 || (d == 28 && m == September)
166 // Bhau Bhij
167 || (d == 19 && m == October)
168 // Gurunanak Jayanti
169 || (d == 2 && m == November)
170 // Moharram (again)
171 || (d == 28 && m == December)
172 )
173 return false;
174 }
175
176 if (y == 2010) {
177 if (// New Year's Day
178 (d == 1 && m == January)
179 // Mahashivratri
180 || (d == 12 && m == February)
181 // Holi
182 || (d == 1 && m == March)
183 // Ram Navmi
184 || (d == 24 && m == March)
185 // Ramzan Id
186 || (d == 10 && m == September)
187 // Laxmi Puja
188 || (d == 5 && m == November)
189 // Bakri Id
190 || (d == 17 && m == November)
191 // Moharram
192 || (d == 17 && m == December)
193 )
194 return false;
195 }
196
197 if (y == 2011) {
198 if (// Mahashivratri
199 (d == 2 && m == March)
200 // Ram Navmi
201 || (d == 12 && m == April)
202 // Ramzan Id
203 || (d == 31 && m == August)
204 // Ganesh Chaturthi
205 || (d == 1 && m == September)
206 // Dasara
207 || (d == 6 && m == October)
208 // Laxmi Puja
209 || (d == 26 && m == October)
210 // Diwali - Balipratipada
211 || (d == 27 && m == October)
212 // Bakri Id
213 || (d == 7 && m == November)
214 // Gurunanak Jayanti
215 || (d == 10 && m == November)
216 // Moharram
217 || (d == 6 && m == December)
218 )
219 return false;
220 }
221
222 if (y == 2012) {
223 if (// Mahashivratri
224 (d == 20 && m == February)
225 // Holi
226 || (d == 8 && m == March)
227 // Mahavir Jayanti
228 || (d == 5 && m == April)
229 // Ramzan Id
230 || (d == 20 && m == August)
231 // Ganesh Chaturthi
232 || (d == 19 && m == September)
233 // Dasara
234 || (d == 24 && m == October)
235 // Diwali - Balipratipada
236 || (d == 14 && m == November)
237 // Gurunanak Jayanti
238 || (d == 28 && m == November)
239 )
240 return false;
241 }
242
243 if (y == 2013) {
244 if (// Holi
245 (d == 27 && m == March)
246 // Ram Navmi
247 || (d == 19 && m == April)
248 // Mahavir Jayanti
249 || (d == 24 && m == April)
250 // Ramzan Id
251 || (d == 9 && m == August)
252 // Ganesh Chaturthi
253 || (d == 9 && m == September)
254 // Bakri Id
255 || (d == 16 && m == October)
256 // Diwali - Balipratipada
257 || (d == 4 && m == November)
258 // Moharram
259 || (d == 14 && m == November)
260 )
261 return false;
262 }
263
264 if (y == 2014) {
265 if (// Mahashivratri
266 (d == 27 && m == February)
267 // Holi
268 || (d == 17 && m == March)
269 // Ram Navmi
270 || (d == 8 && m == April)
271 // Ramzan Id
272 || (d == 29 && m == July)
273 // Ganesh Chaturthi
274 || (d == 29 && m == August)
275 // Dasera
276 || (d == 3 && m == October)
277 // Bakri Id
278 || (d == 6 && m == October)
279 // Diwali - Balipratipada
280 || (d == 24 && m == October)
281 // Moharram
282 || (d == 4 && m == November)
283 // Gurunank Jayanti
284 || (d == 6 && m == November)
285 )
286 return false;
287 }
288
289 if (y == 2019) {
290 if (// Chatrapati Shivaji Jayanti
291 (d == 19 && m == February)
292 // Mahashivratri
293 || (d == 4 && m == March)
294 // Holi
295 || (d == 21 && m == March)
296 // Annual Bank Closing
297 || (d == 1 && m == April)
298 // Mahavir Jayanti
299 || (d == 17 && m == April)
300 // Parliamentary Elections
301 || (d == 29 && m == April)
302 // Ramzan Id
303 || (d == 05 && m == June)
304 // Bakri Id
305 || (d == 12 && m == August)
306 // Ganesh Chaturthi
307 || (d == 2 && m == September)
308 // Moharram
309 || (d == 10 && m == September)
310 // Dasera
311 || (d == 8 && m == October)
312 // General Assembly Elections in Maharashtra
313 || (d == 21 && m == October)
314 // Diwali - Balipratipada
315 || (d == 28 && m == October)
316 // Gurunank Jayanti
317 || (d == 12 && m == November)
318 )
319 return false;
320 }
321
322 if (y == 2020) {
323 if (// Chatrapati Shivaji Jayanti
324 (d == 19 && m == February)
325 // Mahashivratri
326 || (d == 21 && m == February)
327 // Holi
328 || (d == 10 && m == March)
329 // Gudi Padwa
330 || (d == 25 && m == March)
331 // Annual Bank Closing
332 || (d == 1 && m == April)
333 // Ram Navami
334 || (d == 2 && m == April)
335 // Mahavir Jayanti
336 || (d == 6 && m == April)
337 // Buddha Pournima
338 || (d == 7 && m == May)
339 // Ramzan Id
340 || (d == 25 && m == May)
341 // Id-E-Milad
342 || (d == 30 && m == October)
343 // Diwali - Balipratipada
344 || (d == 16 && m == November)
345 // Gurunank Jayanti
346 || (d == 30 && m == November)
347 )
348 return false;
349 }
350
351 if (y == 2021) {
352 if (// Chatrapati Shivaji Jayanti
353 (d == 19 && m == February)
354 // Mahashivratri
355 || (d == 11 && m == March)
356 // Holi
357 || (d == 29 && m == March)
358 // Gudi Padwa
359 || (d == 13 && m == April)
360 // Mahavir Jayanti
361 || (d == 14 && m == April)
362 // Ram Navami
363 || (d == 21 && m == April)
364 // Buddha Pournima
365 || (d == 26 && m == May)
366 // Bakri Id
367 || (d == 21 && m == July)
368 // Ganesh Chaturthi
369 || (d == 10 && m == September)
370 // Dasera
371 || (d == 15 && m == October)
372 // Id-E-Milad
373 || (d == 19 && m == October)
374 // Diwali - Balipratipada
375 || (d == 5 && m == November)
376 // Gurunank Jayanti
377 || (d == 19 && m == November))
378 return false;
379 }
380
381 if (y == 2022) {
382 if ( // Mahashivratri
383 (d == 1 && m == March)
384 // Holi
385 || (d == 18 && m == March)
386 // Ramzan Id
387 || (d == 3 && m == May)
388 // Buddha Pournima
389 || (d == 16 && m == May)
390 // Ganesh Chaturthi
391 || (d == 31 && m == August)
392 // Dasera
393 || (d == 5 && m == October)
394 // Diwali - Balipratipada
395 || (d == 26 && m == October)
396 // Gurunank Jayanti
397 || (d == 8 && m == November))
398 return false;
399 }
400
401 if (y == 2023) {
402 if (
403 // Holi
404 (d == 7 && m == March)
405 // Gudi Padwa
406 || (d == 22 && m == March)
407 // Ram Navami
408 || (d == 30 && m == March)
409 // Mahavir Jayanti
410 || (d == 4 && m == April)
411 // Buddha Pournima
412 || (d == 5 && m == May)
413 // Bakri Id
414 || (d == 29 && m == June)
415 // Parsi New year
416 || (d == 16 && m == August)
417 // Ganesh Chaturthi
418 || (d == 19 && m == September)
419 // Id-E-Milad (was moved to Friday 29th)
420 || (d == 29 && m == September)
421 // Dasera
422 || (d == 24 && m == October)
423 // Diwali - Balipratipada
424 || (d == 14 && m == November)
425 // Gurunank Jayanti
426 || (d == 27 && m == November))
427 return false;
428 }
429
430 if (y == 2024) {
431 if ( // Special holiday
432 (d == 22 && m == January)
433 // Chatrapati Shivaji Jayanti
434 || (d == 19 && m == February)
435 // Mahashivratri
436 || (d == 8 && m == March)
437 // Holi
438 || (d == 25 && m == March)
439 // Annual Bank Closing
440 || (d == 1 && m == April)
441 // Gudi Padwa
442 || (d == 9 && m == April)
443 // Id-Ul-Fitr (Ramadan Eid)
444 || (d == 11 && m == April)
445 // Ram Navamiz
446 || (d == 17 && m == April)
447 // Mahavir Jayanti
448 || (d == 21 && m == April)
449 // Buddha Pournima
450 || (d == 23 && m == May)
451 // Bakri Id (estimated Sunday 16th or Monday 17th)
452 || (d == 17 && m == June)
453 // Id-E-Milad (estimated Sunday 15th or Monday 16th)
454 || (d == 16 && m == September)
455 // Diwali-Laxmi Pujan
456 || (d == 1 && m == November)
457 // Gurunank Jayanti
458 || (d == 15 && m == November))
459 return false;
460 }
461
462 if (y == 2025) {
463 if ( // Chatrapati Shivaji Jayanti
464 (d == 19 && m == February)
465 // Mahashivratri
466 || (d == 26 && m == February)
467 // Holi
468 || (d == 14 && m == March)
469 // Ramzan Id (estimated Sunday 30th or Monday 31st)
470 || (d == 31 && m == March)
471 // Mahavir Jayanti
472 || (d == 10 && m == April)
473 // Buddha Pournima
474 || (d == 12 && m == May)
475 // Id-E-Milad (estimated Thursday 4th or Friday 5th)
476 || (d == 5 && m == September)
477 // Diwali - Balipratipada
478 || (d == 22 && m == October)
479 // Gurunank Jayanti
480 || (d == 5 && m == November))
481 return false;
482 }
483
484 return true;
485 }
486
487}
488
static Day easterMonday(Year)
expressed relative to first day of year
Definition: calendar.cpp:199
bool isWeekend(Weekday) const override
Definition: calendar.cpp:195
ext::shared_ptr< Impl > impl_
Definition: calendar.hpp:72
Concrete date class.
Definition: date.hpp:125
Month month() const
Definition: date.cpp:82
Year year() const
Definition: date.cpp:93
Day dayOfMonth() const
Definition: date.hpp:400
Weekday weekday() const
Definition: date.hpp:395
Day dayOfYear() const
One-based (Jan 1st = 1)
Definition: date.hpp:404
bool isBusinessDay(const Date &) const override
Definition: india.cpp:31
India(Market m=NSE)
Definition: india.cpp:25
Date d
Integer Year
Year number.
Definition: date.hpp:87
Integer Day
Day number.
Definition: date.hpp:53
Month
Month names.
Definition: date.hpp:57
@ December
Definition: date.hpp:68
@ August
Definition: date.hpp:64
@ January
Definition: date.hpp:57
@ July
Definition: date.hpp:63
@ May
Definition: date.hpp:61
@ March
Definition: date.hpp:59
@ February
Definition: date.hpp:58
@ April
Definition: date.hpp:60
@ November
Definition: date.hpp:67
@ October
Definition: date.hpp:66
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
Indian calendars.
Definition: any.hpp:35