QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
germany.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2004 Ferdinando Ametrano
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/germany.hpp>
21#include <ql/errors.hpp>
22
23namespace QuantLib {
24
26 // all calendar instances on the same market share the same
27 // implementation instance
28 static ext::shared_ptr<Calendar::Impl> settlementImpl(
30 static ext::shared_ptr<Calendar::Impl> frankfurtStockExchangeImpl(
32 static ext::shared_ptr<Calendar::Impl> xetraImpl(
34 static ext::shared_ptr<Calendar::Impl> eurexImpl(
36 static ext::shared_ptr<Calendar::Impl> euwaxImpl(
38
39 switch (market) {
40 case Settlement:
41 impl_ = settlementImpl;
42 break;
44 impl_ = frankfurtStockExchangeImpl;
45 break;
46 case Xetra:
47 impl_ = xetraImpl;
48 break;
49 case Eurex:
50 impl_ = eurexImpl;
51 break;
52 case Euwax:
53 impl_ = euwaxImpl;
54 break;
55 default:
56 QL_FAIL("unknown market");
57 }
58 }
59
60
62 Weekday w = date.weekday();
63 Day d = date.dayOfMonth(), dd = date.dayOfYear();
64 Month m = date.month();
65 Year y = date.year();
66 Day em = easterMonday(y);
67 if (isWeekend(w)
68 // New Year's Day
69 || (d == 1 && m == January)
70 // Good Friday
71 || (dd == em-3)
72 // Easter Monday
73 || (dd == em)
74 // Ascension Thursday
75 || (dd == em+38)
76 // Whit Monday
77 || (dd == em+49)
78 // Corpus Christi
79 || (dd == em+59)
80 // Labour Day
81 || (d == 1 && m == May)
82 // National Day
83 || (d == 3 && m == October)
84 // Christmas Eve
85 || (d == 24 && m == December)
86 // Christmas
87 || (d == 25 && m == December)
88 // Boxing Day
89 || (d == 26 && m == December))
90 return false; // NOLINT(readability-simplify-boolean-expr)
91 return true;
92 }
93
95 const Date& date) const {
96 Weekday w = date.weekday();
97 Day d = date.dayOfMonth(), dd = date.dayOfYear();
98 Month m = date.month();
99 Year y = date.year();
100 Day em = easterMonday(y);
101 if (isWeekend(w)
102 // New Year's Day
103 || (d == 1 && m == January)
104 // Good Friday
105 || (dd == em-3)
106 // Easter Monday
107 || (dd == em)
108 // Labour Day
109 || (d == 1 && m == May)
110 // Christmas' Eve
111 || (d == 24 && m == December)
112 // Christmas
113 || (d == 25 && m == December)
114 // Christmas Day
115 || (d == 26 && m == December))
116 return false; // NOLINT(readability-simplify-boolean-expr)
117 return true;
118 }
119
120 bool Germany::XetraImpl::isBusinessDay(const Date& date) const {
121 Weekday w = date.weekday();
122 Day d = date.dayOfMonth(), dd = date.dayOfYear();
123 Month m = date.month();
124 Year y = date.year();
125 Day em = easterMonday(y);
126 if (isWeekend(w)
127 // New Year's Day
128 || (d == 1 && m == January)
129 // Good Friday
130 || (dd == em-3)
131 // Easter Monday
132 || (dd == em)
133 // Labour Day
134 || (d == 1 && m == May)
135 // Christmas' Eve
136 || (d == 24 && m == December)
137 // Christmas
138 || (d == 25 && m == December)
139 // Christmas Day
140 || (d == 26 && m == December))
141 return false; // NOLINT(readability-simplify-boolean-expr)
142 return true;
143 }
144
145 bool Germany::EurexImpl::isBusinessDay(const Date& date) const {
146 Weekday w = date.weekday();
147 Day d = date.dayOfMonth(), dd = date.dayOfYear();
148 Month m = date.month();
149 Year y = date.year();
150 Day em = easterMonday(y);
151 if (isWeekend(w)
152 // New Year's Day
153 || (d == 1 && m == January)
154 // Good Friday
155 || (dd == em-3)
156 // Easter Monday
157 || (dd == em)
158 // Labour Day
159 || (d == 1 && m == May)
160 // Christmas' Eve
161 || (d == 24 && m == December)
162 // Christmas
163 || (d == 25 && m == December)
164 // Christmas Day
165 || (d == 26 && m == December)
166 // New Year's Eve
167 || (d == 31 && m == December))
168 return false; // NOLINT(readability-simplify-boolean-expr)
169 return true;
170 }
171
172 bool Germany::EuwaxImpl::isBusinessDay(const Date& date) const {
173 Weekday w = date.weekday();
174 Day d = date.dayOfMonth(), dd = date.dayOfYear();
175 Month m = date.month();
176 Year y = date.year();
177 Day em = easterMonday(y);
178 if ((w == Saturday || w == Sunday)
179 // New Year's Day
180 || (d == 1 && m == January)
181 // Good Friday
182 || (dd == em-3)
183 // Easter Monday
184 || (dd == em)
185 // Labour Day
186 || (d == 1 && m == May)
187 // Whit Monday
188 || (dd == em+49)
189 // Christmas' Eve
190 || (d == 24 && m == December)
191 // Christmas
192 || (d == 25 && m == December)
193 // Christmas Day
194 || (d == 26 && m == December))
195 return false; // NOLINT(readability-simplify-boolean-expr)
196 return true;
197 }
198}
199
static Day easterMonday(Year)
expressed relative to first day of year
Definition: calendar.cpp:193
bool isWeekend(Weekday) const override
Definition: calendar.cpp:189
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
Definition: germany.cpp:145
bool isBusinessDay(const Date &) const override
Definition: germany.cpp:172
bool isBusinessDay(const Date &) const override
Definition: germany.cpp:94
bool isBusinessDay(const Date &) const override
Definition: germany.cpp:61
bool isBusinessDay(const Date &) const override
Definition: germany.cpp:120
Germany(Market market=FrankfurtStockExchange)
Definition: germany.cpp:25
Market
German calendars.
Definition: germany.hpp:142
@ Settlement
generic settlement calendar
Definition: germany.hpp:142
@ FrankfurtStockExchange
Frankfurt stock-exchange.
Definition: germany.hpp:143
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
@ January
Definition: date.hpp:57
@ May
Definition: date.hpp:61
@ October
Definition: date.hpp:66
@ Sunday
Definition: weekday.hpp:41
@ Saturday
Definition: weekday.hpp:47
Definition: any.hpp:35