| 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 | |
| 24 | namespace QuantLib { |
| 25 | |
| 26 | Brazil::Brazil(Brazil::Market market) { |
| 27 | // all calendar instances on the same market share the same |
| 28 | // implementation instance |
| 29 | static ext::shared_ptr<Calendar::Impl> settlementImpl( |
| 30 | new Brazil::SettlementImpl); |
| 31 | static ext::shared_ptr<Calendar::Impl> exchangeImpl( |
| 32 | new Brazil::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 | |
| 45 | bool Brazil::SettlementImpl::isBusinessDay(const Date& date) const { |
| 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 | |
| 129 |
