QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
saudiarabia.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) 2004 FIMAT Group
5 Copyright (C) 2007, 2011 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
22#include <ql/errors.hpp>
23#include <algorithm>
24
25namespace QuantLib {
26
27 namespace {
28
29 bool isTrueWeekend(Date d) {
30 // The Saudi weekend was changed from 29th June 2013
31 Weekday w = d.weekday();
32 return (d < Date(29, June, 2013)) ?
33 (w == Thursday || w == Friday) :
34 (w == Friday || w == Saturday);
35 }
36
37 // In 2015 and 2014, the Eid holidays of the Tadawul Exchange
38 // have been from Eid-1 to Eid+4
39 // Sometimes, slightly longer holidays are observed
40 // But conservatively, we take Eid-1 to Eid+4 as the holiday
41
42 // Eid Date Holiday Offset Remarks
43 // 2015-09-23 22-27 -1,+4 later extended to 22-28 or -1+5
44 // 2015-07-17 18-21 -1,+4
45 // 2014-10-05 03-11 -1,+4 because of weekend 03-11 is same as 04-09
46 // 2014-07-28 25-03 -1,+4 because of weekend 25-03 is same as 27-01
47 // 2013-10-15 11-19 -2,+4 because of weekend 11-19 is same as 13-19
48 // 2013-08-08 06-12 -2,+4
49 // 2012-10-26 25-03 -1,+5 because of weekend 25-03 is same as 25-31
50 // 2012-08-19 16-24 -1,+4 because of weekend 16-24 is same as 18-23
51
52 bool isEidAlAdha(Date d) {
53 // Eid al Adha dates taken from:
54 // https://en.wikipedia.org/wiki/Eid_al-Adha#Eid_al-Adha_in_the_Gregorian_calendar
55 static std::vector<Date> EidAlAdha = {
56 Date(7, April, 1998),
57 Date(27, March, 1999),
58 Date(16, March, 2000),
59 Date(5, March, 2001),
60 Date(23, February, 2002),
61 Date(12, February, 2003),
62 Date(1, February, 2004),
63 Date(21, January, 2005),
64 Date(10, January, 2006),
65 Date(31, December, 2006),
66 Date(20, December, 2007),
67 Date(8, December, 2008),
68 Date(27, November, 2009),
69 Date(16, November, 2010),
70 Date(6, November, 2011),
71 Date(26, October, 2012),
72 Date(15, October, 2013),
73 Date(4, October, 2014),
74 Date(24, September, 2015),
75 Date(11, September, 2016),
76 Date(1, September, 2017),
77 Date(23, August, 2018),
78 Date(12, August, 2019),
79 Date(31, July, 2020),
80 Date(20, July, 2021),
81 Date(10, July, 2022)
82 };
83
84 return std::any_of(EidAlAdha.begin(), EidAlAdha.end(),
85 [=](Date p) { return d >= p - 1 && d <= p + 4; });
86 }
87
88 bool isEidAlFitr(Date d) {
89 // Eid al Fitr dates taken from:
90 // https://en.wikipedia.org/wiki/Eid_al-Fitr#In_the_Gregorian_calendar
91 static std::vector<Date> EidAlFitr = {
92 Date(16, Dec, 2001),
93 Date(5, Dec, 2002),
94 Date(25, Nov, 2003),
95 Date(13, Nov, 2004),
96 Date(3, Nov, 2005),
97 Date(23, Oct, 2006),
98 Date(12, Oct, 2007),
99 Date(30, Sep, 2008),
100 Date(20, Sep, 2009),
101 Date(10, Sep, 2010),
102 Date(30, Aug, 2011),
103 Date(19, Aug, 2012),
104 Date(8, Aug, 2013),
105 Date(28, Jul, 2014),
106 Date(17, Jul, 2015),
107 Date(6, Jul, 2016),
108 Date(25, Jun, 2017),
109 Date(15, Jun, 2018),
110 Date(4, Jun, 2019),
111 Date(24, May, 2020),
112 Date(13, May, 2021),
113 Date(2, May, 2022),
114 Date(21, Apr, 2023),
115 Date(10, Apr, 2024),
116 Date(30, Mar, 2025),
117 Date(20, Mar, 2026),
118 Date(9, Mar, 2027),
119 Date(26, Feb, 2028),
120 Date(14, Feb, 2029)
121 };
122
123 return std::any_of(EidAlFitr.begin(), EidAlFitr.end(),
124 [=](Date p) { return d >= p - 1 && d <= p + 4; });
125 }
126
127 }
128
130 // all calendar instances share the same implementation instance
131 static ext::shared_ptr<Calendar::Impl> tadawulImpl(
133 switch (market) {
134 case Tadawul:
135 impl_ = tadawulImpl;
136 break;
137 default:
138 QL_FAIL("unknown market");
139 }
140 }
141
143 return w == Friday || w == Saturday;
144 }
145
147 Day d = date.dayOfMonth();
148 Month m = date.month();
149 Year y = date.year();
150
151 if (isTrueWeekend(date)
152 || isEidAlAdha(date)
153 || isEidAlFitr(date)
154 // National Day
155 || (d == 23 && m == September)
156 // other one-shot holidays
157 || (d == 26 && m == February && y==2011)
158 || (d == 19 && m == March && y==2011)
159 )
160 return false; // NOLINT(readability-simplify-boolean-expr)
161 return true;
162 }
163
164}
165
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:400
Weekday weekday() const
Definition: date.hpp:395
bool isBusinessDay(const Date &) const override
bool isWeekend(Weekday) const override
SaudiArabia(Market m=Tadawul)
@ Tadawul
Tadawul financial market.
Definition: saudiarabia.hpp:59
Classes and functions for error handling.
#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
@ Jul
Definition: date.hpp:74
@ December
Definition: date.hpp:68
@ August
Definition: date.hpp:64
@ January
Definition: date.hpp:57
@ Mar
Definition: date.hpp:71
@ Nov
Definition: date.hpp:78
@ Aug
Definition: date.hpp:75
@ Oct
Definition: date.hpp:77
@ Feb
Definition: date.hpp:70
@ Jun
Definition: date.hpp:73
@ July
Definition: date.hpp:63
@ Dec
Definition: date.hpp:79
@ May
Definition: date.hpp:61
@ March
Definition: date.hpp:59
@ February
Definition: date.hpp:58
@ April
Definition: date.hpp:60
@ November
Definition: date.hpp:67
@ October
Definition: date.hpp:66
@ Apr
Definition: date.hpp:72
@ June
Definition: date.hpp:62
@ Sep
Definition: date.hpp:76
@ September
Definition: date.hpp:65
@ Saturday
Definition: weekday.hpp:47
@ Thursday
Definition: weekday.hpp:45
@ Friday
Definition: weekday.hpp:46
Definition: any.hpp:35
Saudi Arabian calendar.