QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
brazil.cpp
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
21#include <ql/time/calendars/brazil.hpp>
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 // Christmas
69 || (d == 25 && m == December)
70 // Passion of Christ
71 || (dd == em-3)
72 // Carnival
73 || (dd == em-49 || dd == em-48)
74 // Corpus Christi
75 || (dd == em+59)
76 )
77 return false; // NOLINT(readability-simplify-boolean-expr)
78 return true;
79 }
80
81 bool Brazil::ExchangeImpl::isBusinessDay(const Date& date) const {
82 Weekday w = date.weekday();
83 Day d = date.dayOfMonth();
84 Month m = date.month();
85 Year y = date.year();
86 Day dd = date.dayOfYear();
87 Day em = easterMonday(y);
88
89 if (isWeekend(w)
90 // New Year's Day
91 || (d == 1 && m == January)
92 // Sao Paulo City Day
93 || (d == 25 && m == January)
94 // Tiradentes Day
95 || (d == 21 && m == April)
96 // Labor Day
97 || (d == 1 && m == May)
98 // Revolution Day
99 || (d == 9 && m == July)
100 // Independence Day
101 || (d == 7 && m == September)
102 // Nossa Sra. Aparecida Day
103 || (d == 12 && m == October)
104 // All Souls Day
105 || (d == 2 && m == November)
106 // Republic Day
107 || (d == 15 && m == November)
108 // Black Consciousness Day
109 || (d == 20 && m == November && y >= 2007)
110 // Christmas Eve
111 || (d == 24 && m == December)
112 // Christmas
113 || (d == 25 && m == December)
114 // Passion of Christ
115 || (dd == em-3)
116 // Carnival
117 || (dd == em-49 || dd == em-48)
118 // Corpus Christi
119 || (dd == em+59)
120 // last business day of the year
121 || (m == December && (d == 31 || (d >= 29 && w == Friday)))
122 )
123 return false; // NOLINT(readability-simplify-boolean-expr)
124 return true;
125 }
126
127}
128
bool isBusinessDay(const Date &) const override
Definition: brazil.cpp:81
bool isBusinessDay(const Date &) const override
Definition: brazil.cpp:45
Brazil(Market market=Settlement)
Definition: brazil.cpp:26
Market
Brazilian calendars.
Definition: brazil.hpp:91
@ Settlement
generic settlement calendar
Definition: brazil.hpp:91
@ Exchange
BOVESPA calendar.
Definition: brazil.hpp:92
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
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