/src/quantlib/ql/time/calendars/malaysia.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2026 Lawrenz Law |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | #include <ql/time/calendars/malaysia.hpp> |
21 | | #include <algorithm> |
22 | | #include <vector> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | namespace { |
27 | | |
28 | | // Holidays that cannot be derived from a rule: the lunar (Chinese and |
29 | | // Hindu) and Islamic festivals, the substitute days granted when a |
30 | | // gazetted holiday falls on a Sunday, and one-off federal closures. |
31 | 0 | bool isTabulatedHoliday(const Date& date) { |
32 | 0 | static const std::vector<Date> holidays = { |
33 | | // 2015 |
34 | 0 | Date(3, January, 2015), // Maulidur Rasul |
35 | 0 | Date(2, February, 2015), // Federal Territory Day |
36 | 0 | Date(3, February, 2015), // Thaipusam |
37 | 0 | Date(19, February, 2015), // Chinese New Year |
38 | 0 | Date(20, February, 2015), // Chinese New Year |
39 | 0 | Date(4, May, 2015), // Wesak Day |
40 | 0 | Date(6, June, 2015), // Agong's Birthday |
41 | 0 | Date(4, July, 2015), // Nuzul Al-Quran |
42 | 0 | Date(17, July, 2015), // Hari Raya Aidilfitri |
43 | 0 | Date(18, July, 2015), // Hari Raya Aidilfitri |
44 | 0 | Date(24, September, 2015), // Hari Raya Haji |
45 | 0 | Date(14, October, 2015), // Awal Muharram |
46 | 0 | Date(10, November, 2015), // Deepavali |
47 | 0 | Date(24, December, 2015), // Maulidur Rasul |
48 | | // 2016 |
49 | 0 | Date(24, January, 2016), // Thaipusam |
50 | 0 | Date(25, January, 2016), // Thaipusam |
51 | 0 | Date(8, February, 2016), // Chinese New Year |
52 | 0 | Date(9, February, 2016), // Chinese New Year |
53 | 0 | Date(2, May, 2016), // Labour Day |
54 | 0 | Date(21, May, 2016), // Wesak Day |
55 | 0 | Date(4, June, 2016), // Agong's Birthday |
56 | 0 | Date(22, June, 2016), // Nuzul Al-Quran |
57 | 0 | Date(6, July, 2016), // Hari Raya Aidilfitri |
58 | 0 | Date(7, July, 2016), // Hari Raya Aidilfitri |
59 | 0 | Date(12, September, 2016), // Hari Raya Haji |
60 | 0 | Date(2, October, 2016), // Awal Muharram |
61 | 0 | Date(3, October, 2016), // Awal Muharram |
62 | 0 | Date(29, October, 2016), // Deepavali |
63 | 0 | Date(12, December, 2016), // Maulidur Rasul |
64 | 0 | Date(26, December, 2016), // Christmas Day (in lieu) |
65 | | // 2017 |
66 | 0 | Date(2, January, 2017), // New Year's Day (in lieu) |
67 | 0 | Date(28, January, 2017), // Chinese New Year |
68 | 0 | Date(29, January, 2017), // Chinese New Year |
69 | 0 | Date(30, January, 2017), // Chinese New Year |
70 | 0 | Date(9, February, 2017), // Thaipusam |
71 | 0 | Date(11, February, 2017), // Thaipusam |
72 | 0 | Date(24, April, 2017), // Installation of the 15th Yang di-Pertuan Agong |
73 | 0 | Date(10, May, 2017), // Wesak Day |
74 | 0 | Date(3, June, 2017), // Agong's Birthday |
75 | 0 | Date(11, June, 2017), // Nuzul Al-Quran |
76 | 0 | Date(12, June, 2017), // Nuzul Al-Quran |
77 | 0 | Date(25, June, 2017), // Hari Raya Aidilfitri |
78 | 0 | Date(26, June, 2017), // Hari Raya Aidilfitri |
79 | 0 | Date(27, June, 2017), // Hari Raya Aidilfitri |
80 | 0 | Date(1, September, 2017), // Hari Raya Haji |
81 | 0 | Date(4, September, 2017), // Special holiday, 29th SEA Games |
82 | 0 | Date(22, September, 2017), // Awal Muharram |
83 | 0 | Date(18, October, 2017), // Deepavali |
84 | 0 | Date(1, December, 2017), // Maulidur Rasul |
85 | | // 2018 |
86 | 0 | Date(31, January, 2018), // Thaipusam |
87 | 0 | Date(16, February, 2018), // Chinese New Year |
88 | 0 | Date(17, February, 2018), // Chinese New Year |
89 | 0 | Date(9, May, 2018), // GE14 polling day |
90 | 0 | Date(10, May, 2018), // Special Holiday |
91 | 0 | Date(11, May, 2018), // Special Holiday |
92 | 0 | Date(29, May, 2018), // Wesak Day |
93 | 0 | Date(2, June, 2018), // Nuzul Al-Quran |
94 | 0 | Date(15, June, 2018), // Hari Raya Aidilfitri |
95 | 0 | Date(16, June, 2018), // Hari Raya Aidilfitri |
96 | 0 | Date(22, August, 2018), // Hari Raya Haji |
97 | 0 | Date(10, September, 2018), // Agong's Birthday |
98 | 0 | Date(11, September, 2018), // Awal Muharram |
99 | 0 | Date(17, September, 2018), // Malaysia Day (in lieu) |
100 | 0 | Date(6, November, 2018), // Deepavali |
101 | 0 | Date(20, November, 2018), // Maulidur Rasul |
102 | | // 2019 |
103 | 0 | Date(21, January, 2019), // Thaipusam |
104 | 0 | Date(5, February, 2019), // Chinese New Year |
105 | 0 | Date(6, February, 2019), // Chinese New Year |
106 | 0 | Date(20, May, 2019), // Wesak Day |
107 | 0 | Date(22, May, 2019), // Nuzul Al-Quran |
108 | 0 | Date(5, June, 2019), // Hari Raya Aidilfitri |
109 | 0 | Date(6, June, 2019), // Hari Raya Aidilfitri (in lieu) |
110 | 0 | Date(30, July, 2019), // Installation of the 16th Yang di-Pertuan Agong |
111 | 0 | Date(11, August, 2019), // Hari Raya Haji |
112 | 0 | Date(12, August, 2019), // Hari Raya Haji (in lieu) |
113 | 0 | Date(1, September, 2019), // Awal Muharram |
114 | 0 | Date(2, September, 2019), // Awal Muharram (in lieu) |
115 | 0 | Date(9, September, 2019), // Agong's Birthday |
116 | 0 | Date(27, October, 2019), // Deepavali |
117 | 0 | Date(28, October, 2019), // Deepavali (in lieu) |
118 | 0 | Date(9, November, 2019), // Maulidur Rasul |
119 | | // 2020 |
120 | 0 | Date(25, January, 2020), // Chinese New Year |
121 | 0 | Date(26, January, 2020), // Chinese New Year |
122 | 0 | Date(27, January, 2020), // Chinese New Year |
123 | 0 | Date(9, February, 2020), // Thaipusam |
124 | 0 | Date(7, May, 2020), // Wesak Day |
125 | 0 | Date(10, May, 2020), // Nuzul Al-Quran |
126 | 0 | Date(11, May, 2020), // Nuzul Al-Quran (in lieu) |
127 | 0 | Date(24, May, 2020), // Hari Raya Aidilfitri |
128 | 0 | Date(25, May, 2020), // Hari Raya Aidilfitri (in lieu) |
129 | 0 | Date(26, May, 2020), // Hari Raya Aidilfitri (in lieu) |
130 | 0 | Date(8, June, 2020), // Agong's Birthday |
131 | 0 | Date(31, July, 2020), // Hari Raya Haji |
132 | 0 | Date(20, August, 2020), // Awal Muharram |
133 | 0 | Date(29, October, 2020), // Maulidur Rasul |
134 | 0 | Date(14, November, 2020), // Deepavali |
135 | | // 2021 |
136 | 0 | Date(28, January, 2021), // Thaipusam |
137 | 0 | Date(12, February, 2021), // Chinese New Year |
138 | 0 | Date(13, February, 2021), // Chinese New Year |
139 | 0 | Date(29, April, 2021), // Nuzul Al-Quran |
140 | 0 | Date(13, May, 2021), // Hari Raya Aidilfitri |
141 | 0 | Date(14, May, 2021), // Hari Raya Aidilfitri (in lieu) |
142 | 0 | Date(26, May, 2021), // Wesak Day |
143 | 0 | Date(7, June, 2021), // Agong's Birthday |
144 | 0 | Date(20, July, 2021), // Hari Raya Haji |
145 | 0 | Date(10, August, 2021), // Awal Muharram |
146 | 0 | Date(19, October, 2021), // Maulidur Rasul |
147 | 0 | Date(4, November, 2021), // Deepavali |
148 | 0 | Date(3, December, 2021), // Special Holiday (Federal Territories) |
149 | | // 2022 |
150 | 0 | Date(18, January, 2022), // Thaipusam |
151 | 0 | Date(1, February, 2022), // Chinese New Year |
152 | 0 | Date(2, February, 2022), // Chinese New Year |
153 | 0 | Date(3, February, 2022), // Federal Territory Day (in lieu) |
154 | 0 | Date(19, April, 2022), // Nuzul Al-Quran |
155 | 0 | Date(2, May, 2022), // Hari Raya Aidilfitri |
156 | 0 | Date(3, May, 2022), // Hari Raya Aidilfitri (in lieu) |
157 | 0 | Date(4, May, 2022), // Labour Day (in lieu) |
158 | 0 | Date(15, May, 2022), // Wesak Day |
159 | 0 | Date(16, May, 2022), // Wesak Day (in lieu) |
160 | 0 | Date(6, June, 2022), // Agong's Birthday |
161 | 0 | Date(10, July, 2022), // Hari Raya Haji |
162 | 0 | Date(11, July, 2022), // Hari Raya Haji (in lieu) |
163 | 0 | Date(30, July, 2022), // Awal Muharram |
164 | 0 | Date(9, October, 2022), // Maulidur Rasul |
165 | 0 | Date(10, October, 2022), // Maulidur Rasul (in lieu) |
166 | 0 | Date(24, October, 2022), // Deepavali |
167 | 0 | Date(18, November, 2022), // Special days |
168 | 0 | Date(28, November, 2022), // Special Bank Holiday |
169 | 0 | Date(26, December, 2022), // Christmas Day (in lieu) |
170 | | // 2023 |
171 | 0 | Date(2, January, 2023), // New Year's Day (in lieu) |
172 | 0 | Date(22, January, 2023), // Chinese New Year |
173 | 0 | Date(23, January, 2023), // Chinese New Year |
174 | 0 | Date(24, January, 2023), // Chinese New Year |
175 | 0 | Date(5, February, 2023), // Thaipusam |
176 | 0 | Date(6, February, 2023), // Thaipusam (in lieu) |
177 | 0 | Date(8, April, 2023), // Nuzul Al-Quran |
178 | 0 | Date(21, April, 2023), // Hari Raya Aidilfitri (in lieu) |
179 | 0 | Date(22, April, 2023), // Hari Raya Aidilfitri |
180 | 0 | Date(23, April, 2023), // Hari Raya Aidilfitri (in lieu) |
181 | 0 | Date(24, April, 2023), // Hari Raya Aidilfitri (in lieu) |
182 | 0 | Date(4, May, 2023), // Wesak Day |
183 | 0 | Date(5, June, 2023), // Agong's Birthday |
184 | 0 | Date(29, June, 2023), // Hari Raya Haji |
185 | 0 | Date(19, July, 2023), // Awal Muharram |
186 | 0 | Date(28, September, 2023), // Maulidur Rasul |
187 | 0 | Date(12, November, 2023), // Deepavali |
188 | 0 | Date(13, November, 2023), // Deepavali (in lieu) |
189 | | // 2024 |
190 | 0 | Date(25, January, 2024), // Thaipusam |
191 | 0 | Date(10, February, 2024), // Chinese New Year |
192 | 0 | Date(11, February, 2024), // Chinese New Year |
193 | 0 | Date(12, February, 2024), // Chinese New Year |
194 | 0 | Date(28, March, 2024), // Nuzul Al-Quran |
195 | 0 | Date(10, April, 2024), // Hari Raya Aidilfitri |
196 | 0 | Date(11, April, 2024), // Hari Raya Aidilfitri |
197 | 0 | Date(22, May, 2024), // Wesak Day |
198 | 0 | Date(3, June, 2024), // Agong's Birthday |
199 | 0 | Date(17, June, 2024), // Hari Raya Haji |
200 | 0 | Date(7, July, 2024), // Awal Muharram |
201 | 0 | Date(8, July, 2024), // Awal Muharram |
202 | 0 | Date(16, September, 2024), // Maulidur Rasul |
203 | 0 | Date(31, October, 2024), // Deepavali |
204 | | // 2025 |
205 | 0 | Date(29, January, 2025), // Chinese New Year |
206 | 0 | Date(30, January, 2025), // Chinese New Year |
207 | 0 | Date(11, February, 2025), // Thaipusam |
208 | 0 | Date(18, March, 2025), // Nuzul Al-Quran |
209 | 0 | Date(30, March, 2025), // Hari Raya Aidilfitri (in lieu) |
210 | 0 | Date(31, March, 2025), // Hari Raya Aidilfitri |
211 | 0 | Date(1, April, 2025), // Hari Raya Aidilfitri (in lieu) |
212 | 0 | Date(12, May, 2025), // Wesak Day |
213 | 0 | Date(2, June, 2025), // Agong's Birthday |
214 | 0 | Date(7, June, 2025), // Hari Raya Haji |
215 | 0 | Date(27, June, 2025), // Awal Muharram |
216 | 0 | Date(1, September, 2025), // National Day (in lieu) |
217 | 0 | Date(5, September, 2025), // Maulidur Rasul |
218 | 0 | Date(15, September, 2025), // Malaysia Day (in lieu) |
219 | 0 | Date(20, October, 2025), // Deepavali |
220 | | // 2026 |
221 | 0 | Date(1, February, 2026), // Thaipusam |
222 | 0 | Date(2, February, 2026), // Thaipusam (in lieu) |
223 | 0 | Date(17, February, 2026), // Chinese New Year |
224 | 0 | Date(18, February, 2026), // Chinese New Year |
225 | 0 | Date(7, March, 2026), // Nuzul Al-Quran |
226 | 0 | Date(20, March, 2026), // Hari Raya Aidilfitri (in lieu) |
227 | 0 | Date(21, March, 2026), // Hari Raya Aidilfitri |
228 | 0 | Date(22, March, 2026), // Hari Raya Aidilfitri (in lieu) |
229 | 0 | Date(23, March, 2026), // Hari Raya Aidilfitri (in lieu) |
230 | 0 | Date(27, May, 2026), // Hari Raya Haji |
231 | 0 | Date(31, May, 2026), // Wesak Day |
232 | 0 | Date(1, June, 2026), // Agong's Birthday |
233 | 0 | Date(17, June, 2026), // Awal Muharram |
234 | 0 | Date(25, August, 2026), // Maulidur Rasul |
235 | 0 | Date(8, November, 2026), // Deepavali |
236 | 0 | Date(9, November, 2026), // Deepavali (in lieu) |
237 | | // 2027 |
238 | 0 | Date(22, January, 2027), // Thaipusam |
239 | 0 | Date(6, February, 2027), // Chinese New Year |
240 | 0 | Date(7, February, 2027), // Chinese New Year |
241 | 0 | Date(24, February, 2027), // Nuzul Al-Quran |
242 | 0 | Date(10, March, 2027), // Hari Raya Aidilfitri |
243 | 0 | Date(11, March, 2027), // Hari Raya Aidilfitri (in lieu) |
244 | 0 | Date(17, May, 2027), // Hari Raya Haji (in lieu) |
245 | 0 | Date(20, May, 2027), // Wesak Day |
246 | 0 | Date(5, June, 2027), // Agong's Birthday |
247 | 0 | Date(6, June, 2027), // Awal Muharram |
248 | 0 | Date(15, August, 2027), // Maulidur Rasul |
249 | 0 | Date(30, October, 2027), // Deepavali |
250 | 0 | }; |
251 | 0 | return std::binary_search(holidays.begin(), holidays.end(), date); |
252 | 0 | } |
253 | | |
254 | | } |
255 | | |
256 | 0 | Malaysia::Malaysia(Market) { |
257 | | // all calendar instances share the same implementation instance |
258 | 0 | static ext::shared_ptr<Calendar::Impl> impl(new Malaysia::KlseImpl); |
259 | 0 | impl_ = impl; |
260 | 0 | } |
261 | | |
262 | 0 | bool Malaysia::KlseImpl::isBusinessDay(const Date& date) const { |
263 | 0 | Weekday w = date.weekday(); |
264 | 0 | Day d = date.dayOfMonth(); |
265 | 0 | Month m = date.month(); |
266 | 0 | Year y = date.year(); |
267 | |
|
268 | 0 | if (isWeekend(w) |
269 | | // New Year's Day |
270 | 0 | || (d == 1 && m == January) |
271 | | // Federal Territory Day |
272 | 0 | || (d == 1 && m == February) |
273 | | // Labour Day |
274 | 0 | || (d == 1 && m == May) |
275 | | // National Day |
276 | 0 | || (d == 31 && m == August) |
277 | | // Malaysia Day (a federal holiday since 2010) |
278 | 0 | || (d == 16 && m == September && y >= 2010) |
279 | | // Christmas Day |
280 | 0 | || (d == 25 && m == December)) |
281 | 0 | return false; |
282 | | |
283 | 0 | return !isTabulatedHoliday(date); |
284 | 0 | } |
285 | | |
286 | | } |