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