Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added china calendar for the year 2024 #1873

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions ql/time/calendars/china.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace QuantLib {
|| (y == 2021 && (d == 11 || d == 12 || d == 15 || d == 16 || d == 17) && m == February)
|| (y == 2022 && ((d == 31 && m == January) || (d <= 4 && m == February)))
|| (y == 2023 && d >= 23 && d <= 27 && m == January)
|| (y == 2024 && (d == 9 || (d >= 12 && d <= 16)) && m == February)
// Ching Ming Festival
|| (y <= 2008 && d == 4 && m == April)
|| (y == 2009 && d == 6 && m == April)
Expand All @@ -112,6 +113,7 @@ namespace QuantLib {
|| (y == 2021 && d == 5 && m == April)
|| (y == 2022 && d >= 4 && d <= 5 && m == April)
|| (y == 2023 && d == 5 && m == April)
|| (y == 2024 && d >= 4 && d <= 5 && m == April)
// Labor Day
|| (y <= 2007 && d >= 1 && d <= 7 && m == May)
|| (y == 2008 && d >= 1 && d <= 2 && m == May)
Expand All @@ -132,6 +134,7 @@ namespace QuantLib {
|| (y == 2021 && (d == 3 || d == 4 || d == 5) && m == May)
|| (y == 2022 && d >= 2 && d <= 4 && m == May)
|| (y == 2023 && d >= 1 && d <= 3 && m == May)
|| (y == 2024 && d >= 1 && d <= 3 && m == May)
// Tuen Ng Festival
|| (y <= 2008 && d == 9 && m == June)
|| (y == 2009 && (d == 28 || d == 29) && m == May)
Expand All @@ -149,6 +152,7 @@ namespace QuantLib {
|| (y == 2021 && d == 14 && m == June)
|| (y == 2022 && d == 3 && m == June)
|| (y == 2023 && d >= 22 && d <= 23 && m == June)
|| (y == 2024 && d == 10 && m == June)
// Mid-Autumn Festival
|| (y <= 2008 && d == 15 && m == September)
|| (y == 2010 && d >= 22 && d <= 24 && m == September)
Expand All @@ -163,6 +167,7 @@ namespace QuantLib {
|| (y == 2021 && (d == 20 || d == 21) && m == September)
|| (y == 2022 && d == 12 && m == September)
|| (y == 2023 && d == 29 && m == September)
|| (y == 2024 && d >= 16 && d <= 17 && m == September)
// National Day
|| (y <= 2007 && d >= 1 && d <= 7 && m == October)
|| (y == 2008 && ((d >= 29 && m == September) ||
Expand All @@ -183,6 +188,7 @@ namespace QuantLib {
|| (y == 2021 && (d == 1 || d == 4 || d == 5 || d == 6 || d == 7) && m == October)
|| (y == 2022 && d >= 3 && d <= 7 && m == October)
|| (y == 2023 && d >= 2 && d <= 6 && m == October)
|| (y == 2024 && ((d >= 1 && d <= 4) || d == 7) && m == October)
// 70th anniversary of the victory of anti-Japaneses war
|| (y == 2015 && d >= 3 && d <= 4 && m == September)
)
Expand All @@ -195,7 +201,7 @@ namespace QuantLib {
}

bool China::IbImpl::isBusinessDay(const Date& date) const {
static const Date working_weekends[] = {
static const std::set<Date> workingWeekends = {
// 2005
Date(5, February, 2005),
Date(6, February, 2005),
Expand Down Expand Up @@ -338,12 +344,18 @@ namespace QuantLib {
Date(6, May, 2023),
Date(25, June, 2023),
Date(7, October, 2023),
Date(8, October, 2023)
Date(8, October, 2023),
// 2024
Date(4, Feb, 2024),
Date(9, Feb, 2024),
Date(18, Feb, 2024),
Date(7, Apr, 2024),
Date(28, Apr, 2024),
Date(11, May, 2024),
Date(14, Sep, 2024),
Date(29, Sep, 2024),
Date(12, October, 2024)
};
static const Size n =
sizeof(working_weekends)/sizeof(working_weekends[0]);
static const std::set<Date> workingWeekends(working_weekends+0,
working_weekends+n);

// If it is already a SSE business day, it must be a IB business day
return sseImpl->isBusinessDay(date) ||
Expand Down
36 changes: 34 additions & 2 deletions test-suite/calendars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3177,8 +3177,30 @@ BOOST_AUTO_TEST_CASE(testChinaSSE) {
expectedHol.emplace_back(5, October, 2023);
expectedHol.emplace_back(6, October, 2023);

// China Shanghai Securities Exchange holiday list in the year 2024
expectedHol.emplace_back(1, Jan, 2024);
expectedHol.emplace_back(9, Feb, 2024);
expectedHol.emplace_back(12, Feb, 2024);
expectedHol.emplace_back(13, Feb, 2024);
expectedHol.emplace_back(14, Feb, 2024);
expectedHol.emplace_back(15, Feb, 2024);
expectedHol.emplace_back(16, Feb, 2024);
expectedHol.emplace_back(4, April, 2024);
expectedHol.emplace_back(5, April, 2024);
expectedHol.emplace_back(1, May, 2024);
expectedHol.emplace_back(2, May, 2024);
expectedHol.emplace_back(3, May, 2024);
expectedHol.emplace_back(10, Jun, 2024);
expectedHol.emplace_back(16, Sep, 2024);
expectedHol.emplace_back(17, Sep, 2024);
expectedHol.emplace_back(1, Oct, 2024);
expectedHol.emplace_back(2, Oct, 2024);
expectedHol.emplace_back(3, Oct, 2024);
expectedHol.emplace_back(4, Oct, 2024);
expectedHol.emplace_back(7, Oct, 2024);

Calendar c = China(China::SSE);
std::vector<Date> hol = c.holidayList(Date(1, January, 2014), Date(31, December, 2023));
std::vector<Date> hol = c.holidayList(Date(1, January, 2014), Date(31, December, 2024));

for (Size i = 0; i < std::min<Size>(hol.size(), expectedHol.size()); i++) {
if (hol[i] != expectedHol[i])
Expand Down Expand Up @@ -3276,9 +3298,19 @@ BOOST_AUTO_TEST_CASE(testChinaIB) {
expectedWorkingWeekEnds.emplace_back(7, October, 2023);
expectedWorkingWeekEnds.emplace_back(8, October, 2023);

// China Inter Bank working weekends list in the year 2024
expectedWorkingWeekEnds.emplace_back(4, Feb, 2024);
expectedWorkingWeekEnds.emplace_back(18, Feb, 2024);
expectedWorkingWeekEnds.emplace_back(7, April, 2024);
expectedWorkingWeekEnds.emplace_back(28, April, 2024);
expectedWorkingWeekEnds.emplace_back(11, May, 2024);
expectedWorkingWeekEnds.emplace_back(14, Sep, 2024);
expectedWorkingWeekEnds.emplace_back(29, Sep, 2024);
expectedWorkingWeekEnds.emplace_back(12, October, 2024);

Calendar c = China(China::IB);
Date start(1, Jan, 2014);
Date end(31, Dec, 2023);
Date end(31, Dec, 2024);

Size k = 0;

Expand Down