QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
brazil.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) 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 <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
27 // all calendar instances on the same market share the same
28 // implementation instance
29 static ext::shared_ptr<Calendar::Impl> settlementImpl(
31 static ext::shared_ptr<Calendar::Impl> exchangeImpl(
33 switch (market) {
34 case Settlement:
35 impl_ = settlementImpl;
36 break;
37 case Exchange:
38 impl_ = exchangeImpl;
39 break;
40 default:
41 QL_FAIL("unknown market");
42 }
43 }
44
46 Weekday w = date.weekday();
47 Day d = date.dayOfMonth();
48 Month m = date.month();
49 Year y = date.year();
50 Day dd = date.dayOfYear();
51 Day em = easterMonday(y);
52
53 if (isWeekend(w)
54 // New Year's Day
55 || (d == 1 && m == January)
56 // Tiradentes Day
57 || (d == 21 && m == April)
58 // Labor Day
59 || (d == 1 && m == May)
60 // Independence Day
61 || (d == 7 && m == September)
62 // Nossa Sra. Aparecida Day
63 || (d == 12 && m == October)
64 // All Souls Day
65 || (d == 2 && m == November)
66 // Republic Day
67 || (d == 15 && m == November)
68 // Black Awareness Day
69 || (d == 20 && m == November && y >= 2024)
70 // Christmas
71 || (d == 25 && m == December)
72 // Passion of Christ
73 || (dd == em-3)
74 // Carnival
75 || (dd == em-49 || dd == em-48)
76 // Corpus Christi
77 || (dd == em+59)
78 )
79 return false; // NOLINT(readability-simplify-boolean-expr)
80 return true;
81 }
82
83 bool Brazil::ExchangeImpl::isBusinessDay(const Date& date) const {
84 Weekday w = date.weekday();
85 Day d = date.dayOfMonth();
86 Month m = date.month();
87 Year y = date.year();
88 Day dd = date.dayOfYear();
89 Day em = easterMonday(y);
90
91 if (isWeekend(w)
92 // New Year's Day
93 || (d == 1 && m == January)
94 // Sao Paulo City Day
95 || (d == 25 && m == January && y < 2022)
96 // Tiradentes Day
97 || (d == 21 && m == April)
98 // Labor Day
99 || (d == 1 && m == May)
100 // Revolution Day
101 || (d == 9 && m == July)
102 // Independence Day
103 || (d == 7 && m == September)
104 // Nossa Sra. Aparecida Day
105 || (d == 12 && m == October)
106 // All Souls Day
107 || (d == 2 && m == November)
108 // Republic Day
109 || (d == 15 && m == November)
110 // Black Consciousness Day
111 || (d == 20 && m == November && y >= 2007)
112 // Christmas Eve
113 || (d == 24 && m == December)
114 // Christmas
115 || (d == 25 && m == December)
116 // Passion of Christ
117 || (dd == em-3)
118 // Carnival
119 || (dd == em-49 || dd == em-48)
120 // Corpus Christi
121 || (dd == em+59)
122 // last business day of the year
123 || (m == December && (d == 31 || (d >= 29 && w == Friday)))
124 )
125 return false; // NOLINT(readability-simplify-boolean-expr)
126 return true;
127 }
128
129}
130
Brazilian calendar.
bool isBusinessDay(const Date &) const override
Definition: brazil.cpp:83
bool isBusinessDay(const Date &) const override
Definition: brazil.cpp:45
Brazil(Market market=Settlement)
Definition: brazil.cpp:26
Market
Brazilian calendars.
Definition: brazil.hpp:92
@ Settlement
generic settlement calendar
Definition: brazil.hpp:92
@ Exchange
BOVESPA calendar.
Definition: brazil.hpp:93
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
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
@ January
Definition: date.hpp:57
@ July
Definition: date.hpp:63
@ May
Definition: date.hpp:61
@ April
Definition: date.hpp:60
@ November
Definition: date.hpp:67
@ October
Definition: date.hpp:66
@ September
Definition: date.hpp:65
@ Friday
Definition: weekday.hpp:46
Definition: any.hpp:35