QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
unitedkingdom.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 Ferdinando Ametrano
5 Copyright (C) 2000, 2001, 2002, 2003 RiskMap 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
26 namespace {
27
28 // common rules
29
30 bool isBankHoliday(Day d, Weekday w, Month m, Year y) {
31 return
32 // first Monday of May (Early May Bank Holiday)
33 // moved to May 8th in 1995 and 2020 for V.E. day
34 (d <= 7 && w == Monday && m == May && y != 1995 && y != 2020)
35 || (d == 8 && m == May && (y == 1995 || y == 2020))
36 // last Monday of May (Spring Bank Holiday)
37 // moved to in 2002, 2012 and 2022 for the Golden, Diamond and Platinum
38 // Jubilee with an additional holiday
39 || (d >= 25 && w == Monday && m == May && y != 2002 && y != 2012 && y != 2022)
40 || ((d == 3 || d == 4) && m == June && y == 2002)
41 || ((d == 4 || d == 5) && m == June && y == 2012)
42 || ((d == 2 || d == 3) && m == June && y == 2022)
43 // last Monday of August (Summer Bank Holiday)
44 || (d >= 25 && w == Monday && m == August)
45 // April 29th, 2011 only (Royal Wedding Bank Holiday)
46 || (d == 29 && m == April && y == 2011)
47 // September 19th, 2022 only (The Queen's Funeral Bank Holiday)
48 || (d == 19 && m == September && y == 2022)
49 // May 8th, 2023 (King Charles III Coronation Bank Holiday)
50 || (d == 8 && m == May && y == 2023)
51 ;
52 }
53
54 }
55
57 // all calendar instances on the same market share the same
58 // implementation instance
59 static ext::shared_ptr<Calendar::Impl> settlementImpl(
61 static ext::shared_ptr<Calendar::Impl> exchangeImpl(
63 static ext::shared_ptr<Calendar::Impl> metalsImpl(
65 switch (market) {
66 case Settlement:
67 impl_ = settlementImpl;
68 break;
69 case Exchange:
70 impl_ = exchangeImpl;
71 break;
72 case Metals:
73 impl_ = metalsImpl;
74 break;
75 default:
76 QL_FAIL("unknown market");
77 }
78 }
79
81 Weekday w = date.weekday();
82 Day d = date.dayOfMonth(), dd = date.dayOfYear();
83 Month m = date.month();
84 Year y = date.year();
85 Day em = easterMonday(y);
86 if (isWeekend(w)
87 // New Year's Day (possibly moved to Monday)
88 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) &&
89 m == January)
90 // Good Friday
91 || (dd == em-3)
92 // Easter Monday
93 || (dd == em)
94 || isBankHoliday(d, w, m, y)
95 // Christmas (possibly moved to Monday or Tuesday)
96 || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
97 && m == December)
98 // Boxing Day (possibly moved to Monday or Tuesday)
99 || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
100 && m == December)
101 // December 31st, 1999 only
102 || (d == 31 && m == December && y == 1999))
103 return false; // NOLINT(readability-simplify-boolean-expr)
104 return true;
105 }
106
107
109 Weekday w = date.weekday();
110 Day d = date.dayOfMonth(), dd = date.dayOfYear();
111 Month m = date.month();
112 Year y = date.year();
113 Day em = easterMonday(y);
114 if (isWeekend(w)
115 // New Year's Day (possibly moved to Monday)
116 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) &&
117 m == January)
118 // Good Friday
119 || (dd == em-3)
120 // Easter Monday
121 || (dd == em)
122 || isBankHoliday(d, w, m, y)
123 // Christmas (possibly moved to Monday or Tuesday)
124 || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
125 && m == December)
126 // Boxing Day (possibly moved to Monday or Tuesday)
127 || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
128 && m == December)
129 // December 31st, 1999 only
130 || (d == 31 && m == December && y == 1999))
131 return false; // NOLINT(readability-simplify-boolean-expr)
132 return true;
133 }
134
135
137 Weekday w = date.weekday();
138 Day d = date.dayOfMonth(), dd = date.dayOfYear();
139 Month m = date.month();
140 Year y = date.year();
141 Day em = easterMonday(y);
142 if (isWeekend(w)
143 // New Year's Day (possibly moved to Monday)
144 || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) &&
145 m == January)
146 // Good Friday
147 || (dd == em-3)
148 // Easter Monday
149 || (dd == em)
150 || isBankHoliday(d, w, m, y)
151 // Christmas (possibly moved to Monday or Tuesday)
152 || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
153 && m == December)
154 // Boxing Day (possibly moved to Monday or Tuesday)
155 || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
156 && m == December)
157 // December 31st, 1999 only
158 || (d == 31 && m == December && y == 1999))
159 return false; // NOLINT(readability-simplify-boolean-expr)
160 return true;
161 }
162
163}
164
static Day easterMonday(Year)
expressed relative to first day of year
Definition: calendar.cpp:199
bool isWeekend(Weekday) const override
Definition: calendar.cpp:195
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
Day dayOfYear() const
One-based (Jan 1st = 1)
Definition: date.hpp:404
bool isBusinessDay(const Date &) const override
bool isBusinessDay(const Date &) const override
bool isBusinessDay(const Date &) const override
UnitedKingdom(Market market=Settlement)
@ Settlement
generic settlement calendar
@ Exchange
London stock-exchange calendar.
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
@ May
Definition: date.hpp:61
@ April
Definition: date.hpp:60
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
@ Monday
Definition: weekday.hpp:42
@ Tuesday
Definition: weekday.hpp:43
Definition: any.hpp:35
UK calendars.