QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
southkorea.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, 2011 StatPro Italia srl
6 Copyright (C) 2008, 2011 Charles Chongseok Hyun
7 Copyright (C) 2015 Riccardo Barone
8 Copyright (C) 2015 Paolo Mazzocchi
9 Copyright (C) 2023 Skandinaviska Enskilda Banken AB (publ)
10 Copyright (C) 2023 Jonghee Lee
11
12 This file is part of QuantLib, a free-software/open-source library
13 for financial quantitative analysts and developers - http://quantlib.org/
14
15 QuantLib is free software: you can redistribute it and/or modify it
16 under the terms of the QuantLib license. You should have received a
17 copy of the license along with this program; if not, please email
18 <quantlib-dev@lists.sf.net>. The license is also available online at
19 <http://quantlib.org/license.shtml>.
20
21 This program is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
23 FOR A PARTICULAR PURPOSE. See the license for more details.
24*/
25
27#include <ql/errors.hpp>
28
29namespace QuantLib {
30
32 // all calendar instances share the same implementation instance
33 static ext::shared_ptr<Calendar::Impl> settlementImpl(
35 static ext::shared_ptr<Calendar::Impl> krxImpl(
37 switch (market) {
38 case Settlement:
39 impl_ = settlementImpl;
40 break;
41 case KRX:
42 impl_ = krxImpl;
43 break;
44 default:
45 QL_FAIL("unknown market");
46 }
47 }
48
50 return w == Saturday || w == Sunday;
51 }
52
54 Weekday w = date.weekday();
55 Day d = date.dayOfMonth();
56 Month m = date.month();
57 Year y = date.year();
58
59 if (isWeekend(w)
60 // New Year's Day
61 || (d == 1 && m == January)
62 // Independence Day
63 || (d == 1 && m == March)
64 || (w == Monday && (d == 2 || d == 3) && m == March && y > 2021)
65 // Arbour Day
66 || (d == 5 && m == April && y <= 2005)
67 // Labour Day
68 || (d == 1 && m == May)
69 // Children's Day
70 || (d == 5 && m == May)
71 || (w == Monday && (d == 6 || d == 7) && m == May && y > 2013)
72 // Memorial Day
73 || (d == 6 && m == June)
74 // Constitution Day
75 || (d == 17 && m == July && y <= 2007)
76 // Liberation Day
77 || (d == 15 && m == August)
78 || (w == Monday && (d == 16 || d == 17) && m == August && y > 2020)
79 // National Foundation Day
80 || (d == 3 && m == October)
81 || (w == Monday && (d == 4 || d == 5) && m == October && y > 2020)
82 // Christmas Day
83 || (d == 25 && m == December)
84 || (w == Monday && (d == 26 || d == 27) && m == December && y > 2022)
85
86 // Lunar New Year
87 || ((d == 21 || d == 22 || d == 23) && m == January && y == 2004)
88 || ((d == 8 || d == 9 || d == 10) && m == February && y == 2005)
89 || ((d == 28 || d == 29 || d == 30) && m == January && y == 2006)
90 || ( d == 19 && m == February && y == 2007)
91 || ((d == 6 || d == 7 || d == 8) && m == February && y == 2008)
92 || ((d == 25 || d == 26 || d == 27) && m == January && y == 2009)
93 || ((d == 13 || d == 14 || d == 15) && m == February && y == 2010)
94 || ((d == 2 || d == 3 || d == 4) && m == February && y == 2011)
95 || ((d == 23 || d == 24) && m == January && y == 2012)
96 || ( d == 11 && m == February && y == 2013)
97 || ((d == 30 || d == 31) && m == January && y == 2014)
98 || ((d == 18 || d == 19 || d == 20) && m == February && y == 2015)
99 || ((d >= 7 && d <= 10) && m == February && y == 2016)
100 || ((d >= 27 && d <= 30) && m == January && y == 2017)
101 || ((d == 15 || d == 16 || d == 17) && m == February && y == 2018)
102 || ((d == 4 || d == 5 || d == 6) && m == February && y == 2019)
103 || ((d >= 24 && d <= 27) && m == January && y == 2020)
104 || ((d == 11 || d == 12 || d == 13) && m == February && y == 2021)
105 || (((d == 31 && m == January) || ((d == 1 || d == 2)
106 && m == February)) && y == 2022)
107 || ((d == 23 || d == 24) && m == January && y == 2023)
108 || ((d >= 9 && d <= 12) && m == February && y == 2024)
109 || ((d == 28 || d == 29 || d == 30) && m == January && y == 2025)
110 || ((d == 16 || d == 17 || d == 18) && m == February && y == 2026)
111 || ((d == 8 || d == 9) && m == February && y == 2027)
112 || ((d == 26 || d == 27 || d == 28) && m == January && y == 2028)
113 || ((d == 12 || d == 13 || d == 14) && m == February && y == 2029)
114 || ((d == 4 || d == 5) && m == February && y == 2030)
115 || ((d == 22 || d == 23 || d == 24) && m == January && y == 2031)
116 || ((d == 10 || d == 11 || d == 12) && m == February && y == 2032)
117 || (((d == 31 && m == January) || ((d == 1|| d == 2)
118 && m == February)) && y == 2033)
119 || ((d == 20 || d == 21) && m == February && y == 2034)
120 || ((d == 7 || d == 8 || d == 9) && m == February && y == 2035)
121 || ((d == 28 || d == 29 || d == 30) && m == January && y == 2036)
122 || ((d == 16 || d == 17) && m == February && y == 2037)
123 || ((d == 3 || d == 4 || d == 5) && m == February && y == 2038)
124 || ((d == 24 || d == 25 || d == 26) && m == January && y == 2039)
125 || ((d == 13 || d == 14) && m == February && y == 2040)
126 || (((d == 31 && m == January) || ((d == 1|| d == 2)
127 && m == February)) && y == 2041)
128 || ((d == 21 || d == 22 || d == 23) && m == January && y == 2042)
129 || ((d == 9 || d == 10 || d == 11) && m == February && y == 2043)
130 || ((((d == 29|| d == 30|| d == 31) && m == January)
131 || (d == 1 && m == February)) && y == 2044)
132 || ((d == 16 || d == 17 || d == 18) && m == February && y == 2045)
133 || ((d == 5 || d == 6 || d == 7) && m == February && y == 2046)
134 || ((d >= 25 && d <= 28) && m == January && y == 2047)
135 || ((d == 13 || d == 14 || d == 15) && m == February && y == 2048)
136 || ((d == 1 || d == 2 || d == 3) && m == February && y == 2049)
137 || ((d == 24 || d == 25) && m == January && y == 2050)
138
139 // Election Days
140 || (d == 15 && m == April && y == 2004) // National Assembly
141 || (d == 31 && m == May && y == 2006) // Regional election
142 || (d == 19 && m == December && y == 2007) // Presidency
143 || (d == 9 && m == April && y == 2008) // National Assembly
144 || (d == 2 && m == June && y == 2010) // Local election
145 || (d == 11 && m == April && y == 2012) // National Assembly
146 || (d == 19 && m == December && y == 2012) // Presidency
147 || (d == 4 && m == June && y == 2014) // Local election
148 || (d == 13 && m == April && y == 2016) // National Assembly
149 || (d == 9 && m == May && y == 2017) // Presidency
150 || (d == 13 && m == June && y == 2018) // Local election
151 || (d == 15 && m == April && y == 2020) // National Assembly
152 || (d == 9 && m == March && y == 2022) // Presidency
153 || (d == 1 && m == June && y == 2022) // Local election
154 || (d == 10 && m == April && y == 2024) // National Assembly
155 // Buddha's birthday
156 || (d == 26 && m == May && y == 2004)
157 || (d == 15 && m == May && y == 2005)
158 || (d == 5 && m == May && y == 2006)
159 || (d == 24 && m == May && y == 2007)
160 || (d == 12 && m == May && y == 2008)
161 || (d == 2 && m == May && y == 2009)
162 || (d == 21 && m == May && y == 2010)
163 || (d == 10 && m == May && y == 2011)
164 || (d == 28 && m == May && y == 2012)
165 || (d == 17 && m == May && y == 2013)
166 || (d == 6 && m == May && y == 2014)
167 || (d == 25 && m == May && y == 2015)
168 || (d == 14 && m == May && y == 2016)
169 || (d == 3 && m == May && y == 2017)
170 || (d == 22 && m == May && y == 2018)
171 || (d == 12 && m == May && y == 2019)
172 || (d == 30 && m == April && y == 2020)
173 || (d == 19 && m == May && y == 2021)
174 || (d == 8 && m == May && y == 2022)
175 || (d == 29 && m == May && y == 2023) // Substitute holiday
176 || (d == 15 && m == May && y == 2024)
177 || (d == 6 && m == May && y == 2025)
178 || (d == 25 && m == May && y == 2026) // Substitute holiday
179 || (d == 13 && m == May && y == 2027)
180 || (d == 2 && m == May && y == 2028)
181 || (d == 21 && m == May && y == 2029) // Substitute holiday
182 || (d == 9 && m == May && y == 2030)
183 || (d == 28 && m == May && y == 2031)
184 || (d == 17 && m == May && y == 2032) // Substitute holiday
185 || (d == 6 && m == May && y == 2033)
186 || (d == 25 && m == May && y == 2034)
187 || (d == 15 && m == May && y == 2035)
188 || (d == 6 && m == May && y == 2036) // Substitute holiday
189 || (d == 22 && m == May && y == 2037)
190 || (d == 11 && m == May && y == 2038)
191 || (d == 2 && m == May && y == 2039) // Substitute holiday
192 || (d == 18 && m == May && y == 2040)
193 || (d == 7 && m == May && y == 2041)
194 || (d == 26 && m == May && y == 2042)
195 || (d == 18 && m == May && y == 2043) // Substitute holiday
196 || (d == 6 && m == May && y == 2044)
197 || (d == 24 && m == May && y == 2045)
198 || (d == 14 && m == May && y == 2046) // Substitute holiday
199 || (d == 2 && m == May && y == 2047)
200 || (d == 20 && m == May && y == 2048)
201 || (d == 10 && m == May && y == 2049) // Substitute holiday
202 || (d == 30 && m == May && y == 2050) // Substitute holiday
203
204 // Special holiday: 70 years from Independence Day
205 || (d == 14 && m == August && y == 2015)
206 // Special temporary holiday
207 || (d == 17 && m == August && y == 2020)
208 || (d == 2 && m == October && y == 2023)
209
210 // Harvest Moon Day
211 || ((d == 27 || d == 28 || d == 29) && m == September && y == 2004)
212 || ((d == 17 || d == 18 || d == 19) && m == September && y == 2005)
213 || ((d == 5 || d == 6 || d == 7) && m == October && y == 2006)
214 || ((d == 24 || d == 25 || d == 26) && m == September && y == 2007)
215 || ((d == 13 || d == 14 || d == 15) && m == September && y == 2008)
216 || ((d == 2 || d == 3 || d == 4) && m == October && y == 2009)
217 || ((d == 21 || d == 22 || d == 23) && m == September && y == 2010)
218 || ((d == 12 || d == 13) && m == September && y == 2011)
219 || ((d == 1) && m == October && y == 2012)
220 || ((d == 18 || d == 19 || d == 20) && m == September && y == 2013)
221 || ((d == 8 || d == 9 || d == 10) && m == September && y == 2014)
222 || ((d == 28 || d == 29) && m == September && y == 2015)
223 || ((d == 14 || d == 15 || d == 16) && m == September && y == 2016)
224 || ((d >= 3 && d <= 6) && m == October && y == 2017)
225 || ((d >= 23 && d <= 26) && m == September && y == 2018)
226 || ((d == 12 || d == 13 || d == 14) && m == September && y == 2019)
227 || (((d == 30 && m == September) || ((d == 1 || d == 2)
228 && m == October)) && y == 2020)
229 || ((d == 20 || d == 21 || d == 22) && m == September && y == 2021)
230 || ((d == 9 || d == 10 || d == 11) && m == September && y == 2022)
231 || ((d >= 9 && d <= 12) && m == September && y == 2022)
232 || ((d == 28 || d == 29 || d == 30) && m == September && y == 2023)
233 || ((d == 16 || d == 17 || d == 18) && m == September && y == 2024)
234 || ((d == 6 || d == 7 || d == 8) && m == October && y == 2025)
235 || ((d == 24 || d == 25 || d == 26) && m == September && y == 2026)
236 || ((d == 14 || d == 15 || d == 16) && m == September && y == 2027)
237 || ((d >= 2 && d <= 5) && m == October && y == 2028)
238 || ((d >= 21 && d <= 24) && m == September && y == 2029)
239 || ((d == 11 || d == 12 || d == 13) && m == September && y == 2030)
240 || (((d == 30 && m == September) || ((d == 1 || d == 2)
241 && m == October)) && y == 2031)
242 || ((d == 20 || d == 21) && m == September && y == 2032)
243 || ((d == 7 || d == 8 || d == 9) && m == September && y == 2033)
244 || ((d == 26 || d == 27 || d == 28) && m == September && y == 2034)
245 || ((d == 17 || d == 18) && m == September && y == 2035)
246 || ((d >= 3 && d <= 7) && m == October && y == 2036)
247 || ((d == 23 || d == 24 || d == 25) && m == September && y == 2037)
248 || ((d == 13 || d == 14 || d == 15) && m == September && y == 2038)
249 || ((d == 3 || d == 4 || d == 5) && m == October && y == 2039)
250 || ((d == 20 || d == 21 || d == 22) && m == September && y == 2040)
251 || ((d == 9 || d == 10 || d == 11) && m == September && y == 2041)
252 || ((d == 29 || d == 30) && m == September && y == 2042)
253 || ((d == 16 || d == 17 || d == 18) && m == September && y == 2043)
254 || ((d == 4 || d == 5 || d == 6) && m == October && y == 2044)
255 || ((d == 25 || d == 26 || d == 27) && m == September && y == 2045)
256 || ((d >= 14 && d <= 17) && m == September && y == 2046)
257 || ((d == 4 || d == 5 || d == 7) && m == October && y == 2047)
258 || ((d == 21 || d == 22 || d == 23) && m == September && y == 2048)
259 || ((d >= 10 && d <= 13) && m == September && y == 2049)
260 || ((((d == 29|| d == 30) && m == September)
261 || (d == 1 && m == October)) && y == 2050)
262
263 // Hangul Proclamation of Korea
264 || (d == 9 && m == October && y >= 2013)
265 || (w == Monday && (d == 10 || d == 11) && m == October && y > 2020)
266 )
267 return false; // NOLINT(readability-simplify-boolean-expr)
268
269 return true;
270 }
271
272 bool SouthKorea::KrxImpl::isBusinessDay(const Date& date) const {
273 // public holidays
275 return false;
276
277 Day d = date.dayOfMonth();
278 Weekday w = date.weekday();
279 Month m = date.month();
280 Year y = date.year();
281
282 if (// Year-end closing
283 ((((d == 29 || d == 30) && w == Friday) || d == 31)
284 && m == December)
285 )
286 return false;
287 if (// occasional closing days (KRX day)
288 (d == 6 && m == May && y == 2016) ||
289 (d == 2 && m == October && y == 2017)
290 )
291 return false;
292
293 return true;
294 }
295
296}
297
bool isWeekend(Weekday w) const
Definition: calendar.hpp:255
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
bool isBusinessDay(const Date &) const override
Definition: southkorea.cpp:272
bool isBusinessDay(const Date &) const override
Definition: southkorea.cpp:53
bool isWeekend(Weekday) const override
Definition: southkorea.cpp:49
SouthKorea(Market m=KRX)
Definition: southkorea.cpp:31
@ KRX
Korea exchange.
Definition: southkorea.hpp:92
@ Settlement
Public holidays.
Definition: southkorea.hpp:91
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
@ 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
@ October
Definition: date.hpp:66
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
@ Monday
Definition: weekday.hpp:42
@ Sunday
Definition: weekday.hpp:41
@ Saturday
Definition: weekday.hpp:47
@ Friday
Definition: weekday.hpp:46
Definition: any.hpp:35
South Korean calendars.