Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
ireland.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 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#include <ql/errors.hpp>
21
22namespace QuantExt {
23using namespace QuantLib;
24
25Ireland::Ireland(const Market market) {
26 // all calendar instances on the same market share the same
27 // implementation instance
28 switch (market) {
30 impl_ = QuantLib::ext::make_shared<Ireland::IrishStockExchangeImpl>();
31 break;
32 case BankHolidays:
33 impl_ = QuantLib::ext::make_shared<Ireland::BankHolidaysImpl>();
34 break;
35 default:
36 QL_FAIL("Internal error, unexpected market " << market);
37 }
38}
39
41 Weekday w = date.weekday();
42 Day d = date.dayOfMonth(), dd = date.dayOfYear();
43 Month m = date.month();
44 Year y = date.year();
45 Day em = easterMonday(y);
46
47 if (isWeekend(w)
48 // New Year's Day (possibly moved to Monday)
49 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == January)
50 // Good Friday
51 || (dd == em - 3)
52 // Easter Monday
53 || (dd == em)
54 // St. Patrick's Day (possibly moved to Monday)
55 || (m == Mar && ((d == 17) || ((d == 18 || d == 19) && w == Monday)))
56 // first Monday of May
57 || (m == May && d == Date::nthWeekday(1, Monday, May, y).dayOfMonth())
58 // first Monday of June
59 || (m == June && d == Date::nthWeekday(1, Monday, June, y).dayOfMonth())
60 // first Monday of August
61 || (m == August && d == Date::nthWeekday(1, Monday, August, y).dayOfMonth())
62 // last Monday of October
63 || (m == October && d == DateUtilities::lastWeekday(Monday, October, y).dayOfMonth())
64 // Christmas (possibly moved to Monday or Tuesday)
65 || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday))) && m == December)
66 // Boxing Day (possibly moved to Monday or Tuesday)
67 || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday))) && m == December))
68 return false; // NOLINT(readability-simplify-boolean-expr)
69 return true;
70}
71
72bool Ireland::BankHolidaysImpl::isBusinessDay(const Date& date) const {
73 Weekday w = date.weekday();
74 Day d = date.dayOfMonth();
75 Month m = date.month();
77 (m == December && (d == 27 || (d == 29 && (w == Mon || w == Tue || w == Wed)) || (d == 28 && w == Wed))))
78 return false;
79 else
80 return true;
81}
82} // namespace QuantExt
bool isBusinessDay(const QuantLib::Date &) const override
Definition: ireland.cpp:72
bool isBusinessDay(const QuantLib::Date &) const override
Definition: ireland.cpp:40
Ireland(const Market market=IrishStockExchange)
Definition: ireland.cpp:25
helper functions for date operations
Ireland Calendar.
Date lastWeekday(Weekday dayOfWeek, Month m, Year y)