/src/quantlib/ql/time/calendars/brazil.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2005, 2006 Piter Dias |
5 | | Copyright (C) 2007 Richard Gomes |
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 | | <https://www.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 | | |
21 | | #include <ql/time/calendars/brazil.hpp> |
22 | | #include <ql/errors.hpp> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | 0 | Brazil::Brazil(Brazil::Market market) { |
27 | | // all calendar instances on the same market share the same |
28 | | // implementation instance |
29 | 0 | static ext::shared_ptr<Calendar::Impl> settlementImpl( |
30 | 0 | new Brazil::SettlementImpl); |
31 | 0 | static ext::shared_ptr<Calendar::Impl> exchangeImpl( |
32 | 0 | new Brazil::ExchangeImpl); |
33 | 0 | switch (market) { |
34 | 0 | case Settlement: |
35 | 0 | impl_ = settlementImpl; |
36 | 0 | break; |
37 | 0 | case Exchange: |
38 | 0 | impl_ = exchangeImpl; |
39 | 0 | break; |
40 | 0 | default: |
41 | 0 | QL_FAIL("unknown market"); |
42 | 0 | } |
43 | 0 | } |
44 | | |
45 | 0 | bool Brazil::SettlementImpl::isBusinessDay(const Date& date) const { |
46 | 0 | Weekday w = date.weekday(); |
47 | 0 | Day d = date.dayOfMonth(); |
48 | 0 | Month m = date.month(); |
49 | 0 | Year y = date.year(); |
50 | 0 | Day dd = date.dayOfYear(); |
51 | 0 | Day em = easterMonday(y); |
52 | |
|
53 | 0 | if (isWeekend(w) |
54 | | // New Year's Day |
55 | 0 | || (d == 1 && m == January) |
56 | | // Tiradentes Day |
57 | 0 | || (d == 21 && m == April) |
58 | | // Labor Day |
59 | 0 | || (d == 1 && m == May) |
60 | | // Independence Day |
61 | 0 | || (d == 7 && m == September) |
62 | | // Nossa Sra. Aparecida Day |
63 | 0 | || (d == 12 && m == October) |
64 | | // All Souls Day |
65 | 0 | || (d == 2 && m == November) |
66 | | // Republic Day |
67 | 0 | || (d == 15 && m == November) |
68 | | // Black Awareness Day |
69 | 0 | || (d == 20 && m == November && y >= 2024) |
70 | | // Christmas |
71 | 0 | || (d == 25 && m == December) |
72 | | // Passion of Christ |
73 | 0 | || (dd == em-3) |
74 | | // Carnival |
75 | 0 | || (dd == em-49 || dd == em-48) |
76 | | // Corpus Christi |
77 | 0 | || (dd == em+59) |
78 | 0 | ) |
79 | 0 | return false; // NOLINT(readability-simplify-boolean-expr) |
80 | 0 | return true; |
81 | 0 | } |
82 | | |
83 | 0 | bool Brazil::ExchangeImpl::isBusinessDay(const Date& date) const { |
84 | 0 | Weekday w = date.weekday(); |
85 | 0 | Day d = date.dayOfMonth(); |
86 | 0 | Month m = date.month(); |
87 | 0 | Year y = date.year(); |
88 | 0 | Day dd = date.dayOfYear(); |
89 | 0 | Day em = easterMonday(y); |
90 | |
|
91 | 0 | if (isWeekend(w) |
92 | | // New Year's Day |
93 | 0 | || (d == 1 && m == January) |
94 | | // Sao Paulo City Day |
95 | 0 | || (d == 25 && m == January && y < 2022) |
96 | | // Tiradentes Day |
97 | 0 | || (d == 21 && m == April) |
98 | | // Labor Day |
99 | 0 | || (d == 1 && m == May) |
100 | | // Revolution Day |
101 | 0 | || (d == 9 && m == July && y < 2022) |
102 | | // Independence Day |
103 | 0 | || (d == 7 && m == September) |
104 | | // Nossa Sra. Aparecida Day |
105 | 0 | || (d == 12 && m == October) |
106 | | // All Souls Day |
107 | 0 | || (d == 2 && m == November) |
108 | | // Republic Day |
109 | 0 | || (d == 15 && m == November) |
110 | | // Black Consciousness Day |
111 | 0 | || (d == 20 && m == November && y >= 2007 && y != 2022 && y != 2023) |
112 | | // Christmas Eve |
113 | 0 | || (d == 24 && m == December) |
114 | | // Christmas |
115 | 0 | || (d == 25 && m == December) |
116 | | // Passion of Christ |
117 | 0 | || (dd == em-3) |
118 | | // Carnival |
119 | 0 | || (dd == em-49 || dd == em-48) |
120 | | // Corpus Christi |
121 | 0 | || (dd == em+59) |
122 | | // last business day of the year |
123 | 0 | || (m == December && (d == 31 || (d >= 29 && w == Friday))) |
124 | 0 | ) |
125 | 0 | return false; // NOLINT(readability-simplify-boolean-expr) |
126 | 0 | return true; |
127 | 0 | } |
128 | | |
129 | | } |
130 | | |