QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
singapore.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) 2004 FIMAT Group
5 Copyright (C) 2007, 2008, 2009, 2010 StatPro Italia srl
6 Copyright (C) 2024 Skandinaviska Enskilda Banken AB (publ)
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
23
24namespace QuantLib {
25
27 // all calendar instances share the same implementation instance
28 static ext::shared_ptr<Calendar::Impl> impl(new Singapore::SgxImpl);
29 impl_ = impl;
30 }
31
32 bool Singapore::SgxImpl::isBusinessDay(const Date& date) const {
33 Weekday w = date.weekday();
34 Day d = date.dayOfMonth(), dd = date.dayOfYear();
35 Month m = date.month();
36 Year y = date.year();
37 Day em = easterMonday(y);
38
39 if (isWeekend(w)
40 // New Year's Day
41 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
42 // Good Friday
43 || (dd == em-3)
44 // Labor Day
45 || (d == 1 && m == May)
46 // National Day
47 || ((d == 9 || (d == 10 && w == Monday)) && m == August)
48 // Christmas Day
49 || (d == 25 && m == December)
50
51 // Chinese New Year
52 || ((d == 22 || d == 23) && m == January && y == 2004)
53 || ((d == 9 || d == 10) && m == February && y == 2005)
54 || ((d == 30 || d == 31) && m == January && y == 2006)
55 || ((d == 19 || d == 20) && m == February && y == 2007)
56 || ((d == 7 || d == 8) && m == February && y == 2008)
57 || ((d == 26 || d == 27) && m == January && y == 2009)
58 || ((d == 15 || d == 16) && m == January && y == 2010)
59 || ((d == 23 || d == 24) && m == January && y == 2012)
60 || ((d == 11 || d == 12) && m == February && y == 2013)
61 || (d == 31 && m == January && y == 2014)
62 || (d == 1 && m == February && y == 2014)
63
64 // Hari Raya Haji
65 || ((d == 1 || d == 2) && m == February && y == 2004)
66 || (d == 21 && m == January && y == 2005)
67 || (d == 10 && m == January && y == 2006)
68 || (d == 2 && m == January && y == 2007)
69 || (d == 20 && m == December && y == 2007)
70 || (d == 8 && m == December && y == 2008)
71 || (d == 27 && m == November && y == 2009)
72 || (d == 17 && m == November && y == 2010)
73 || (d == 26 && m == October && y == 2012)
74 || (d == 15 && m == October && y == 2013)
75 || (d == 6 && m == October && y == 2014)
76
77 // Vesak Poya Day
78 || (d == 2 && m == June && y == 2004)
79 || (d == 22 && m == May && y == 2005)
80 || (d == 12 && m == May && y == 2006)
81 || (d == 31 && m == May && y == 2007)
82 || (d == 18 && m == May && y == 2008)
83 || (d == 9 && m == May && y == 2009)
84 || (d == 28 && m == May && y == 2010)
85 || (d == 5 && m == May && y == 2012)
86 || (d == 24 && m == May && y == 2013)
87 || (d == 13 && m == May && y == 2014)
88
89 // Deepavali
90 || (d == 11 && m == November && y == 2004)
91 || (d == 8 && m == November && y == 2007)
92 || (d == 28 && m == October && y == 2008)
93 || (d == 16 && m == November && y == 2009)
94 || (d == 5 && m == November && y == 2010)
95 || (d == 13 && m == November && y == 2012)
96 || (d == 2 && m == November && y == 2013)
97 || (d == 23 && m == October && y == 2014)
98
99 // Diwali
100 || (d == 1 && m == November && y == 2005)
101
102 // Hari Raya Puasa
103 || ((d == 14 || d == 15) && m == November && y == 2004)
104 || (d == 3 && m == November && y == 2005)
105 || (d == 24 && m == October && y == 2006)
106 || (d == 13 && m == October && y == 2007)
107 || (d == 1 && m == October && y == 2008)
108 || (d == 21 && m == September && y == 2009)
109 || (d == 10 && m == September && y == 2010)
110 || (d == 20 && m == August && y == 2012)
111 || (d == 8 && m == August && y == 2013)
112 || (d == 28 && m == July && y == 2014)
113 )
114 return false; // NOLINT(readability-simplify-boolean-expr)
115
116 // https://api2.sgx.com/sites/default/files/2019-01/2019%20DT%20Calendar.pdf
117 if (y == 2019)
118 {
119 if ( // Chinese New Year
120 ((d == 5 || d == 6) && m == February)
121 // Vesak Poya Day
122 || (d == 20 && m == May)
123 // Hari Raya Puasa
124 || (d == 5 && m == June)
125 // Hari Raya Haji
126 || (d == 12 && m == August)
127 // Deepavali
128 || (d == 28 && m == October)
129 )
130 return false;
131 }
132
133 // https://api2.sgx.com/sites/default/files/2020-11/SGX%20Derivatives%20Trading%20Calendar%202020_Dec%20Update_D3.pdf
134 if (y == 2020)
135 {
136 if ( // Chinese New Year
137 (d == 27 && m == January)
138 // Vesak Poya Day
139 || (d == 7 && m == May)
140 // Hari Raya Puasa
141 || (d == 25 && m == May)
142 // Hari Raya Haji
143 || (d == 31 && m == July)
144 // Deepavali
145 || (d == 14 && m == November)
146 )
147 return false;
148 }
149
150 // https://api2.sgx.com/sites/default/files/2021-07/SGX_Derivatives%20Trading%20Calendar%202021%20%28Final%20-%20Jul%29.pdf
151 if (y == 2021)
152 {
153 if ( // Chinese New Year
154 (d == 12 && m == February)
155 // Hari Raya Puasa
156 || (d == 13 && m == May)
157 // Vesak Poya Day
158 || (d == 26 && m == May)
159 // Hari Raya Haji
160 || (d == 20 && m == July)
161 // Deepavali
162 || (d == 4 && m == November)
163 )
164 return false;
165 }
166
167 // https://api2.sgx.com/sites/default/files/2022-06/DT%20Trading%20Calendar%202022%20%28Final%29.pdf
168 if (y == 2022)
169 {
170 if (// Chinese New Year
171 ((d == 1 || d == 2) && m == February)
172 // Labour Day
173 || (d == 2 && m == May)
174 // Hari Raya Puasa
175 || (d == 3 && m == May)
176 // Vesak Poya Day
177 || (d == 16 && m == May)
178 // Hari Raya Haji
179 || (d == 11 && m == July)
180 // Deepavali
181 || (d == 24 && m == October)
182 // Christmas Day
183 || (d == 26 && m == December)
184 )
185 return false;
186 }
187
188 // https://api2.sgx.com/sites/default/files/2023-01/SGX%20Calendar%202023_0.pdf
189 if (y == 2023)
190 {
191 if (// Chinese New Year
192 ((d == 23 || d == 24) && m == January)
193 // Hari Raya Puasa
194 || (d == 22 && m == April)
195 // Vesak Poya Day
196 || (d == 2 && m == June)
197 // Hari Raya Haji
198 || (d == 29 && m == June)
199 // Public holiday on polling day
200 || (d == 1 && m == September)
201 // Deepavali
202 || (d == 13 && m == November))
203 return false;
204 }
205 // https://api2.sgx.com/sites/default/files/2024-01/SGX%20Calendar%202024_2.pdf
206 if (y == 2024)
207 {
208 if (// Chinese New Year
209 (d == 12 && m == February)
210 // Hari Raya Puasa
211 || (d == 10 && m == April)
212 // Vesak Poya Day
213 || (d == 22 && m == May)
214 // Hari Raya Haji
215 || (d == 17 && m == June)
216 // Deepavali
217 || (d == 31 && m == October))
218 return false;
219 }
220 return true;
221 }
222
223}
224
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: singapore.cpp:32
Singapore(Market m=SGX)
Definition: singapore.cpp:26
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
@ 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
@ Monday
Definition: weekday.hpp:42
Definition: any.hpp:35
Singapore calendars.