Coverage Report

Created: 2025-09-04 07:11

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