/src/quantlib/ql/time/calendars/chile.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2021 Anubhav Pandey |
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 | | <https://www.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/chile.hpp> |
21 | | |
22 | | namespace QuantLib { |
23 | | |
24 | | namespace { |
25 | | |
26 | | // Celebrated on the Winter Solstice day, except in 2021, when it was the day after. |
27 | 0 | inline bool isAboriginalPeopleDay(Day d, Month m, Year y) { |
28 | 0 | static const unsigned char aboriginalPeopleDay[] = { |
29 | 0 | 21, 21, 21, 20, 20, 21, 21, 20, 20, // 2021-2029 |
30 | 0 | 21, 21, 20, 20, 21, 21, 20, 20, 21, 21, // 2030-2039 |
31 | 0 | 20, 20, 21, 21, 20, 20, 21, 21, 20, 20, // 2040-2049 |
32 | 0 | 20, 21, 20, 20, 20, 21, 20, 20, 20, 21, // 2050-2059 |
33 | 0 | 20, 20, 20, 21, 20, 20, 20, 21, 20, 20, // 2060-2069 |
34 | 0 | 20, 21, 20, 20, 20, 21, 20, 20, 20, 20, // 2070-2079 |
35 | 0 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 2080-2089 |
36 | 0 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, // 2090-2099 |
37 | 0 | 21, 21, 21, 21, 21, 21, 21, 21, 20, 21, // 2100-2109 |
38 | 0 | 21, 21, 20, 21, 21, 21, 20, 21, 21, 21, // 2110-2119 |
39 | 0 | 20, 21, 21, 21, 20, 21, 21, 21, 20, 21, // 2120-2129 |
40 | 0 | 21, 21, 20, 21, 21, 21, 20, 20, 21, 21, // 2130-2139 |
41 | 0 | 20, 20, 21, 21, 20, 20, 21, 21, 20, 20, // 2140-2149 |
42 | 0 | 21, 21, 20, 20, 21, 21, 20, 20, 21, 21, // 2150-2159 |
43 | 0 | 20, 20, 21, 21, 20, 20, 21, 21, 20, 20, // 2160-2169 |
44 | 0 | 20, 21, 20, 20, 20, 21, 20, 20, 20, 21, // 2170-2179 |
45 | 0 | 20, 20, 20, 21, 20, 20, 20, 21, 20, 20, // 2180-2189 |
46 | 0 | 20, 21, 20, 20, 20, 21, 20, 20, 20, 20 // 2190-2199 |
47 | 0 | }; |
48 | 0 | return m == June && y >= 2021 && d == aboriginalPeopleDay[y-2021]; |
49 | 0 | } |
50 | | |
51 | | } |
52 | | |
53 | 0 | Chile::Chile(Market) { |
54 | | // all calendar instances share the same implementation instance |
55 | 0 | static ext::shared_ptr<Calendar::Impl> impl(new Chile::SseImpl); |
56 | 0 | impl_ = impl; |
57 | 0 | } |
58 | | |
59 | 0 | bool Chile::SseImpl::isBusinessDay(const Date& date) const { |
60 | 0 | Weekday w = date.weekday(); |
61 | 0 | Day d = date.dayOfMonth(); |
62 | 0 | Month m = date.month(); |
63 | 0 | Year y = date.year(); |
64 | 0 | Day dd = date.dayOfYear(); |
65 | 0 | Day em = easterMonday(y); |
66 | |
|
67 | 0 | if (isWeekend(w) |
68 | | // New Year's Day |
69 | 0 | || (d == 1 && m == January) |
70 | 0 | || (d == 2 && m == January && w == Monday && y > 2016) |
71 | | // Papal visit in 2018 |
72 | 0 | || (d == 16 && m == January && y == 2018) |
73 | | // Good Friday |
74 | 0 | || (dd == em-3) |
75 | | // Easter Saturday |
76 | 0 | || (dd == em-2) |
77 | | // Census Day in 2017 |
78 | 0 | || (d == 19 && m == April && y == 2017) |
79 | | // Labour Day |
80 | 0 | || (d == 1 && m == May) |
81 | | // Navy Day |
82 | 0 | || (d == 21 && m == May) |
83 | | // Day of Aboriginal People |
84 | 0 | || isAboriginalPeopleDay(d, m, y) |
85 | | // St. Peter and St. Paul |
86 | 0 | || (d >= 26 && d <= 29 && m == June && w == Monday) |
87 | 0 | || (d == 2 && m == July && w == Monday) |
88 | | // Our Lady of Mount Carmel |
89 | 0 | || (d == 16 && m == July) |
90 | | // Assumption Day |
91 | 0 | || (d == 15 && m == August) |
92 | | // Independence Day |
93 | 0 | || (d == 16 && m == September && y == 2022) |
94 | 0 | || (d == 17 && m == September && ((w == Monday && y >= 2007) || (w == Friday && y > 2016))) |
95 | 0 | || (d == 18 && m == September) |
96 | | // Army Day |
97 | 0 | || (d == 19 && m == September) |
98 | 0 | || (d == 20 && m == September && w == Friday && y >= 2007) |
99 | | // Discovery of Two Worlds |
100 | 0 | || (d >= 9 && d <= 12 && m == October && w == Monday) |
101 | 0 | || (d == 15 && m == October && w == Monday) |
102 | | // Reformation Day |
103 | 0 | || (((d == 27 && m == October && w == Friday) |
104 | 0 | || (d == 31 && m == October && w != Tuesday && w != Wednesday) |
105 | 0 | || (d == 2 && m == November && w == Friday)) && y >= 2008) |
106 | | // All Saints' Day |
107 | 0 | || (d == 1 && m == November) |
108 | | // Immaculate Conception |
109 | 0 | || (d == 8 && m == December) |
110 | | // Christmas Day |
111 | 0 | || (d == 25 && m == December) |
112 | | // New Year's Eve |
113 | 0 | || (d == 31 && m == December) |
114 | 0 | ) |
115 | 0 | return false; |
116 | | |
117 | 0 | return true; |
118 | 0 | } |
119 | | |
120 | | } |
121 | | |