QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
newzealand.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) 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
21
22namespace QuantLib {
23
25 Weekday w = date.weekday();
26 Day d = date.dayOfMonth(), dd = date.dayOfYear();
27 Month m = date.month();
28 Year y = date.year();
29 Day em = easterMonday(y);
30 if (isWeekend(w)
31 // New Year's Day (possibly moved to Monday or Tuesday)
32 || ((d == 1 || (d == 3 && (w == Monday || w == Tuesday))) &&
33 m == January)
34 // Day after New Year's Day (possibly moved to Mon or Tuesday)
35 || ((d == 2 || (d == 4 && (w == Monday || w == Tuesday))) &&
36 m == January)
37 // Waitangi Day. February 6th (possibly moved to Monday since 2013)
38 || (d == 6 && m == February)
39 || ((d == 7 || d == 8) && w == Monday && m == February && y > 2013)
40 // Good Friday
41 || (dd == em-3)
42 // Easter Monday
43 || (dd == em)
44 // ANZAC Day. April 25th (possibly moved to Monday since 2013)
45 || (d == 25 && m == April)
46 || ((d == 26 || d == 27) && w == Monday && m == April && y > 2013)
47 // Queen's Birthday, first Monday in June
48 || (d <= 7 && w == Monday && m == June)
49 // Labour Day, fourth Monday in October
50 || ((d >= 22 && d <= 28) && w == Monday && m == October)
51 // Christmas, December 25th (possibly Monday or Tuesday)
52 || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
53 && m == December)
54 // Boxing Day, December 26th (possibly Monday or Tuesday)
55 || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
56 && m == December)
57 // Matariki, it happens on Friday in June or July
58 // official calendar released by the NZ government for the
59 // next 30 years
60 || (d == 20 && m == June && y == 2025)
61 || (d == 21 && m == June && (y == 2030 || y == 2052))
62 || (d == 24 && m == June && (y == 2022 || y == 2033 || y == 2044))
63 || (d == 25 && m == June && (y == 2027 || y == 2038 || y == 2049))
64 || (d == 28 && m == June && y == 2024)
65 || (d == 29 && m == June && (y == 2035 || y == 2046))
66 || (d == 30 && m == June && y == 2051)
67 || (d == 2 && m == July && y == 2032)
68 || (d == 3 && m == July && (y == 2043 || y == 2048))
69 || (d == 6 && m == July && (y == 2029 || y == 2040))
70 || (d == 7 && m == July && (y == 2034 || y == 2045))
71 || (d == 10 && m == July && (y == 2026 || y == 2037))
72 || (d == 11 && m == July && (y == 2031 || y == 2042))
73 || (d == 14 && m == July && (y == 2023 || y == 2028))
74 || (d == 15 && m == July && (y == 2039 || y == 2050))
75 || (d == 18 && m == July && y == 2036)
76 || (d == 19 && m == July && (y == 2041 || y == 2047))
77 // Queen Elizabeth's funeral
78 || (d == 26 && m == September && y == 2022))
79 return false; // NOLINT(readability-simplify-boolean-expr)
80 return true;
81 }
82
85 return false;
86 Weekday w = date.weekday();
87 Day d = date.dayOfMonth();
88 Month m = date.month();
89 // Anniversary Day, Monday nearest January 22nd
90 if ((d >= 19 && d <= 25) && w == Monday && m == January)
91 return false; // NOLINT(readability-simplify-boolean-expr)
92 return true;
93 }
94
97 return false;
98 Weekday w = date.weekday();
99 Day d = date.dayOfMonth();
100 Month m = date.month();
101 // Anniversary Day, Monday nearest January 29nd
102 if ((d >= 26 && w == Monday && m == January)
103 || (d == 1 && w == Monday && m == February))
104 return false; // NOLINT(readability-simplify-boolean-expr)
105 return true;
106 }
107
108
110 // all calendar instances for a given market share the same implementation instance
111 static auto wellingtonImpl = ext::make_shared<NewZealand::WellingtonImpl>();
112 static auto aucklandImpl = ext::make_shared<NewZealand::AucklandImpl>();
113
114 switch (market) {
115 case Wellington:
116 impl_ = wellingtonImpl;
117 break;
118 case Auckland:
119 impl_ = aucklandImpl;
120 break;
121 default:
122 QL_FAIL("unknown market");
123 }
124 }
125
126}
static Day easterMonday(Year)
expressed relative to first day of year
Definition: calendar.cpp:199
bool isWeekend(Weekday) const override
Definition: calendar.cpp:195
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:396
Weekday weekday() const
Definition: date.hpp:391
Day dayOfYear() const
One-based (Jan 1st = 1)
Definition: date.hpp:400
bool isBusinessDay(const Date &) const override
Definition: newzealand.cpp:95
bool isBusinessDay(const Date &) const override
Definition: newzealand.cpp:24
bool isBusinessDay(const Date &) const override
Definition: newzealand.cpp:83
NewZealand(Market market=Wellington)
Definition: newzealand.cpp:109
Market
NZ calendars.
Definition: newzealand.hpp:84
#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
@ February
Definition: date.hpp:58
@ April
Definition: date.hpp:60
@ October
Definition: date.hpp:66
@ June
Definition: date.hpp:62
@ September
Definition: date.hpp:65
@ Monday
Definition: weekday.hpp:42
@ Tuesday
Definition: weekday.hpp:43
Definition: any.hpp:37
New Zealand calendar.