QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
hongkong.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, 2009, 2010, 2011 StatPro Italia srl
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#include <ql/errors.hpp>
23
24namespace QuantLib {
25
27 // all calendar instances share the same implementation instance
28 static ext::shared_ptr<Calendar::Impl> impl(new HongKong::HkexImpl);
29 switch (m) {
30 case HKEx:
31 impl_ = impl;
32 break;
33 default:
34 QL_FAIL("unknown market");
35 }
36 }
37
38 bool HongKong::HkexImpl::isBusinessDay(const Date& date) const {
39 Weekday w = date.weekday();
40 Day d = date.dayOfMonth(), dd = date.dayOfYear();
41 Month m = date.month();
42 Year y = date.year();
43 Day em = easterMonday(y);
44
45 if (isWeekend(w)
46 // New Year's Day
47 || ((d == 1 || ((d == 2) && w == Monday))
48 && m == January)
49 // Good Friday
50 || (dd == em-3)
51 // Easter Monday
52 || (dd == em)
53 // Labor Day
54 || ((d == 1 || ((d == 2) && w == Monday)) && m == May)
55 // SAR Establishment Day
56 || ((d == 1 || ((d == 2) && w == Monday)) && m == July)
57 // National Day
58 || ((d == 1 || ((d == 2) && w == Monday))
59 && m == October)
60 // Christmas Day
61 || (d == 25 && m == December)
62 // Boxing Day
63 || (d == 26 && m == December)
64 )
65 return false;
66
67 if (y == 2004) {
68 if (// Lunar New Year
69 ((d==22 || d==23 || d==24) && m == January)
70 // Ching Ming Festival
71 || (d == 5 && m == April)
72 // Buddha's birthday
73 || (d == 26 && m == May)
74 // Tuen Ng festival
75 || (d == 22 && m == June)
76 // Mid-autumn festival
77 || (d == 29 && m == September)
78 // Chung Yeung
79 || (d == 22 && m == October))
80 return false;
81 }
82
83 if (y == 2005) {
84 if (// Lunar New Year
85 ((d==9 || d==10 || d==11) && m == February)
86 // Ching Ming Festival
87 || (d == 5 && m == April)
88 // Buddha's birthday
89 || (d == 16 && m == May)
90 // Tuen Ng festival
91 || (d == 11 && m == June)
92 // Mid-autumn festival
93 || (d == 19 && m == September)
94 // Chung Yeung festival
95 || (d == 11 && m == October))
96 return false;
97 }
98
99 if (y == 2006) {
100 if (// Lunar New Year
101 ((d >= 28 && d <= 31) && m == January)
102 // Ching Ming Festival
103 || (d == 5 && m == April)
104 // Buddha's birthday
105 || (d == 5 && m == May)
106 // Tuen Ng festival
107 || (d == 31 && m == May)
108 // Mid-autumn festival
109 || (d == 7 && m == October)
110 // Chung Yeung festival
111 || (d == 30 && m == October))
112 return false;
113 }
114
115 if (y == 2007) {
116 if (// Lunar New Year
117 ((d >= 17 && d <= 20) && m == February)
118 // Ching Ming Festival
119 || (d == 5 && m == April)
120 // Buddha's birthday
121 || (d == 24 && m == May)
122 // Tuen Ng festival
123 || (d == 19 && m == June)
124 // Mid-autumn festival
125 || (d == 26 && m == September)
126 // Chung Yeung festival
127 || (d == 19 && m == October))
128 return false;
129 }
130
131 if (y == 2008) {
132 if (// Lunar New Year
133 ((d >= 7 && d <= 9) && m == February)
134 // Ching Ming Festival
135 || (d == 4 && m == April)
136 // Buddha's birthday
137 || (d == 12 && m == May)
138 // Tuen Ng festival
139 || (d == 9 && m == June)
140 // Mid-autumn festival
141 || (d == 15 && m == September)
142 // Chung Yeung festival
143 || (d == 7 && m == October))
144 return false;
145 }
146
147 if (y == 2009) {
148 if (// Lunar New Year
149 ((d >= 26 && d <= 28) && m == January)
150 // Ching Ming Festival
151 || (d == 4 && m == April)
152 // Buddha's birthday
153 || (d == 2 && m == May)
154 // Tuen Ng festival
155 || (d == 28 && m == May)
156 // Mid-autumn festival
157 || (d == 3 && m == October)
158 // Chung Yeung festival
159 || (d == 26 && m == October))
160 return false;
161 }
162
163 if (y == 2010) {
164 if (// Lunar New Year
165 ((d == 15 || d == 16) && m == February)
166 // Ching Ming Festival
167 || (d == 6 && m == April)
168 // Buddha's birthday
169 || (d == 21 && m == May)
170 // Tuen Ng festival
171 || (d == 16 && m == June)
172 // Mid-autumn festival
173 || (d == 23 && m == September))
174 return false;
175 }
176
177 if (y == 2011) {
178 if (// Lunar New Year
179 ((d == 3 || d == 4) && m == February)
180 // Ching Ming Festival
181 || (d == 5 && m == April)
182 // Buddha's birthday
183 || (d == 10 && m == May)
184 // Tuen Ng festival
185 || (d == 6 && m == June)
186 // Mid-autumn festival
187 || (d == 13 && m == September)
188 // Chung Yeung festival
189 || (d == 5 && m == October)
190 // Second day after Christmas
191 || (d == 27 && m == December))
192 return false;
193 }
194
195 if (y == 2012) {
196 if (// Lunar New Year
197 (d >= 23 && d <= 25 && m == January)
198 // Ching Ming Festival
199 || (d == 4 && m == April)
200 // Buddha's birthday
201 || (d == 10 && m == May)
202 // Mid-autumn festival
203 || (d == 1 && m == October)
204 // Chung Yeung festival
205 || (d == 23 && m == October))
206 return false;
207 }
208
209 if (y == 2013) {
210 if (// Lunar New Year
211 (d >= 11 && d <= 13 && m == February)
212 // Ching Ming Festival
213 || (d == 4 && m == April)
214 // Buddha's birthday
215 || (d == 17 && m == May)
216 // Tuen Ng festival
217 || (d == 12 && m == June)
218 // Mid-autumn festival
219 || (d == 20 && m == September)
220 // Chung Yeung festival
221 || (d == 14 && m == October))
222 return false;
223 }
224
225 if (y == 2014) {
226 if (// Lunar New Year
227 ((d == 31 && m == January) || (d <= 3 && m == February))
228 // Buddha's birthday
229 || (d == 6 && m == May)
230 // Tuen Ng festival
231 || (d == 2 && m == June)
232 // Mid-autumn festival
233 || (d == 9 && m == September)
234 // Chung Yeung festival
235 || (d == 2 && m == October))
236 return false;
237 }
238
239 if (y == 2015) {
240 if (// Lunar New Year
241 ((d == 19 && m == February) || (d == 20 && m == February))
242 // The day following Easter Monday
243 || (d == 7 && m == April)
244 // Buddha's birthday
245 || (d == 25 && m == May)
246 // Tuen Ng festival
247 || (d == 20 && m == June)
248 // The 70th anniversary day of the victory of the Chinese
249 // people's war of resistance against Japanese aggression
250 || (d == 3 && m == September)
251 // Mid-autumn festival
252 || (d == 28 && m == September)
253 // Chung Yeung festival
254 || (d == 21 && m == October))
255 return false;
256 }
257
258 if (y == 2016) {
259 if (// Lunar New Year
260 ((d >= 8 && d <= 10) && m == February)
261 // Ching Ming Festival
262 || (d == 4 && m == April)
263 // Tuen Ng festival
264 || (d == 9 && m == June)
265 // Mid-autumn festival
266 || (d == 16 && m == September)
267 // Chung Yeung festival
268 || (d == 10 && m == October)
269 // Second day after Christmas
270 || (d == 27 && m == December))
271 return false;
272 }
273
274 if (y == 2017) {
275 if (// Lunar New Year
276 ((d == 30 || d == 31) && m == January)
277 // Ching Ming Festival
278 || (d == 4 && m == April)
279 // Buddha's birthday
280 || (d == 3 && m == May)
281 // Tuen Ng festival
282 || (d == 30 && m == May)
283 // Mid-autumn festival
284 || (d == 5 && m == October))
285 return false;
286 }
287
288 if (y == 2018) {
289 if (// Lunar New Year
290 ((d == 16 && m == February) || (d == 19 && m == February))
291 // Ching Ming Festival
292 || (d == 5 && m == April)
293 // Buddha's birthday
294 || (d == 22 && m == May)
295 // Tuen Ng festival
296 || (d == 18 && m == June)
297 // Mid-autumn festival
298 || (d == 25 && m == September)
299 // Chung Yeung festival
300 || (d == 17 && m == October))
301 return false;
302 }
303
304 if (y == 2019) {
305 if (// Lunar New Year
306 ((d >= 5 && d <= 7) && m == February)
307 // Ching Ming Festival
308 || (d == 5 && m == April)
309 // Tuen Ng festival
310 || (d == 7 && m == June)
311 // Chung Yeung festival
312 || (d == 7 && m == October))
313 return false;
314 }
315
316 if (y == 2020) {
317 if (// Lunar New Year
318 ((d == 27 || d == 28) && m == January)
319 // Ching Ming Festival
320 || (d == 4 && m == April)
321 // Buddha's birthday
322 || (d == 30 && m == April)
323 // Tuen Ng festival
324 || (d == 25 && m == June)
325 // Mid-autumn festival
326 || (d == 2 && m == October)
327 // Chung Yeung festival
328 || (d == 26 && m == October))
329 return false;
330 }
331
332 // data from https://www.hkex.com.hk/-/media/hkex-market/services/circulars-and-notices/participant-and-members-circulars/sehk/2020/ce_sehk_ct_038_2020.pdf
333 if (y == 2021)
334 {
335 if (// Lunar New Year
336 ((d == 12 || d == 15) && m == February)
337 // Ching Ming Festival
338 || (d == 5 && m == April)
339 // Buddha's birthday
340 || (d == 19 && m == May)
341 // Tuen Ng festival
342 || (d == 14 && m == June)
343 // Mid-autumn festival
344 || (d == 22 && m == September)
345 // Chung Yeung festival
346 || (d == 14 && m == October))
347 return false;
348 }
349
350 // data from https://www.hkex.com.hk/-/media/HKEX-Market/Services/Circulars-and-Notices/Participant-and-Members-Circulars/SEHK/2021/ce_SEHK_CT_082_2021.pdf
351 if (y == 2022)
352 {
353 if (// Lunar New Year
354 ((d >= 1 && d <= 3) && m == February)
355 // Ching Ming Festival
356 || (d == 5 && m == April)
357 // Buddha's birthday
358 || (d == 9 && m == May)
359 // Tuen Ng festival
360 || (d == 3 && m == June)
361 // Mid-autumn festival
362 || (d == 12 && m == September)
363 // Chung Yeung festival
364 || (d == 4 && m == October))
365 return false;
366 }
367
368 // data from https://www.hkex.com.hk/-/media/HKEX-Market/Services/Circulars-and-Notices/Participant-and-Members-Circulars/SEHK/2022/ce_SEHK_CT_058_2022.pdf
369 if (y == 2023)
370 {
371 if (// Lunar New Year
372 ((d >= 23 && d <= 25) && m == January)
373 // Ching Ming Festival
374 || (d == 5 && m == April)
375 // Buddha's birthday
376 || (d == 26 && m == May)
377 // Tuen Ng festival
378 || (d == 22 && m == June)
379 // Chung Yeung festival
380 || (d == 23 && m == October))
381 return false;
382 }
383
384 // data from https://www.hkex.com.hk/-/media/HKEX-Market/Services/Circulars-and-Notices/Participant-and-Members-Circulars/SEHK/2023/ce_SEHK_CT_079_2023.pdf
385 if (y == 2024) {
386 if (// Lunar New Year
387 ((d == 12 || d == 13) && m == February)
388 // Ching Ming Festival
389 || (d == 4 && m == April)
390 // Buddha's birthday
391 || (d == 15 && m == May)
392 // Tuen Ng festival
393 || (d == 10 && m == June)
394 // Mid-autumn festival
395 || (d == 18 && m == September)
396 // Chung Yeung festival
397 || (d == 11 && m == October))
398 return false;
399 }
400
401 return true;
402 }
403
404}
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: hongkong.cpp:38
HongKong(Market m=HKEx)
Definition: hongkong.cpp:26
@ HKEx
Hong Kong stock exchange.
Definition: hongkong.hpp:71
Classes and functions for error handling.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
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
@ 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
@ October
Definition: date.hpp:66
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
@ Monday
Definition: weekday.hpp:42
Hong Kong calendars.
Definition: any.hpp:35