Skip to content

Commit

Permalink
Sync from QuantLib 1.37 (rc)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Jan 13, 2025
1 parent 6498dd3 commit 8cd9096
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 27 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2025-01-13 Dirk Eddelbuettel <[email protected]>

* src/ql/time/calendars/newzealand.?pp: Updated from QuantLib 1.37 (rc)
* src/ql/time/calendars/unitedstates.cpp: Idem

2024-10-15 Dirk Eddelbuettel <[email protected]>

* DESCRIPTION (Version, Date): Release 0.0.13
Expand Down
61 changes: 49 additions & 12 deletions src/ql/time/calendars/newzealand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@

namespace QuantLib {

NewZealand::NewZealand() {
// all calendar instances share the same implementation instance
static ext::shared_ptr<Calendar::Impl> impl(new NewZealand::Impl);
impl_ = impl;
}

bool NewZealand::Impl::isBusinessDay(const Date& date) const {
bool NewZealand::CommonImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth(), dd = date.dayOfYear();
Month m = date.month();
Expand All @@ -40,16 +34,14 @@ namespace QuantLib {
// Day after New Year's Day (possibly moved to Mon or Tuesday)
|| ((d == 2 || (d == 4 && (w == Monday || w == Tuesday))) &&
m == January)
// Anniversary Day, Monday nearest January 22nd
|| ((d >= 19 && d <= 25) && w == Monday && m == January)
// Waitangi Day. February 6th ("Mondayised" since 2013)
// Waitangi Day. February 6th (possibly moved to Monday since 2013)
|| (d == 6 && m == February)
|| ((d == 7 || d == 8) && w == Monday && m == February && y > 2013)
// Good Friday
|| (dd == em-3)
// Easter Monday
|| (dd == em)
// ANZAC Day. April 25th ("Mondayised" since 2013)
// ANZAC Day. April 25th (possibly moved to Monday since 2013)
|| (d == 25 && m == April)
|| ((d == 26 || d == 27) && w == Monday && m == April && y > 2013)
// Queen's Birthday, first Monday in June
Expand Down Expand Up @@ -81,9 +73,54 @@ namespace QuantLib {
|| (d == 14 && m == July && (y == 2023 || y == 2028))
|| (d == 15 && m == July && (y == 2039 || y == 2050))
|| (d == 18 && m == July && y == 2036)
|| (d == 19 && m == July && (y == 2041 || y == 2047)))
|| (d == 19 && m == July && (y == 2041 || y == 2047))
// Queen Elizabeth's funeral
|| (d == 26 && m == September && y == 2022))
return false; // NOLINT(readability-simplify-boolean-expr)
return true;
}

bool NewZealand::WellingtonImpl::isBusinessDay(const Date& date) const {
if (!NewZealand::CommonImpl::isBusinessDay(date))
return false;
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
// Anniversary Day, Monday nearest January 22nd
if ((d >= 19 && d <= 25) && w == Monday && m == January)
return false; // NOLINT(readability-simplify-boolean-expr)
return true;
}

bool NewZealand::AucklandImpl::isBusinessDay(const Date& date) const {
if (!NewZealand::CommonImpl::isBusinessDay(date))
return false;
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
// Anniversary Day, Monday nearest January 29nd
if ((d >= 26 && w == Monday && m == January)
|| (d == 1 && w == Monday && m == February))
return false; // NOLINT(readability-simplify-boolean-expr)
return true;
}


NewZealand::NewZealand(Market market) {
// all calendar instances for a given market share the same implementation instance
static auto wellingtonImpl = ext::make_shared<NewZealand::WellingtonImpl>();
static auto aucklandImpl = ext::make_shared<NewZealand::AucklandImpl>();

switch (market) {
case Wellington:
impl_ = wellingtonImpl;
break;
case Auckland:
impl_ = aucklandImpl;
break;
default:
QL_FAIL("unknown market");
}
}

}
44 changes: 31 additions & 13 deletions src/ql/time/calendars/newzealand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,33 @@
namespace QuantLib {

//! New Zealand calendar
/*! Holidays:
/*! Common holidays:
<ul>
<li>Saturdays</li>
<li>Sundays</li>
<li>New Year's Day, January 1st (possibly moved to Monday or
Tuesday)</li>
<li>Day after New Year's Day, January 2st (possibly moved to
Monday or Tuesday)</li>
<li>Anniversary Day, Monday nearest January 22nd</li>
<li>Waitangi Day. February 6th</li>
<li>New Year's Day, January 1st (possibly moved to Monday or Tuesday)</li>
<li>Day after New Year's Day, January 2st (possibly moved to Monday or Tuesday)</li>
<li>Waitangi Day. February 6th (possibly moved to Monday since 2013)</li>
<li>Good Friday</li>
<li>Easter Monday</li>
<li>ANZAC Day. April 25th</li>
<li>ANZAC Day. April 25th (possibly moved to Monday since 2013)</li>
<li>Queen's Birthday, first Monday in June</li>
<li>Labour Day, fourth Monday in October</li>
<li>Christmas, December 25th (possibly moved to Monday or Tuesday)</li>
<li>Boxing Day, December 26th (possibly moved to Monday or
Tuesday)</li>
<li>Boxing Day, December 26th (possibly moved to Monday or Tuesday)</li>
<li>Matariki, in June or July, official calendar released for years 2022-2052</li>
</ul>
Additional holidays for Wellington:
<ul>
<li>Anniversary Day, Monday nearest January 22nd</li>
</ul>
Additional holidays for Auckland:
<ul>
<li>Anniversary Day, Monday nearest January 29nd</li>
</ul>
\note The holiday rules for New Zealand were documented by
David Gilbert for IDB (http://www.jrefinery.com/ibd/)
The Matariki holiday calendar has been released by the NZ Government
Expand All @@ -58,13 +65,24 @@ namespace QuantLib {
*/
class NewZealand : public Calendar {
private:
class Impl final : public Calendar::WesternImpl {
class CommonImpl : public Calendar::WesternImpl {
public:
bool isBusinessDay(const Date&) const override;
};
class WellingtonImpl final : public CommonImpl {
public:
std::string name() const override { return "New Zealand (Wellington)"; }
bool isBusinessDay(const Date&) const override;
};
class AucklandImpl final : public CommonImpl {
public:
std::string name() const override { return "New Zealand"; }
std::string name() const override { return "New Zealand (Auckland)"; }
bool isBusinessDay(const Date&) const override;
};
public:
NewZealand();
//! NZ calendars
enum Market { Wellington, Auckland };
explicit NewZealand(Market market = Wellington);
};

}
Expand Down
7 changes: 5 additions & 2 deletions src/ql/time/calendars/unitedstates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Copyright (C) 2017 Peter Caspers
Copyright (C) 2017 Oleg Kulkov
Copyright (C) 2023 Skandinaviska Enskilda Banken AB (publ)
Copyright (C) 2024 Dirk Eddelbuettel
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
Expand Down Expand Up @@ -219,8 +220,10 @@ namespace QuantLib {
return false;

// Special closings
if (// President Bush's Funeral
(y == 2018 && m == December && d == 5)
if (// President Carter's Funeral
(y == 2025 && m == January && d == 9)
// President Bush's Funeral
|| (y == 2018 && m == December && d == 5)
// Hurricane Sandy
|| (y == 2012 && m == October && (d == 29 || d == 30))
// President Ford's funeral
Expand Down

0 comments on commit 8cd9096

Please sign in to comment.