1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | |
3 | /* |
4 | Copyright (C) 2018 Matthias Groncki |
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 | <http://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/thailand.hpp> |
21 | |
22 | namespace QuantLib { |
23 | |
24 | Thailand::Thailand() { |
25 | // all calendar instances share the same implementation instance |
26 | static ext::shared_ptr<Calendar::Impl> impl(new Thailand::SetImpl); |
27 | impl_ = impl; |
28 | } |
29 | |
30 | bool Thailand::SetImpl::isBusinessDay(const Date& date) const { |
31 | Weekday w = date.weekday(); |
32 | Day d = date.dayOfMonth(); |
33 | Month m = date.month(); |
34 | Year y = date.year(); |
35 | |
36 | if (isWeekend(w) |
37 | // New Year's Day |
38 | || ((d == 1 || (d==3 && w==Monday)) && m == January) |
39 | // Chakri Memorial Day |
40 | || ((d == 6 || ((d==7 || d==8) && w==Monday)) && m == April) |
41 | // Songkran Festival |
42 | || ((d == 13 || d == 14 || d == 15) && m == April) |
43 | // Songkran Festival obersvence (usually not more then 1 holiday will be replaced) |
44 | || (d == 16 && (w == Monday || w == Tuesday) && m == April) |
45 | // Labor Day |
46 | || ((d == 1 || ((d==2 || d==3) && w==Monday)) && m == May) |
47 | // H.M. the King's Birthday |
48 | || ((d == 28 || ((d==29 || d==30) && w==Monday)) && m == July && y >= 2017) |
49 | // H.M. the Queen's Birthday |
50 | || ((d == 12 || ((d==13 || d==14) && w==Monday)) && m == August) |
51 | // H.M. King Bhumibol Adulyadej Memorial Day |
52 | || ((d == 13 || ((d==14 || d==15) && w==Monday)) && m == October && y >= 2017) |
53 | // H.M. King Bhumibol Adulyadej's Birthday |
54 | || ((d == 5 || ((d==6 || d==7) && w==Monday)) && m == December) |
55 | // Constitution Day |
56 | || ((d == 10 || ((d==11 || d==12) && w==Monday)) && m == December) |
57 | // New Year’s Eve |
58 | || (d == 31 && m == December) |
59 | // New Year’s Eve Observence |
60 | || ((d == 1 || d==2) && w == Monday && m == January) |
61 | ) |
62 | return false; |
63 | |
64 | if ((y == 2000) && |
65 | ( (d==21 && m==February) // Makha Bucha Day (Substitution Day) |
66 | || (d==5 && m==May) // Coronation Day |
67 | || (d==17 && m==May) // Wisakha Bucha Day |
68 | || (d==17 && m==July) // Buddhist Lent Day |
69 | || (d==23 && m==October) // Chulalongkorn Day |
70 | )) |
71 | return false; |
72 | |
73 | if ((y == 2001) && |
74 | ( (d==8 && m==February) // Makha Bucha Day |
75 | || (d==7 && m==May) // Wisakha Bucha Day |
76 | || (d==8 && m==May) // Coronation Day (Substitution Day) |
77 | || (d==6 && m==July) // Buddhist Lent Day |
78 | || (d==23 && m==October) // Chulalongkorn Day |
79 | )) |
80 | return false; |
81 | |
82 | // 2002, 2003 and 2004 are missing |
83 | |
84 | if ((y == 2005) && |
85 | ( (d==23 && m==February) // Makha Bucha Day |
86 | || (d==5 && m==May) // Coronation Day |
87 | || (d==23 && m==May) // Wisakha Bucha Day (Substitution Day for Sunday 22 May) |
88 | || (d==1 && m==July) // Mid Year Closing Day |
89 | || (d==22 && m==July) // Buddhist Lent Day |
90 | || (d==24 && m==October) // Chulalongkorn Day (Substitution Day for Sunday 23 October) |
91 | )) |
92 | return false; |
93 | |
94 | if ((y == 2006) && |
95 | ( (d==13 && m==February) // Makha Bucha Day |
96 | || (d==19 && m==April) // Special Holiday |
97 | || (d==5 && m==May) // Coronation Day |
98 | || (d==12 && m==May) // Wisakha Bucha Day |
99 | || (d==12 && m==June) // Special Holidays (Due to the auspicious occasion of the |
100 | // celebration of 60th Anniversary of His Majesty's Accession |
101 | // to the throne. For Bangkok, Samut Prakan, Nonthaburi, |
102 | // Pathumthani and Nakhon Pathom province) |
103 | || (d==13 && m==June) // Special Holidays (as above) |
104 | || (d==11 && m==July) // Buddhist Lent Day |
105 | || (d==23 && m==October) // Chulalongkorn Day |
106 | )) |
107 | return false; |
108 | |
109 | if ((y == 2007) && |
110 | ( (d==5 && m==March) // Makha Bucha Day (Substitution Day for Saturday 3 March) |
111 | || (d==7 && m==May) // Coronation Day (Substitution Day for Saturday 5 May) |
112 | || (d==31 && m==May) // Wisakha Bucha Day |
113 | || (d==30 && m==July) // Asarnha Bucha Day (Substitution Day for Sunday 29 July) |
114 | || (d==23 && m==October) // Chulalongkorn Day |
115 | || (d==24 && m==December) // Special Holiday |
116 | )) |
117 | return false; |
118 | |
119 | if ((y == 2008) && |
120 | ( (d==21 && m==February) // Makha Bucha Day |
121 | || (d==5 && m==May) // Coronation Day |
122 | || (d==19 && m==May) // Wisakha Bucha Day |
123 | || (d==1 && m==July) // Mid Year Closing Day |
124 | || (d==17 && m==July) // Asarnha Bucha Day |
125 | || (d==23 && m==October) // Chulalongkorn Day |
126 | )) |
127 | return false; |
128 | |
129 | if ((y == 2009) && |
130 | ( (d==2 && m==January) // Special Holiday |
131 | || (d==9 && m==February) // Makha Bucha Day |
132 | || (d==5 && m==May) // Coronation Day |
133 | || (d==8 && m==May) // Wisakha Bucha Day |
134 | || (d==1 && m==July) // Mid Year Closing Day |
135 | || (d==6 && m==July) // Special Holiday |
136 | || (d==7 && m==July) // Asarnha Bucha Day |
137 | || (d==23 && m==October) // Chulalongkorn Day |
138 | )) |
139 | return false; |
140 | |
141 | if ((y == 2010) && |
142 | ( (d==1 && m==March) // Substitution for Makha Bucha Day(Sunday 28 February) |
143 | || (d==5 && m==May) // Coronation Day |
144 | || (d==20 && m==May) // Special Holiday |
145 | || (d==21 && m==May) // Special Holiday |
146 | || (d==28 && m==May) // Wisakha Bucha Day |
147 | || (d==1 && m==July) // Mid Year Closing Day |
148 | || (d==26 && m==July) // Asarnha Bucha Day |
149 | || (d==13 && m==August) // Special Holiday |
150 | || (d==25 && m==October) // Substitution for Chulalongkorn Day(Saturday 23 October) |
151 | )) |
152 | return false; |
153 | |
154 | if ((y == 2011) && |
155 | ( (d==18 && m==February) // Makha Bucha Day |
156 | || (d==5 && m==May) // Coronation Day |
157 | || (d==16 && m==May) // Special Holiday |
158 | || (d==17 && m==May) // Wisakha Bucha Day |
159 | || (d==1 && m==July) // Mid Year Closing Day |
160 | || (d==15 && m==July) // Asarnha Bucha Day |
161 | || (d==24 && m==October) // Substitution for Chulalongkorn Day(Sunday 23 October) |
162 | )) |
163 | return false; |
164 | |
165 | if ((y == 2012) && |
166 | ( (d==3 && m==January) // Special Holiday |
167 | || (d==7 && m==March) // Makha Bucha Day 2/ |
168 | || (d==9 && m==April) // Special Holiday |
169 | || (d==7 && m==May) // Substitution for Coronation Day(Saturday 5 May) |
170 | || (d==4 && m==June) // Wisakha Bucha Day |
171 | || (d==2 && m==August) // Asarnha Bucha Day |
172 | || (d==23 && m==October) // Chulalongkorn Day |
173 | )) |
174 | return false; |
175 | |
176 | if ((y == 2013) && |
177 | ( (d==25 && m==February) // Makha Bucha Day |
178 | || (d==6 && m==May) // Substitution for Coronation Day(Sunday 5 May) |
179 | || (d==24 && m==May) // Wisakha Bucha Day |
180 | || (d==1 && m==July) // Mid Year Closing Day |
181 | || (d==22 && m==July) // Asarnha Bucha Day 2/ |
182 | || (d==23 && m==October) // Chulalongkorn Day |
183 | || (d==30 && m==December) // Special Holiday |
184 | )) |
185 | return false; |
186 | |
187 | if ((y == 2014) && |
188 | ( (d==14 && m==February) // Makha Bucha Day |
189 | || (d==5 && m==May) // Coronation Day |
190 | || (d==13 && m==May) // Wisakha Bucha Day |
191 | || (d==1 && m==July) // Mid Year Closing Day |
192 | || (d==11 && m==July) // Asarnha Bucha Day 1/ |
193 | || (d==11 && m==August) // Special Holiday |
194 | || (d==23 && m==October) // Chulalongkorn Day |
195 | )) |
196 | return false; |
197 | |
198 | if ((y == 2015) && |
199 | ( (d==2 && m==January) // Special Holiday |
200 | || (d==4 && m==March) // Makha Bucha Day |
201 | || (d==4 && m==May) // Special Holiday |
202 | || (d==5 && m==May) // Coronation Day |
203 | || (d==1 && m==June) // Wisakha Bucha Day |
204 | || (d==1 && m==July) // Mid Year Closing Day |
205 | || (d==30 && m==July) // Asarnha Bucha Day 1/ |
206 | || (d==23 && m==October) // Chulalongkorn Day |
207 | )) |
208 | return false; |
209 | |
210 | if ((y == 2016) && |
211 | ( (d==22 && m==February) // Makha Bucha Day |
212 | || (d==5 && m==May) // Coronation Day |
213 | || (d==6 && m==May) // Special Holiday |
214 | || (d==20 && m==May) // Wisakha Bucha Day |
215 | || (d==1 && m==July) // Mid Year Closing Day |
216 | || (d==18 && m==July) // Special Holiday |
217 | || (d==19 && m==July) // Asarnha Bucha Day 1/ |
218 | || (d==24 && m==October) // Substitution for Chulalongkorn Day (Sunday 23rd October) |
219 | )) |
220 | return false; |
221 | |
222 | if ((y == 2017) && |
223 | ( (d == 13 && m == February) // Makha Bucha Day |
224 | || (d == 10 && m == May) // Wisakha Bucha Day |
225 | || (d == 10 && m == July) // Asarnha Bucha Day |
226 | || (d == 23 && m == October) // Chulalongkorn Day |
227 | || (d == 26 && m == October) // Special Holiday |
228 | )) |
229 | return false; |
230 | |
231 | if ((y == 2018) && |
232 | ( (d==1 && m==March) // Makha Bucha Day |
233 | || (d==29 && m==May) // Wisakha Bucha Day |
234 | || (d==27 && m==July) // Asarnha Bucha Day1 |
235 | || (d==23 && m==October) // Chulalongkorn Day |
236 | )) |
237 | return false; |
238 | |
239 | return true; |
240 | } |
241 | |
242 | } |
243 | |