QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
jointcalendar.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) 2003 RiskMap srl
5 Copyright (C) 2007 StatPro Italia srl
6 Copyright (C) 2020 Piotr Siejda
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/errors.hpp>
24#include <sstream>
25#include <utility>
26
27namespace QuantLib {
28
30 const Calendar& c2,
32 : rule_(r), calendars_(2) {
33 calendars_[0] = c1;
34 calendars_[1] = c2;
35 }
36
37
39 const Calendar& c2,
40 const Calendar& c3,
42 : rule_(r), calendars_(3) {
43 calendars_[0] = c1;
44 calendars_[1] = c2;
45 calendars_[2] = c3;
46 }
47
49 const Calendar& c2,
50 const Calendar& c3,
51 const Calendar& c4,
53 : rule_(r), calendars_(4) {
54 calendars_[0] = c1;
55 calendars_[1] = c2;
56 calendars_[2] = c3;
57 calendars_[3] = c4;
58 }
59
61 : rule_(r), calendars_(std::move(cv)) {}
62
63 std::string JointCalendar::Impl::name() const {
64 std::ostringstream out;
65 switch (rule_) {
66 case JoinHolidays:
67 out << "JoinHolidays(";
68 break;
70 out << "JoinBusinessDays(";
71 break;
72 default:
73 QL_FAIL("unknown joint calendar rule");
74 }
75 out << calendars_.front().name();
76 std::vector<Calendar>::const_iterator i;
77 for (i=calendars_.begin()+1; i!=calendars_.end(); ++i)
78 out << ", " << i->name();
79 out << ")";
80 return out.str();
81 }
82
84 std::vector<Calendar>::const_iterator i;
85 switch (rule_) {
86 case JoinHolidays:
87 for (i=calendars_.begin(); i!=calendars_.end(); ++i) {
88 if (i->isWeekend(w))
89 return true;
90 }
91 return false;
93 for (i=calendars_.begin(); i!=calendars_.end(); ++i) {
94 if (!i->isWeekend(w))
95 return false;
96 }
97 return true;
98 default:
99 QL_FAIL("unknown joint calendar rule");
100 }
101 }
102
103 bool JointCalendar::Impl::isBusinessDay(const Date& date) const {
104 std::vector<Calendar>::const_iterator i;
105 switch (rule_) {
106 case JoinHolidays:
107 for (i=calendars_.begin(); i!=calendars_.end(); ++i) {
108 if (i->isHoliday(date))
109 return false;
110 }
111 return true;
112 case JoinBusinessDays:
113 for (i=calendars_.begin(); i!=calendars_.end(); ++i) {
114 if (i->isBusinessDay(date))
115 return true;
116 }
117 return false;
118 default:
119 QL_FAIL("unknown joint calendar rule");
120 }
121 }
122
123
125 const Calendar& c2,
127 impl_ = ext::shared_ptr<Calendar::Impl>(
128 new JointCalendar::Impl(c1,c2,r));
129 }
130
132 const Calendar& c2,
133 const Calendar& c3,
135 impl_ = ext::shared_ptr<Calendar::Impl>(
136 new JointCalendar::Impl(c1,c2,c3,r));
137 }
138
140 const Calendar& c2,
141 const Calendar& c3,
142 const Calendar& c4,
144 impl_ = ext::shared_ptr<Calendar::Impl>(
145 new JointCalendar::Impl(c1,c2,c3,c4,r));
146 }
147
148 JointCalendar::JointCalendar(const std::vector<Calendar> &cv,
150 impl_ = ext::shared_ptr<Calendar::Impl>(
151 new JointCalendar::Impl(cv,r));
152 }
153
154}
calendar class
Definition: calendar.hpp:61
ext::shared_ptr< Impl > impl_
Definition: calendar.hpp:72
Concrete date class.
Definition: date.hpp:125
bool isBusinessDay(const Date &) const override
Impl(const Calendar &, const Calendar &, JointCalendarRule)
std::vector< Calendar > calendars_
std::string name() const override
bool isWeekend(Weekday) const override
JointCalendar(const Calendar &, const Calendar &, JointCalendarRule=JoinHolidays)
Classes and functions for error handling.
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
Joint calendar.
Definition: any.hpp:35
JointCalendarRule
rules for joining calendars
STL namespace.
ext::shared_ptr< YieldTermStructure > r