| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl |
| 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 | <http://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/australia.hpp> |
| 21 | |
| 22 | namespace QuantLib { |
| 23 | |
| 24 | Australia::Australia(Australia::Market market) { |
| 25 | // all calendar instances share the same implementation instance |
| 26 | static ext::shared_ptr<Calendar::Impl> settlementImpl( |
| 27 | new Australia::SettlementImpl); |
| 28 | static ext::shared_ptr<Calendar::Impl> asxImpl( |
| 29 | new Australia::AsxImpl); |
| 30 | switch (market) { |
| 31 | case Settlement: |
| 32 | impl_ = settlementImpl; |
| 33 | break; |
| 34 | case ASX: |
| 35 | impl_ = asxImpl; |
| 36 | break; |
| 37 | default: |
| 38 | QL_FAIL("unknown market" ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | bool Australia::SettlementImpl::isBusinessDay(const Date& date) const { |
| 43 | Weekday w = date.weekday(); |
| 44 | Day d = date.dayOfMonth(), dd = date.dayOfYear(); |
| 45 | Month m = date.month(); |
| 46 | Year y = date.year(); |
| 47 | Day em = easterMonday(y); |
| 48 | if (isWeekend(w) |
| 49 | // New Year's Day (possibly moved to Monday) |
| 50 | || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == January) |
| 51 | // Australia Day, January 26th (possibly moved to Monday) |
| 52 | || ((d == 26 || ((d == 27 || d == 28) && w == Monday)) && |
| 53 | m == January) |
| 54 | // Good Friday |
| 55 | || (dd == em-3) |
| 56 | // Easter Monday |
| 57 | || (dd == em) |
| 58 | // ANZAC Day, April 25th |
| 59 | || (d == 25 && m == April) |
| 60 | // Queen's Birthday, second Monday in June |
| 61 | || ((d > 7 && d <= 14) && w == Monday && m == June) |
| 62 | // Bank Holiday, first Monday in August |
| 63 | || (d <= 7 && w == Monday && m == August) |
| 64 | // Labour Day, first Monday in October |
| 65 | || (d <= 7 && w == Monday && m == October) |
| 66 | // Christmas, December 25th (possibly Monday or Tuesday) |
| 67 | || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday))) |
| 68 | && m == December) |
| 69 | // Boxing Day, December 26th (possibly Monday or Tuesday) |
| 70 | || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday))) |
| 71 | && m == December) |
| 72 | // National Day of Mourning for Her Majesty, September 22 (only 2022) |
| 73 | || (d == 22 && m == September && y == 2022)) |
| 74 | return false; // NOLINT(readability-simplify-boolean-expr) |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | bool Australia::AsxImpl::isBusinessDay(const Date& date) const { |
| 79 | Weekday w = date.weekday(); |
| 80 | Day d = date.dayOfMonth(), dd = date.dayOfYear(); |
| 81 | Month m = date.month(); |
| 82 | Year y = date.year(); |
| 83 | Day em = easterMonday(y); |
| 84 | if (isWeekend(w) |
| 85 | // New Year's Day (possibly moved to Monday) |
| 86 | || ((d == 1 || ((d == 2 || d == 3) && w == Monday)) && m == January) |
| 87 | // Australia Day, January 26th (possibly moved to Monday) |
| 88 | || ((d == 26 || ((d == 27 || d == 28) && w == Monday)) && |
| 89 | m == January) |
| 90 | // Good Friday |
| 91 | || (dd == em-3) |
| 92 | // Easter Monday |
| 93 | || (dd == em) |
| 94 | // ANZAC Day, April 25th |
| 95 | || (d == 25 && m == April) |
| 96 | // Queen's Birthday, second Monday in June |
| 97 | || ((d > 7 && d <= 14) && w == Monday && m == June) |
| 98 | // Christmas, December 25th (possibly Monday or Tuesday) |
| 99 | || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday))) |
| 100 | && m == December) |
| 101 | // Boxing Day, December 26th (possibly Monday or Tuesday) |
| 102 | || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday))) |
| 103 | && m == December) |
| 104 | // National Day of Mourning for Her Majesty, September 22 (only 2022) |
| 105 | || (d == 22 && m == September && y == 2022)) |
| 106 | return false; // NOLINT(readability-simplify-boolean-expr) |
| 107 | return true; |
| 108 | } |
| 109 | |
| 110 | } |