Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
ice.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/shared_ptr.hpp>
20#include <qle/calendars/ice.hpp>
21
22using namespace QuantLib;
23
24namespace QuantExt {
25
27
28 // All calendar instances on the same market share the same implementation instance
29 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresUSImpl(new ICE::FuturesUSImpl);
30 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresUSImpl_1(new ICE::FuturesUSImpl_1);
31 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresUSImpl_2(new ICE::FuturesUSImpl_2);
32 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresEUImpl(new ICE::FuturesEUImpl);
33 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresEUImpl_1(new ICE::FuturesEUImpl_1);
34 static ext::shared_ptr<QuantLib::Calendar::Impl> endexEnergyImpl(new ICE::EndexEnergyImpl);
35 static ext::shared_ptr<QuantLib::Calendar::Impl> endexEquitiesImpl(new ICE::EndexEquitiesImpl);
36 static ext::shared_ptr<QuantLib::Calendar::Impl> swapTradeUSImpl(new ICE::SwapTradeUSImpl);
37 static ext::shared_ptr<QuantLib::Calendar::Impl> swapTradeUKImpl(new ICE::SwapTradeUKImpl);
38 static ext::shared_ptr<QuantLib::Calendar::Impl> futuresSingaporeImpl(new ICE::FuturesSingaporeImpl);
39
40 switch (market) {
41 case FuturesUS:
42 impl_ = futuresUSImpl;
43 break;
44 case FuturesUS_1:
45 impl_ = futuresUSImpl_1;
46 break;
47 case FuturesUS_2:
48 impl_ = futuresUSImpl_2;
49 break;
50 case FuturesEU:
51 impl_ = futuresEUImpl;
52 break;
53 case FuturesEU_1:
54 impl_ = futuresEUImpl_1;
55 break;
56 case EndexEnergy:
57 impl_ = endexEnergyImpl;
58 break;
59 case EndexEquities:
60 impl_ = endexEquitiesImpl;
61 break;
62 case SwapTradeUS:
63 impl_ = swapTradeUSImpl;
64 break;
65 case SwapTradeUK:
66 impl_ = swapTradeUKImpl;
67 break;
69 impl_ = futuresSingaporeImpl;
70 break;
71 default:
72 QL_FAIL("unknown market");
73 }
74}
75
76bool ICE::FuturesUSImpl::isBusinessDay(const Date& date) const {
77
78 Weekday w = date.weekday();
79 Day d = date.dayOfMonth();
80 Month m = date.month();
81 Year y = date.year();
82
83 Day dd = date.dayOfYear();
84 Day em = easterMonday(y);
85
86 if (isWeekend(w)
87 // New Year's Day (possibly moved to Monday if on Sunday)
88 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
89 // Good Friday
90 || (dd == em - 3)
91 // Christmas (Monday if Sunday or Friday if Saturday)
92 || ((d == 25 || (d == 26 && w == Monday) || (d == 24 && w == Friday)) && m == December))
93 return false;
94
95 return true;
96}
97
98bool ICE::FuturesUSImpl_1::isBusinessDay(const Date& date) const {
99
100 Weekday w = date.weekday();
101 Day d = date.dayOfMonth();
102 Month m = date.month();
103 Year y = date.year();
104
106 // Martin Luther King's birthday (third Monday in January)
107 || (y >= 1998 && (d >= 15 && d <= 21) && w == Monday && m == January)
108 // Washington's birthday (third Monday in February)
109 || ((d >= 15 && d <= 21) && w == Monday && m == February)
110 // Memorial Day (last Monday in May)
111 || (d >= 25 && w == Monday && m == May)
112 // Independence Day (Monday if Sunday or Friday if Saturday)
113 || ((d == 4 || (d == 5 && w == Monday) || (d == 3 && w == Friday)) && m == July)
114 // Labor Day (first Monday in September)
115 || (d <= 7 && w == Monday && m == September)
116 // Thanksgiving Day (fourth Thursday in November)
117 || ((d >= 22 && d <= 28) && w == Thursday && m == November))
118 return false;
119
120 return true;
121}
122
123bool ICE::FuturesUSImpl_2::isBusinessDay(const Date& date) const {
124
125 Weekday w = date.weekday();
126 Day d = date.dayOfMonth();
127 Month m = date.month();
128
130 // Washington's birthday (third Monday in February)
131 || ((d >= 15 && d <= 21) && w == Monday && m == February)
132 // The Monday on or preceding 24 May (Victoria Day)
133 || (d > 17 && d <= 24 && w == Monday && m == May)
134 // July 1st, possibly moved to Monday (Canada Day)
135 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == July)
136 // First Monday of August (Terry Fox Day)
137 || (d <= 7 && w == Monday && m == August)
138 // Labor Day (first Monday in September)
139 || (d <= 7 && w == Monday && m == September)
140 // Second Monday of October (Thanksgiving Day Canada)
141 || (d > 7 && d <= 14 && w == Monday && m == October)
142 // Boxing Day Canada (Monday if Sunday, Tuesday if Monday i.e. xmas day is Sunday)
143 || ((d == 26 || (d == 27 && (w == Monday || w == Tuesday))) && m == December))
144 return false;
145
146 return true;
147}
148
149bool ICE::FuturesEUImpl::isBusinessDay(const Date& date) const {
150
151 Weekday w = date.weekday();
152 Day d = date.dayOfMonth();
153 Month m = date.month();
154 Year y = date.year();
155
156 Day dd = date.dayOfYear();
157 Day em = easterMonday(y);
158
159 if (isWeekend(w)
160 // New Year's Day (Monday if on Sunday)
161 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
162 // Good Friday
163 || (dd == em - 3)
164 // Christmas (Monday if Sunday)
165 || ((d == 25 || (d == 26 && w == Monday)) && m == December))
166 return false;
167
168 return true;
169}
170
171bool ICE::FuturesEUImpl_1::isBusinessDay(const Date& date) const {
172
173 Weekday w = date.weekday();
174 Day d = date.dayOfMonth();
175 Month m = date.month();
176
178 // 26 Dec (Monday off if Sunday or Saturday is 26 Dec, Tuesday off if Monday is 26 Dec)
179 || ((d == 26 || ((d == 27 || d == 28) && w == Monday) || (d == 27 && w == Tuesday)) && m == December))
180 return false;
181
182 return true;
183}
184
185bool ICE::EndexEnergyImpl::isBusinessDay(const Date& date) const {
186
187 Weekday w = date.weekday();
188 Day d = date.dayOfMonth();
189 Month m = date.month();
190 Year y = date.year();
191
192 Day dd = date.dayOfYear();
193 Day em = easterMonday(y);
194
195 if (isWeekend(w)
196 // New Year's Day (Monday if on Sunday)
197 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
198 // Good Friday
199 || (dd == em - 3)
200 // Easter Monday
201 || dd == em
202 // Christmas (Monday if Sunday)
203 || ((d == 25 || (d == 26 && w == Monday)) && m == December)
204 // 26 Dec (Monday if Sunday)
205 || ((d == 26 || (d == 27 && w == Monday)) && m == December))
206 return false;
207
208 return true;
209}
210
211bool ICE::EndexEquitiesImpl::isBusinessDay(const Date& date) const {
212
213 Weekday w = date.weekday();
214 Day d = date.dayOfMonth();
215 Month m = date.month();
216 Year y = date.year();
217
218 Day dd = date.dayOfYear();
219 Day em = easterMonday(y);
220
221 if (isWeekend(w)
222 // New Year's Day (Monday if on Sunday)
223 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
224 // Good Friday
225 || (dd == em - 3)
226 // Easter Monday
227 || dd == em
228 // Labour Day
229 || (d == 1 && m == May)
230 // Christmas (Monday if Sunday)
231 || ((d == 25 || (d == 26 && w == Monday)) && m == December)
232 // 26 Dec (Monday if Sunday)
233 || ((d == 26 || (d == 27 && w == Monday)) && m == December))
234 return false;
235
236 return true;
237}
238
239bool ICE::SwapTradeUSImpl::isBusinessDay(const Date& date) const {
240
241 Weekday w = date.weekday();
242 Day d = date.dayOfMonth();
243 Month m = date.month();
244 Year y = date.year();
245
246 Day dd = date.dayOfYear();
247 Day em = easterMonday(y);
248
249 if (isWeekend(w)
250 // New Year's Day (possibly moved to Monday if on Sunday)
251 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
252 // Good Friday
253 || (dd == em - 3)
254 // Martin Luther King's birthday (third Monday in January)
255 || (y >= 1998 && (d >= 15 && d <= 21) && w == Monday && m == January)
256 // Washington's birthday (third Monday in February)
257 || ((d >= 15 && d <= 21) && w == Monday && m == February)
258 // Memorial Day (last Monday in May)
259 || (d >= 25 && w == Monday && m == May)
260 // Independence Day (Monday if Sunday or Friday if Saturday)
261 || ((d == 4 || (d == 5 && w == Monday) || (d == 3 && w == Friday)) && m == July)
262 // Labor Day (first Monday in September)
263 || (d <= 7 && w == Monday && m == September)
264 // Columbus Day
265 || ((d >= 8 && d <= 14) && w == Monday && m == October && y >= 1971)
266 // Veteran's Day: November 11th, adjusted
267 || ((d == 11 || (d == 12 && w == Monday) || (d == 10 && w == Friday)) && m == November)
268 // Thanksgiving Day (fourth Thursday in November)
269 || ((d >= 22 && d <= 28) && w == Thursday && m == November)
270 // Christmas (Monday if Sunday)
271 || ((d == 25 || (d == 26 && w == Monday)) && m == December))
272 return false;
273
274 return true;
275}
276
277bool ICE::SwapTradeUKImpl::isBusinessDay(const Date& date) const {
278
279 Weekday w = date.weekday();
280 Day d = date.dayOfMonth();
281 Month m = date.month();
282 Year y = date.year();
283
284 Day dd = date.dayOfYear();
285 Day em = easterMonday(y);
286
287 if (isWeekend(w)
288 // New Year's Day (possibly moved to Monday if on Sunday)
289 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
290 // Good Friday
291 || (dd == em - 3)
292 // Easter Monday
293 || dd == em
294 // first Monday of May (Early May Bank Holiday)
295 || (d <= 7 && w == Monday && m == May)
296 // last Monday of August (Summer Bank Holiday)
297 || (d >= 25 && w == Monday && m == August)
298 // Christmas (Monday if Sunday)
299 || ((d == 25 || (d == 26 && w == Monday)) && m == December)
300 // 26 Dec (Monday if Sunday)
301 || ((d == 26 || (d == 27 && w == Monday)) && m == December))
302 return false;
303
304 return true;
305}
306
307bool ICE::FuturesSingaporeImpl::isBusinessDay(const Date& date) const {
308
309 Weekday w = date.weekday();
310 Day d = date.dayOfMonth();
311 Month m = date.month();
312 Year y = date.year();
313
314 Day dd = date.dayOfYear();
315 Day em = easterMonday(y);
316
317 if (isWeekend(w)
318 // New Year's Day (Monday if Sunday)
319 || ((d == 1 || (d == 2 && w == Monday)) && m == January)
320 // Good Friday
321 || (dd == em - 3)
322 // Christmas (Monday if Sunday)
323 || ((d == 25 || (d == 26 && w == Monday)) && m == December))
324 return false;
325
326 return true;
327}
328
329} // namespace QuantExt
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:185
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:211
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:171
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:149
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:307
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:98
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:123
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:76
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:277
bool isBusinessDay(const QuantLib::Date &d) const override
Definition: ice.cpp:239
ICE(Market market)
Definition: ice.cpp:26
@ FuturesEU_1
ICE Futures Europe for contracts where 26 Dec is a holiday.
Definition: ice.hpp:103
@ FuturesEU
ICE Futures Europe.
Definition: ice.hpp:102
@ FuturesUS_2
ICE Futures U.S. Canola.
Definition: ice.hpp:101
@ FuturesSingapore
ICE futures Singapore.
Definition: ice.hpp:108
@ FuturesUS_1
ICE Futures U.S. Sugar, Cocoa, Coffee, Cotton and FCOJ.
Definition: ice.hpp:100
@ FuturesUS
Definition: ice.hpp:98
@ EndexEnergy
ICE Endex European power and natural gas products.
Definition: ice.hpp:104
@ EndexEquities
ICE Endex European equities.
Definition: ice.hpp:105
@ SwapTradeUS
ICE Swap Trade U.S.
Definition: ice.hpp:106
@ SwapTradeUK
ICE Swap Trade U.K.
Definition: ice.hpp:107
Intercontinental Exchange calendars.