Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
conventions.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file configuration/conventions.cpp
20 \brief Currency and instrument specific conventions
21 \ingroup
22*/
23
24#include <boost/lexical_cast.hpp>
25#include <boost/make_shared.hpp>
26#include <boost/tokenizer.hpp>
27
34#include <ql/time/calendars/weekendsonly.hpp>
35
36using namespace QuantLib;
37using namespace std;
38using boost::lexical_cast;
40
41namespace {
42
43// TODO move to parsers
44SubPeriodsCoupon1::Type parseSubPeriodsCouponType(const string& s) {
45 if (s == "Compounding")
47 else if (s == "Averaging")
49 else
50 QL_FAIL("SubPeriodsCoupon type " << s << " not recognized");
51};
52
53void checkContinuationMappings(const map<Natural, Natural>& mp, const string& name) {
54
55 Natural previousValue = 0;
56 for (const auto& kv : mp) {
57 QL_REQUIRE(kv.first <= kv.second, "Not allowed a " << name << " continuation mapping where From (" <<
58 kv.first << ") is greater than To (" << kv.second << ").");
59 QL_REQUIRE(kv.second > previousValue, "The To " << name << " continuation mappings should be strictly " <<
60 "increasing but got " << kv.second << " <= " << previousValue);
61 previousValue = kv.second;
62 }
63}
64
65} // namespace
66
67namespace ore {
68namespace data {
69
70Convention::Convention(const string& id, Type type) : type_(type), id_(id) {}
71
72const QuantLib::ext::shared_ptr<ore::data::Conventions>& InstrumentConventions::conventions(QuantLib::Date d) const {
73 QL_REQUIRE(!conventions_.empty(), "InstrumentConventions: No conventions provided.");
74 boost::shared_lock<boost::shared_mutex> lock(mutex_);
75 Date dt = d == Date() ? Settings::instance().evaluationDate() : d;
76 auto it = conventions_.lower_bound(dt);
77 if(it != conventions_.end() && it->first == dt)
78 return it->second;
79 QL_REQUIRE(it != conventions_.begin(), "InstrumentConventions: Could not find conventions for " << dt);
80 --it;
81 constexpr std::size_t max_num_warnings = 10;
82 if (numberOfEmittedWarnings_ < max_num_warnings) {
84 WLOG("InstrumentConventions: Could not find conventions for "
85 << dt << ", using conventions from " << it->first
86 << (numberOfEmittedWarnings_ == max_num_warnings ? " (no more warnings of this type will be emitted)"
87 : ""));
88 }
89 return it->second;
90}
91
93 const QuantLib::ext::shared_ptr<ore::data::Conventions>& conventions, QuantLib::Date d) {
94 boost::unique_lock<boost::shared_mutex> lock(mutex_);
96}
97
98ZeroRateConvention::ZeroRateConvention(const string& id, const string& dayCounter, const string& compounding,
99 const string& compoundingFrequency)
100 : Convention(id, Type::Zero), tenorBased_(false), strDayCounter_(dayCounter), strCompounding_(compounding),
101 strCompoundingFrequency_(compoundingFrequency) {
102 build();
103}
104
105ZeroRateConvention::ZeroRateConvention(const string& id, const string& dayCounter, const string& tenorCalendar,
106 const string& compounding, const string& compoundingFrequency,
107 const string& spotLag, const string& spotCalendar, const string& rollConvention,
108 const string& eom)
109 : Convention(id, Type::Zero), tenorBased_(true), strDayCounter_(dayCounter), strTenorCalendar_(tenorCalendar),
110 strCompounding_(compounding), strCompoundingFrequency_(compoundingFrequency), strSpotLag_(spotLag),
111 strSpotCalendar_(spotCalendar), strRollConvention_(rollConvention), strEom_(eom) {
112 build();
113}
114
119 if (tenorBased_) {
121 spotLag_ = strSpotLag_.empty() ? 0 : lexical_cast<Natural>(strSpotLag_);
122 spotCalendar_ = strSpotCalendar_.empty() ? NullCalendar() : parseCalendar(strSpotCalendar_);
124 eom_ = strEom_.empty() ? false : parseBool(strEom_);
125 }
126}
127
129
130 XMLUtils::checkNode(node, "Zero");
132 id_ = XMLUtils::getChildValue(node, "Id", true);
133 tenorBased_ = XMLUtils::getChildValueAsBool(node, "TenorBased", true);
134
135 // Get string values from xml
136 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
137 strCompoundingFrequency_ = XMLUtils::getChildValue(node, "CompoundingFrequency", false);
138 strCompounding_ = XMLUtils::getChildValue(node, "Compounding", false);
139 if (tenorBased_) {
140 strTenorCalendar_ = XMLUtils::getChildValue(node, "TenorCalendar", true);
141 strSpotLag_ = XMLUtils::getChildValue(node, "SpotLag", false);
142 strSpotCalendar_ = XMLUtils::getChildValue(node, "SpotCalendar", false);
143 strRollConvention_ = XMLUtils::getChildValue(node, "RollConvention", false);
144 strEom_ = XMLUtils::getChildValue(node, "EOM", false);
145 }
146 build();
147}
148
150
151 XMLNode* node = doc.allocNode("Zero");
152 XMLUtils::addChild(doc, node, "Id", id_);
153 XMLUtils::addChild(doc, node, "TenorBased", tenorBased_);
154 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
155 XMLUtils::addChild(doc, node, "CompoundingFrequency", strCompoundingFrequency_);
156 XMLUtils::addChild(doc, node, "Compounding", strCompounding_);
157 if (tenorBased_) {
158 XMLUtils::addChild(doc, node, "TenorCalendar", strTenorCalendar_);
159 XMLUtils::addChild(doc, node, "SpotLag", strSpotLag_);
160 XMLUtils::addChild(doc, node, "SpotCalendar", strSpotCalendar_);
161 XMLUtils::addChild(doc, node, "RollConvention", strRollConvention_);
162 XMLUtils::addChild(doc, node, "EOM", strEom_);
163 }
164
165 return node;
166}
167
168DepositConvention::DepositConvention(const string& id, const string& index)
169 : Convention(id, Type::Deposit), index_(index), indexBased_(true) {}
170
171DepositConvention::DepositConvention(const string& id, const string& calendar, const string& convention,
172 const string& eom, const string& dayCounter, const string& settlementDays)
173 : Convention(id, Type::Deposit), indexBased_(false), strCalendar_(calendar), strConvention_(convention),
174 strEom_(eom), strDayCounter_(dayCounter), strSettlementDays_(settlementDays) {
175 build();
176}
177
184}
185
187
188 XMLUtils::checkNode(node, "Deposit");
190 id_ = XMLUtils::getChildValue(node, "Id", true);
191 indexBased_ = XMLUtils::getChildValueAsBool(node, "IndexBased", true);
192
193 // Get string values from xml
194 if (indexBased_) {
195 index_ = XMLUtils::getChildValue(node, "Index", true);
196 } else {
197 strCalendar_ = XMLUtils::getChildValue(node, "Calendar", true);
198 strConvention_ = XMLUtils::getChildValue(node, "Convention", true);
199 strEom_ = XMLUtils::getChildValue(node, "EOM", true);
200 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
201 strSettlementDays_ = XMLUtils::getChildValue(node, "SettlementDays", true);
202 build();
203 }
204}
205
207
208 XMLNode* node = doc.allocNode("Deposit");
209 XMLUtils::addChild(doc, node, "Id", id_);
210 XMLUtils::addChild(doc, node, "IndexBased", indexBased_);
211 if (indexBased_) {
212 XMLUtils::addChild(doc, node, "Index", index_);
213 } else {
214 XMLUtils::addChild(doc, node, "Calendar", strCalendar_);
215 XMLUtils::addChild(doc, node, "Convention", strConvention_);
216 XMLUtils::addChild(doc, node, "EOM", strEom_);
217 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
218 XMLUtils::addChild(doc, node, "SettlementDays", strSettlementDays_);
219 }
220
221 return node;
222}
223
224FutureConvention::FutureConvention(const string& id, const string& index)
225 : FutureConvention(id, index, QuantLib::RateAveraging::Type::Compound, DateGenerationRule::IMM) {}
226
227FutureConvention::FutureConvention(const string& id, const string& index,
228 const QuantLib::RateAveraging::Type overnightIndexFutureNettingType,
229 const DateGenerationRule dateGenerationRule)
230 : Convention(id, Type::Future), strIndex_(index),
231 overnightIndexFutureNettingType_(overnightIndexFutureNettingType) {
233}
234
236 XMLUtils::checkNode(node, "Future");
238 id_ = XMLUtils::getChildValue(node, "Id", true);
239 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
241 string nettingTypeStr = XMLUtils::getChildValue(node, "OvernightIndexFutureNettingType", false);
243 nettingTypeStr.empty() ? RateAveraging::Type::Compound : parseOvernightIndexFutureNettingType(nettingTypeStr);
244 string dateGenerationStr = XMLUtils::getChildValue(node, "DateGenerationRule", false);
246 dateGenerationStr.empty() ? DateGenerationRule::IMM : parseFutureDateGenerationRule(dateGenerationStr);
247}
248
250
251 XMLNode* node = doc.allocNode("Future");
252 XMLUtils::addChild(doc, node, "Id", id_);
253 XMLUtils::addChild(doc, node, "Index", strIndex_);
254 XMLUtils::addChild(doc, node, "OvernightIndexFutureNettingType", ore::data::to_string(overnightIndexFutureNettingType_));
255 XMLUtils::addChild(doc, node, "DateGenerationRule", ore::data::to_string(dateGenerationRule_));
256 return node;
257}
258
259QuantLib::ext::shared_ptr<IborIndex> FutureConvention::index() const { return parseIborIndex(strIndex_); }
260
261FraConvention::FraConvention(const string& id, const string& index) : Convention(id, Type::FRA), strIndex_(index) {
263}
264
266
267 XMLUtils::checkNode(node, "FRA");
269 id_ = XMLUtils::getChildValue(node, "Id", true);
270 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
272}
273
275
276 XMLNode* node = doc.allocNode("FRA");
277 XMLUtils::addChild(doc, node, "Id", id_);
278 XMLUtils::addChild(doc, node, "Index", strIndex_);
279
280 return node;
281}
282
283QuantLib::ext::shared_ptr<IborIndex> FraConvention::index() const { return parseIborIndex(strIndex_); }
284
285OisConvention::OisConvention(const string& id, const string& spotLag, const string& index,
286 const string& fixedDayCounter, const string& fixedCalendar, const string& paymentLag,
287 const string& eom, const string& fixedFrequency, const string& fixedConvention,
288 const string& fixedPaymentConvention, const string& rule, const string& paymentCal)
289 : Convention(id, Type::OIS), strSpotLag_(spotLag), strIndex_(index), strFixedDayCounter_(fixedDayCounter),
290 strFixedCalendar_(fixedCalendar), strPaymentLag_(paymentLag), strEom_(eom), strFixedFrequency_(fixedFrequency),
291 strFixedConvention_(fixedConvention), strFixedPaymentConvention_(fixedPaymentConvention), strRule_(rule),
292 strPaymentCal_(paymentCal) {
293 build();
294}
295
297 auto tmpIndex = parseIborIndex(strIndex_);
298 spotLag_ = lexical_cast<Natural>(strSpotLag_);
300 fixedCalendar_ = strFixedCalendar_.empty() ? tmpIndex->fixingCalendar() : parseCalendar(strFixedCalendar_);
301 paymentLag_ = strPaymentLag_.empty() ? 0 : lexical_cast<Natural>(strPaymentLag_);
302 eom_ = strEom_.empty() ? false : parseBool(strEom_);
307 rule_ = strRule_.empty() ? DateGeneration::Backward : parseDateGenerationRule(strRule_);
308 paymentCal_ = strPaymentCal_.empty() ? Calendar() : parseCalendar(strPaymentCal_);
309}
310
312
313 XMLUtils::checkNode(node, "OIS");
315 id_ = XMLUtils::getChildValue(node, "Id", true);
316
317 // Get string values from xml
318 strSpotLag_ = XMLUtils::getChildValue(node, "SpotLag", true);
319 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
320 strFixedDayCounter_ = XMLUtils::getChildValue(node, "FixedDayCounter", true);
321 // bwd compatibility
322 strFixedCalendar_ = XMLUtils::getChildValue(node, "FixedCalendar", false);
323 strPaymentLag_ = XMLUtils::getChildValue(node, "PaymentLag", false);
324 strEom_ = XMLUtils::getChildValue(node, "EOM", false);
325 strFixedFrequency_ = XMLUtils::getChildValue(node, "FixedFrequency", false);
326 strFixedConvention_ = XMLUtils::getChildValue(node, "FixedConvention", false);
327 strFixedPaymentConvention_ = XMLUtils::getChildValue(node, "FixedPaymentConvention", false);
328 strRule_ = XMLUtils::getChildValue(node, "Rule", false);
329 strPaymentCal_ = XMLUtils::getChildValue(node, "PaymentCalendar", false);
330
331 build();
332}
333
335
336 XMLNode* node = doc.allocNode("OIS");
337 XMLUtils::addChild(doc, node, "Id", id_);
338 XMLUtils::addChild(doc, node, "SpotLag", strSpotLag_);
339 XMLUtils::addChild(doc, node, "Index", strIndex_);
340 XMLUtils::addChild(doc, node, "FixedDayCounter", strFixedDayCounter_);
341 if(!strFixedCalendar_.empty())
342 XMLUtils::addChild(doc, node, "FixedCalendar", strFixedCalendar_);
343 if (!strPaymentLag_.empty())
344 XMLUtils::addChild(doc, node, "PaymentLag", strPaymentLag_);
345 if (!strEom_.empty())
346 XMLUtils::addChild(doc, node, "EOM", strEom_);
347 if (!strFixedFrequency_.empty())
348 XMLUtils::addChild(doc, node, "FixedFrequency", strFixedFrequency_);
349 if (!strFixedConvention_.empty())
350 XMLUtils::addChild(doc, node, "FixedConvention", strFixedConvention_);
351 if (!strFixedPaymentConvention_.empty())
352 XMLUtils::addChild(doc, node, "FixedPaymentConvention", strFixedPaymentConvention_);
353 if (!strRule_.empty())
354 XMLUtils::addChild(doc, node, "Rule", strRule_);
355 if (!strPaymentCal_.empty())
356 XMLUtils::addChild(doc, node, "PaymentCalendar", strPaymentCal_);
357
358 return node;
359}
360
361QuantLib::ext::shared_ptr<OvernightIndex> OisConvention::index() const {
362 auto tmp = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(parseIborIndex(strIndex_));
363 QL_REQUIRE(tmp, "The index string '" << strIndex_ << "' does not represent an overnight index.");
364 return tmp;
365}
366
367IborIndexConvention::IborIndexConvention(const string& id, const string& fixingCalendar, const string& dayCounter,
368 const Size settlementDays, const string& businessDayConvention,
369 const bool endOfMonth)
370 : Convention(id, Type::IborIndex), localId_(id), strFixingCalendar_(fixingCalendar), strDayCounter_(dayCounter),
371 settlementDays_(settlementDays), strBusinessDayConvention_(businessDayConvention), endOfMonth_(endOfMonth) {
372 build();
373}
374
376 XMLUtils::checkNode(node, "IborIndex");
378 localId_ = XMLUtils::getChildValue(node, "Id", true);
379 strFixingCalendar_ = XMLUtils::getChildValue(node, "FixingCalendar", true);
380 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
381 settlementDays_ = XMLUtils::getChildValueAsInt(node, "SettlementDays", true);
382 strBusinessDayConvention_ = XMLUtils::getChildValue(node, "BusinessDayConvention", true);
383 endOfMonth_ = XMLUtils::getChildValueAsBool(node, "EndOfMonth", true);
384 build();
385}
386
388 XMLNode* node = doc.allocNode("IborIndex");
389 XMLUtils::addChild(doc, node, "Id", localId_);
390 XMLUtils::addChild(doc, node, "FixingCalendar", strFixingCalendar_);
391 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
392 XMLUtils::addChild(doc, node, "SettlementDays", static_cast<int>(settlementDays_));
393 XMLUtils::addChild(doc, node, "BusinessDayConvention", strBusinessDayConvention_);
394 XMLUtils::addChild(doc, node, "EndOfMonth", endOfMonth_);
395 return node;
396}
397
399 // just a check really that the id is consistent with the ibor index name rules
400 vector<string> tokens;
401 split(tokens, localId_, boost::is_any_of("-"));
402 QL_REQUIRE(tokens.size() == 2 || tokens.size() == 3,
403 "Two or three tokens required in IborIndexConvention " << localId_ << ": CCY-INDEX or CCY-INDEX-TERM");
404
405 // set the Id - this converts the local id term from "7D" to "1W", "28D" to "1M" etc, so if can be picked
406 // up by searches
407 id_ = (tokens.size() == 3) ? (tokens[0] + "-" + tokens[1] + "-" + to_string(parsePeriod(tokens[2]))) : localId_;
408}
409
410OvernightIndexConvention::OvernightIndexConvention(const string& id, const string& fixingCalendar,
411 const string& dayCounter, const Size settlementDays)
412 : Convention(id, Type::OvernightIndex), strFixingCalendar_(fixingCalendar), strDayCounter_(dayCounter),
413 settlementDays_(settlementDays) {
414 build();
415}
416
418 XMLUtils::checkNode(node, "OvernightIndex");
420 id_ = XMLUtils::getChildValue(node, "Id", true);
421 strFixingCalendar_ = XMLUtils::getChildValue(node, "FixingCalendar", true);
422 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
423 settlementDays_ = XMLUtils::getChildValueAsInt(node, "SettlementDays", true);
424 build();
425}
426
428 XMLNode* node = doc.allocNode("OvernightIndex");
429 XMLUtils::addChild(doc, node, "Id", id_);
430 XMLUtils::addChild(doc, node, "FixingCalendar", strFixingCalendar_);
431 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
432 XMLUtils::addChild(doc, node, "SettlementDays", static_cast<int>(settlementDays_));
433 return node;
434}
435
437 // just a check really that the id is consistent with the ibor index name rules
438 vector<string> tokens;
439 split(tokens, id_, boost::is_any_of("-"));
440 QL_REQUIRE(tokens.size() == 2, "Two tokens required in OvernightIndexConvention " << id_ << ": CCY-INDEX");
441}
442
443SwapIndexConvention::SwapIndexConvention(const string& id, const string& conventions, const string& fixingCalendar)
444 : Convention(id, Type::SwapIndex), strConventions_(conventions), fixingCalendar_(fixingCalendar) {}
445
447
448 XMLUtils::checkNode(node, "SwapIndex");
450 id_ = XMLUtils::getChildValue(node, "Id", true);
451
452 // Get string values from xml
453 strConventions_ = XMLUtils::getChildValue(node, "Conventions", true);
454 fixingCalendar_ = XMLUtils::getChildValue(node, "FixingCalendar", false);
455}
456
458
459 XMLNode* node = doc.allocNode("SwapIndex");
460 XMLUtils::addChild(doc, node, "Id", id_);
461 XMLUtils::addChild(doc, node, "Conventions", strConventions_);
462 XMLUtils::addChild(doc, node, "FixingCalendar", fixingCalendar_);
463
464 return node;
465}
466
467IRSwapConvention::IRSwapConvention(const string& id, const string& fixedCalendar, const string& fixedFrequency,
468 const string& fixedConvention, const string& fixedDayCounter, const string& index,
469 bool hasSubPeriod, const string& floatFrequency, const string& subPeriodsCouponType)
470 : Convention(id, Type::Swap), hasSubPeriod_(hasSubPeriod), strFixedCalendar_(fixedCalendar),
471 strFixedFrequency_(fixedFrequency), strFixedConvention_(fixedConvention), strFixedDayCounter_(fixedDayCounter),
472 strIndex_(index), strFloatFrequency_(floatFrequency), strSubPeriodsCouponType_(subPeriodsCouponType) {
473 build();
474}
475
479 auto ind = parseIborIndex(strIndex_);
480
481 if (strFixedCalendar_.empty())
482 fixedCalendar_ = ind->fixingCalendar();
483 else
485
486 if (strFixedConvention_.empty())
487 fixedConvention_ = ind->businessDayConvention();
488 else
490
491 if (hasSubPeriod_) {
493 subPeriodsCouponType_ = parseSubPeriodsCouponType(strSubPeriodsCouponType_);
494 } else {
495 floatFrequency_ = NoFrequency;
497 }
498}
499
501
502 XMLUtils::checkNode(node, "Swap");
504 id_ = XMLUtils::getChildValue(node, "Id", true);
505
506 // Get string values from xml
507 strFixedFrequency_ = XMLUtils::getChildValue(node, "FixedFrequency", true);
508 strFixedDayCounter_ = XMLUtils::getChildValue(node, "FixedDayCounter", true);
509 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
510
511 // optional
512 strFixedCalendar_ = XMLUtils::getChildValue(node, "FixedCalendar", false);
513 strFixedConvention_ = XMLUtils::getChildValue(node, "FixedConvention", false);
514 strFloatFrequency_ = XMLUtils::getChildValue(node, "FloatFrequency", false);
515 strSubPeriodsCouponType_ = XMLUtils::getChildValue(node, "SubPeriodsCouponType", false);
517
518 build();
519}
520
522
523 XMLNode* node = doc.allocNode("Swap");
524 XMLUtils::addChild(doc, node, "Id", id_);
525 XMLUtils::addChild(doc, node, "FixedCalendar", strFixedCalendar_);
526 XMLUtils::addChild(doc, node, "FixedFrequency", strFixedFrequency_);
527 XMLUtils::addChild(doc, node, "FixedConvention", strFixedConvention_);
528 XMLUtils::addChild(doc, node, "FixedDayCounter", strFixedDayCounter_);
529 XMLUtils::addChild(doc, node, "Index", strIndex_);
530 if (hasSubPeriod_) {
531 XMLUtils::addChild(doc, node, "FloatFrequency", strFloatFrequency_);
532 XMLUtils::addChild(doc, node, "SubPeriodsCouponType", strSubPeriodsCouponType_);
533 }
534
535 return node;
536}
537
538QuantLib::ext::shared_ptr<IborIndex> IRSwapConvention::index() const { return parseIborIndex(strIndex_); }
539
540AverageOisConvention::AverageOisConvention(const string& id, const string& spotLag, const string& fixedTenor,
541 const string& fixedDayCounter, const string& fixedCalendar,
542 const string& fixedConvention, const string& fixedPaymentConvention,
543 const string& fixedFrequency, const string& index, const string& onTenor,
544 const string& rateCutoff)
545 : Convention(id, Type::AverageOIS), strSpotLag_(spotLag), strFixedTenor_(fixedTenor),
546 strFixedDayCounter_(fixedDayCounter), strFixedCalendar_(fixedCalendar), strFixedConvention_(fixedConvention),
547 strFixedPaymentConvention_(fixedPaymentConvention), strIndex_(index), strOnTenor_(onTenor),
548 strRateCutoff_(rateCutoff) {
549 build();
550}
551
554 spotLag_ = lexical_cast<Natural>(strSpotLag_);
562 rateCutoff_ = lexical_cast<Natural>(strRateCutoff_);
563}
564
566
567 XMLUtils::checkNode(node, "AverageOIS");
569 id_ = XMLUtils::getChildValue(node, "Id", true);
570
571 // Get string values from xml
572 strSpotLag_ = XMLUtils::getChildValue(node, "SpotLag", true);
573 strFixedTenor_ = XMLUtils::getChildValue(node, "FixedTenor", true);
574 strFixedDayCounter_ = XMLUtils::getChildValue(node, "FixedDayCounter", true);
575 strFixedCalendar_ = XMLUtils::getChildValue(node, "FixedCalendar", true);
576 strFixedConvention_ = XMLUtils::getChildValue(node, "FixedConvention", true);
577 strFixedPaymentConvention_ = XMLUtils::getChildValue(node, "FixedPaymentConvention", true);
578 strFixedFrequency_ = XMLUtils::getChildValue(node, "FixedFrequency", false);
579 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
580 strOnTenor_ = XMLUtils::getChildValue(node, "OnTenor", true);
581 strRateCutoff_ = XMLUtils::getChildValue(node, "RateCutoff", true);
582
583 build();
584}
585
587
588 XMLNode* node = doc.allocNode("AverageOIS");
589 XMLUtils::addChild(doc, node, "Id", id_);
590 XMLUtils::addChild(doc, node, "SpotLag", strSpotLag_);
591 XMLUtils::addChild(doc, node, "FixedTenor", strFixedTenor_);
592 XMLUtils::addChild(doc, node, "FixedDayCounter", strFixedDayCounter_);
593 XMLUtils::addChild(doc, node, "FixedCalendar", strFixedCalendar_);
594 XMLUtils::addChild(doc, node, "FixedConvention", strFixedConvention_);
595 XMLUtils::addChild(doc, node, "FixedPaymentConvention", strFixedPaymentConvention_);
596 if (!strFixedFrequency_.empty())
597 XMLUtils::addChild(doc, node, "FixedFrequency", strFixedFrequency_);
598 XMLUtils::addChild(doc, node, "Index", strIndex_);
599 XMLUtils::addChild(doc, node, "OnTenor", strOnTenor_);
600 XMLUtils::addChild(doc, node, "RateCutoff", strRateCutoff_);
601
602 return node;
603}
604
605QuantLib::ext::shared_ptr<OvernightIndex> AverageOisConvention::index() const {
606 auto tmp = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(parseIborIndex(strIndex_));
607 QL_REQUIRE(tmp, "The index string '" << strIndex_ << "' does not represent an overnight index.");
608 return tmp;
609}
610
611TenorBasisSwapConvention::TenorBasisSwapConvention(const string& id, const string& payIndex, const string& receiveIndex,
612 const string& receiveFrequency, const string& payFrequency,
613 const string& spreadOnRec, const string& includeSpread,
614 const string& subPeriodsCouponType)
615 : Convention(id, Type::TenorBasisSwap), strPayIndex_(payIndex), strReceiveIndex_(receiveIndex),
616 strReceiveFrequency_(receiveFrequency), strPayFrequency_(payFrequency), strSpreadOnRec_(spreadOnRec),
617 strIncludeSpread_(includeSpread), strSubPeriodsCouponType_(subPeriodsCouponType) {
618 build();
619}
620
624
625 QuantLib::ext::shared_ptr<OvernightIndex> payON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(payIndex());
626 QuantLib::ext::shared_ptr<OvernightIndex> recON = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(receiveIndex());
627
628 if (strReceiveFrequency_.empty()) {
629 if (recON) {
630 receiveFrequency_ = 1 * Years;
631 WLOG("receiveFrequency_ empty and overnight, set to 1 Year");
632 } else {
633 receiveFrequency_ = receiveIndex()->tenor();
634 WLOG("receiveFrequency_ empty set to index tenor.");
635 }
636 } else
638
639 if (strPayFrequency_.empty()) {
640 if (payON) {
641 payFrequency_ = 1 * Years;
642 WLOG("payFrequency_ empty and overnight, set to 1 Year");
643 } else {
644 payFrequency_ = payIndex()->tenor();
645 WLOG("payFrequency_ empty set to index tenor.");
646 }
647 } else
649
652 if (includeSpread_ && (payON || recON))
653 QL_FAIL("IncludeSpread must be false for overnight index legs.");
654
656 : parseSubPeriodsCouponType(strSubPeriodsCouponType_);
657}
658
660
661 XMLUtils::checkNode(node, "TenorBasisSwap");
663 id_ = XMLUtils::getChildValue(node, "Id", true);
664
665 // Get string values from xml
666 strPayIndex_ = XMLUtils::getChildValue(node, "PayIndex", false);
667 strReceiveIndex_ = XMLUtils::getChildValue(node, "ReceiveIndex", false);
668 strReceiveFrequency_ = XMLUtils::getChildValue(node, "ReceiveFrequency", false);
669 strPayFrequency_ = XMLUtils::getChildValue(node, "PayFrequency", false);
670 strSpreadOnRec_ = XMLUtils::getChildValue(node, "SpreadOnRec", false);
671 strIncludeSpread_ = XMLUtils::getChildValue(node, "IncludeSpread", false);
672 strSubPeriodsCouponType_ = XMLUtils::getChildValue(node, "SubPeriodsCouponType", false);
673
674 // handle deprecated fields...
675 if (strPayIndex_.empty()) {
676 XMLNode* longIndex = XMLUtils::getChildNode(node, "LongIndex");
677 if (longIndex) {
678 ALOG("TenorBasisSwapConvention: LongIndex is deprecated, fill empty PayIndex");
680 } else
681 QL_FAIL("TenorBasisSwapConvention : PayIndex field missing.");
682 }
683
684 if (strReceiveIndex_.empty()) {
685 XMLNode* shortIndex = XMLUtils::getChildNode(node, "ShortIndex");
686 if (shortIndex) {
687 ALOG("TenorBasisSwapConvention: ShortIndex is deprecated, fill empty ReceiveIndex");
689 } else
690 QL_FAIL("TenorBasisSwapConvention : ReceiveIndex field missing.");
691 }
692
693 XMLNode* longPayTenor = XMLUtils::getChildNode(node, "LongPayTenor");
694 if (longPayTenor) {
695 ALOG("TenorBasisSwapConvention: LongPayTenor is deprecated, fill empty PayFrequency");
696 if (strPayFrequency_.empty())
698 }
699
700 XMLNode* shortPayTenor = XMLUtils::getChildNode(node, "ShortPayTenor");
701 if (shortPayTenor) {
702 ALOG("TenorBasisSwapConvention: ShortPayTenor is deprecated, fill empty ReceiveFrequency");
703 if (strReceiveFrequency_.empty())
705 }
706
707 XMLNode* spreadOnShort = XMLUtils::getChildNode(node, "SpreadOnShort");
708 if (spreadOnShort) {
709 ALOG("TenorBasisSwapConvention: SpreadOnShort is deprecated, fill empty SpreadOnRec");
710 if (strSpreadOnRec_.empty())
712 }
713
714 build();
715}
716
718
719 XMLNode* node = doc.allocNode("TenorBasisSwap");
720 XMLUtils::addChild(doc, node, "Id", id_);
721 XMLUtils::addChild(doc, node, "PayIndex", strPayIndex_);
722 XMLUtils::addChild(doc, node, "ReceiveIndex", strReceiveIndex_);
723 if (!strReceiveFrequency_.empty())
724 XMLUtils::addChild(doc, node, "ReceiveFrequency", strReceiveFrequency_);
725 if (!strPayFrequency_.empty())
726 XMLUtils::addChild(doc, node, "PayFrequency", strPayFrequency_);
727 if (!strSpreadOnRec_.empty())
728 XMLUtils::addChild(doc, node, "SpreadOnRec", strSpreadOnRec_);
729 if (!strIncludeSpread_.empty())
730 XMLUtils::addChild(doc, node, "IncludeSpread", strIncludeSpread_);
731 if (!strSubPeriodsCouponType_.empty())
732 XMLUtils::addChild(doc, node, "SubPeriodsCouponType", strSubPeriodsCouponType_);
733 return node;
734}
735
736QuantLib::ext::shared_ptr<IborIndex> TenorBasisSwapConvention::payIndex() const { return parseIborIndex(strPayIndex_); }
737QuantLib::ext::shared_ptr<IborIndex> TenorBasisSwapConvention::receiveIndex() const { return parseIborIndex(strReceiveIndex_); }
738
740 const string& id, const string& calendar, const string& longFixedFrequency, const string& longFixedConvention,
741 const string& longFixedDayCounter, const string& longIndex, const string& shortFixedFrequency,
742 const string& shortFixedConvention, const string& shortFixedDayCounter, const string& shortIndex,
743 const string& longMinusShort)
744 : Convention(id, Type::TenorBasisTwoSwap), strCalendar_(calendar), strLongFixedFrequency_(longFixedFrequency),
745 strLongFixedConvention_(longFixedConvention), strLongFixedDayCounter_(longFixedDayCounter),
746 strLongIndex_(longIndex), strShortFixedFrequency_(shortFixedFrequency),
747 strShortFixedConvention_(shortFixedConvention), strShortFixedDayCounter_(shortFixedDayCounter),
748 strShortIndex_(shortIndex), strLongMinusShort_(longMinusShort) {
749 build();
750}
751
763}
764
766
767 XMLUtils::checkNode(node, "TenorBasisTwoSwap");
769 id_ = XMLUtils::getChildValue(node, "Id", true);
770
771 // Get string values from xml
772 strCalendar_ = XMLUtils::getChildValue(node, "Calendar", true);
773 strLongFixedFrequency_ = XMLUtils::getChildValue(node, "LongFixedFrequency", true);
774 strLongFixedConvention_ = XMLUtils::getChildValue(node, "LongFixedConvention", true);
775 strLongFixedDayCounter_ = XMLUtils::getChildValue(node, "LongFixedDayCounter", true);
776 strLongIndex_ = XMLUtils::getChildValue(node, "LongIndex", true);
777 strShortFixedFrequency_ = XMLUtils::getChildValue(node, "ShortFixedFrequency", true);
778 strShortFixedConvention_ = XMLUtils::getChildValue(node, "ShortFixedConvention", true);
779 strShortFixedDayCounter_ = XMLUtils::getChildValue(node, "ShortFixedDayCounter", true);
780 strShortIndex_ = XMLUtils::getChildValue(node, "ShortIndex", true);
781 strLongMinusShort_ = XMLUtils::getChildValue(node, "LongMinusShort", false);
782
783 build();
784}
785
786QuantLib::ext::shared_ptr<IborIndex> TenorBasisTwoSwapConvention::longIndex() const { return parseIborIndex(strLongIndex_); }
787QuantLib::ext::shared_ptr<IborIndex> TenorBasisTwoSwapConvention::shortIndex() const { return parseIborIndex(strShortIndex_); }
788
790
791 XMLNode* node = doc.allocNode("TenorBasisTwoSwap");
792 XMLUtils::addChild(doc, node, "Id", id_);
793 XMLUtils::addChild(doc, node, "Calendar", strCalendar_);
794 XMLUtils::addChild(doc, node, "LongFixedFrequency", strLongFixedFrequency_);
795 XMLUtils::addChild(doc, node, "LongFixedConvention", strLongFixedConvention_);
796 XMLUtils::addChild(doc, node, "LongFixedDayCounter", strLongFixedDayCounter_);
797 XMLUtils::addChild(doc, node, "LongIndex", strLongIndex_);
798 XMLUtils::addChild(doc, node, "ShortFixedFrequency", strShortFixedFrequency_);
799 XMLUtils::addChild(doc, node, "ShortFixedConvention", strShortFixedConvention_);
800 XMLUtils::addChild(doc, node, "ShortFixedDayCounter", strShortFixedDayCounter_);
801 XMLUtils::addChild(doc, node, "ShortIndex", strShortIndex_);
802 XMLUtils::addChild(doc, node, "LongMinusShort", strLongMinusShort_);
803
804 return node;
805}
806
807BMABasisSwapConvention::BMABasisSwapConvention(const string& id, const string& longIndex, const string& shortIndex)
808 : Convention(id, Type::BMABasisSwap), strLiborIndex_(longIndex), strBmaIndex_(shortIndex) {
809 build();
810}
811
814}
815
817
818 XMLUtils::checkNode(node, "BMABasisSwap");
820 id_ = XMLUtils::getChildValue(node, "Id", true);
821
822 // Get string values from xml
823 strLiborIndex_ = XMLUtils::getChildValue(node, "LiborIndex", true);
824 strBmaIndex_ = XMLUtils::getChildValue(node, "BMAIndex", true);
825
826 build();
827}
828
830
831 XMLNode* node = doc.allocNode("BMABasisSwap");
832 XMLUtils::addChild(doc, node, "Id", id_);
833 XMLUtils::addChild(doc, node, "LiborIndex", strLiborIndex_);
834 XMLUtils::addChild(doc, node, "BMAIndex", strBmaIndex_);
835
836 return node;
837}
838
839QuantLib::ext::shared_ptr<QuantExt::BMAIndexWrapper> BMABasisSwapConvention::bmaIndex() const {
840 auto tmp = QuantLib::ext::dynamic_pointer_cast<QuantExt::BMAIndexWrapper>(parseIborIndex(strBmaIndex_));
841 QL_REQUIRE(tmp, "the index string '" << strBmaIndex_ << "' does not represent a BMA / SIFMA index.");
842 return tmp;
843}
844
845QuantLib::ext::shared_ptr<IborIndex> BMABasisSwapConvention::liborIndex() const { return parseIborIndex(strLiborIndex_); }
846
847FXConvention::FXConvention(const string& id, const string& spotDays, const string& sourceCurrency,
848 const string& targetCurrency, const string& pointsFactor, const string& advanceCalendar,
849 const string& spotRelative, const string& endOfMonth, const string& convention)
850 : Convention(id, Type::FX), strSpotDays_(spotDays), strSourceCurrency_(sourceCurrency),
851 strTargetCurrency_(targetCurrency), strPointsFactor_(pointsFactor), strAdvanceCalendar_(advanceCalendar),
852 strSpotRelative_(spotRelative), strEndOfMonth_(endOfMonth), strConvention_(convention) {
853 build();
854}
855
857 spotDays_ = lexical_cast<Natural>(strSpotDays_);
865}
866
868
869 XMLUtils::checkNode(node, "FX");
870 type_ = Type::FX;
871 id_ = XMLUtils::getChildValue(node, "Id", true);
872
873 // Get string values from xml
874 strSpotDays_ = XMLUtils::getChildValue(node, "SpotDays", true);
875 strSourceCurrency_ = XMLUtils::getChildValue(node, "SourceCurrency", true);
876 strTargetCurrency_ = XMLUtils::getChildValue(node, "TargetCurrency", true);
877 strPointsFactor_ = XMLUtils::getChildValue(node, "PointsFactor", true);
878 strAdvanceCalendar_ = XMLUtils::getChildValue(node, "AdvanceCalendar", false);
879 strSpotRelative_ = XMLUtils::getChildValue(node, "SpotRelative", false);
880 strEndOfMonth_ = XMLUtils::getChildValue(node, "EOM", false);
881 strConvention_ = XMLUtils::getChildValue(node, "Convention", false);
882
883 build();
884}
885
887
888 XMLNode* node = doc.allocNode("FX");
889 XMLUtils::addChild(doc, node, "Id", id_);
890 XMLUtils::addChild(doc, node, "SpotDays", strSpotDays_);
891 XMLUtils::addChild(doc, node, "SourceCurrency", strSourceCurrency_);
892 XMLUtils::addChild(doc, node, "TargetCurrency", strTargetCurrency_);
893 XMLUtils::addChild(doc, node, "PointsFactor", strPointsFactor_);
894
895 if (!strAdvanceCalendar_.empty())
896 XMLUtils::addChild(doc, node, "AdvanceCalendar", strAdvanceCalendar_);
897 if (!strSpotRelative_.empty())
898 XMLUtils::addChild(doc, node, "SpotRelative", strSpotRelative_);
899 if (!strEndOfMonth_.empty())
900 XMLUtils::addChild(doc, node, "EOM", strEndOfMonth_);
901 if (!strConvention_.empty())
902 XMLUtils::addChild(doc, node, "Convention", strConvention_);
903
904 return node;
905}
906
908 const string& id, const string& strSettlementDays, const string& strSettlementCalendar,
909 const string& strRollConvention, const string& flatIndex, const string& spreadIndex, const string& strEom,
910 const string& strIsResettable, const string& strFlatIndexIsResettable, const string& strFlatTenor,
911 const string& strSpreadTenor, const string& strPaymentLag, const string& strFlatPaymentLag,
912 const string& strIncludeSpread, const string& strLookback, const string& strFixingDays, const string& strRateCutoff,
913 const string& strIsAveraged, const string& strFlatIncludeSpread, const string& strFlatLookback,
914 const string& strFlatFixingDays, const string& strFlatRateCutoff, const string& strFlatIsAveraged,
915 const Conventions* conventions)
916 : Convention(id, Type::CrossCcyBasis), strSettlementDays_(strSettlementDays),
917 strSettlementCalendar_(strSettlementCalendar), strRollConvention_(strRollConvention), strFlatIndex_(flatIndex),
918 strSpreadIndex_(spreadIndex), strEom_(strEom), strIsResettable_(strIsResettable),
919 strFlatIndexIsResettable_(strFlatIndexIsResettable), strFlatTenor_(strFlatTenor), strSpreadTenor_(strSpreadTenor),
920 strPaymentLag_(strPaymentLag), strFlatPaymentLag_(strFlatPaymentLag), strIncludeSpread_(strIncludeSpread),
921 strLookback_(strLookback), strFixingDays_(strFixingDays), strRateCutoff_(strRateCutoff),
922 strIsAveraged_(strIsAveraged), strFlatIncludeSpread_(strFlatIncludeSpread), strFlatLookback_(strFlatLookback),
923 strFlatFixingDays_(strFlatFixingDays), strFlatRateCutoff_(strFlatRateCutoff),
924 strFlatIsAveraged_(strFlatIsAveraged) {
925 build();
926}
927
929 settlementDays_ = lexical_cast<Natural>(strSettlementDays_);
934 eom_ = strEom_.empty() ? false : parseBool(strEom_);
937
938 // default to index tenor, except for ON indices, where we default to 3M since the index tenor 1D does not make sense for them
939
940 if (strFlatTenor_.empty()) {
941 auto tmp = flatIndex();
942 if (QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(tmp))
943 flatTenor_ = 3 * Months;
944 else
945 flatTenor_ = tmp->tenor();
946 } else {
948 }
949
950 if (strSpreadTenor_.empty()) {
951 auto tmp = spreadIndex();
952 if (QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(tmp))
953 spreadTenor_ = 3 * Months;
954 else
955 spreadTenor_ = tmp->tenor();
956 } else {
958 }
959
961 if (!strPaymentLag_.empty())
963 if (!strFlatPaymentLag_.empty())
965
966 // only OIS
967 if (!strIncludeSpread_.empty())
969 if (!strLookback_.empty())
971 if (!strFixingDays_.empty())
973 if (!strRateCutoff_.empty())
975 if (!strIsAveraged_.empty())
977 if (!strFlatIncludeSpread_.empty())
979 if (!strFlatLookback_.empty())
981 if (!strFlatFixingDays_.empty())
983 if (!strFlatRateCutoff_.empty())
985 if (!strFlatIsAveraged_.empty())
987}
988
990
991 XMLUtils::checkNode(node, "CrossCurrencyBasis");
993 id_ = XMLUtils::getChildValue(node, "Id", true);
994
995 // Get string values from xml
996 strSettlementDays_ = XMLUtils::getChildValue(node, "SettlementDays", true);
997 strSettlementCalendar_ = XMLUtils::getChildValue(node, "SettlementCalendar", true);
998 strRollConvention_ = XMLUtils::getChildValue(node, "RollConvention", true);
999 strFlatIndex_ = XMLUtils::getChildValue(node, "FlatIndex", true);
1000 strSpreadIndex_ = XMLUtils::getChildValue(node, "SpreadIndex", true);
1001 strEom_ = XMLUtils::getChildValue(node, "EOM", false);
1002 strIsResettable_ = XMLUtils::getChildValue(node, "IsResettable", false);
1003 strFlatIndexIsResettable_ = XMLUtils::getChildValue(node, "FlatIndexIsResettable", false, "true");
1004 strFlatTenor_ = XMLUtils::getChildValue(node, "FlatTenor", false);
1005 strSpreadTenor_ = XMLUtils::getChildValue(node, "SpreadTenor", false);
1006
1007 strPaymentLag_ = XMLUtils::getChildValue(node, "SpreadPaymentLag", false);
1008 strFlatPaymentLag_ = XMLUtils::getChildValue(node, "FlatPaymentLag", false);
1009
1010 // OIS specific conventions
1011
1012 strIncludeSpread_ = XMLUtils::getChildValue(node, "SpreadIncludeSpread", false);
1013 strLookback_ = XMLUtils::getChildValue(node, "SpreadLookback", false);
1014 strFixingDays_ = XMLUtils::getChildValue(node, "SpreadFixingDays", false);
1015 strRateCutoff_ = XMLUtils::getChildValue(node, "SpreadRateCutoff", false);
1016 strIsAveraged_ = XMLUtils::getChildValue(node, "SpreadIsAveraged", false);
1017
1018 strFlatIncludeSpread_ = XMLUtils::getChildValue(node, "FlatIncludeSpread", false);
1019 strFlatLookback_ = XMLUtils::getChildValue(node, "FlatLookback", false);
1020 strFlatFixingDays_ = XMLUtils::getChildValue(node, "FlatFixingDays", false);
1021 strFlatRateCutoff_ = XMLUtils::getChildValue(node, "FlatRateCutoff", false);
1022 strFlatIsAveraged_ = XMLUtils::getChildValue(node, "FlatIsAveraged", false);
1023
1024 build();
1025}
1026
1028
1029 XMLNode* node = doc.allocNode("CrossCurrencyBasis");
1030 XMLUtils::addChild(doc, node, "Id", id_);
1031 XMLUtils::addChild(doc, node, "SettlementDays", strSettlementDays_);
1032 XMLUtils::addChild(doc, node, "SettlementCalendar", strSettlementCalendar_);
1033 XMLUtils::addChild(doc, node, "RollConvention", strRollConvention_);
1034 XMLUtils::addChild(doc, node, "FlatIndex", strFlatIndex_);
1035 XMLUtils::addChild(doc, node, "SpreadIndex", strSpreadIndex_);
1036
1037 if (!strEom_.empty())
1038 XMLUtils::addChild(doc, node, "EOM", strEom_);
1039 if (!strIsResettable_.empty())
1040 XMLUtils::addChild(doc, node, "IsResettable", strIsResettable_);
1041 if (!strFlatIndexIsResettable_.empty())
1042 XMLUtils::addChild(doc, node, "FlatIndexIsResettable", strFlatIndexIsResettable_);
1043 if (!strFlatTenor_.empty())
1044 XMLUtils::addChild(doc, node, "FlatTenor", strFlatTenor_);
1045 if (!strSpreadTenor_.empty())
1046 XMLUtils::addChild(doc, node, "SpreadTenor", strSpreadTenor_);
1047 if (!strPaymentLag_.empty())
1048 XMLUtils::addChild(doc, node, "SpreadPaymentLag", strPaymentLag_);
1049 if (!strFlatPaymentLag_.empty())
1050 XMLUtils::addChild(doc, node, "FlatPaymentLag", strFlatPaymentLag_);
1051
1052 if (!strIncludeSpread_.empty())
1053 XMLUtils::addChild(doc, node, "SpreadIncludeSpread", strIncludeSpread_);
1054 if (!strLookback_.empty())
1055 XMLUtils::addChild(doc, node, "SpreadLookback", strLookback_);
1056 if (!strFixingDays_.empty())
1057 XMLUtils::addChild(doc, node, "SpreadFixingDays", strFixingDays_);
1058 if (!strRateCutoff_.empty())
1059 XMLUtils::addChild(doc, node, "SpreadRateCutoff", strRateCutoff_);
1060 if (!strIsAveraged_.empty())
1061 XMLUtils::addChild(doc, node, "SpreadIsAveraged", strIsAveraged_);
1062
1063 if (!strFlatIncludeSpread_.empty())
1064 XMLUtils::addChild(doc, node, "FlatIncludeSpread", strFlatIncludeSpread_);
1065 if (!strFlatLookback_.empty())
1066 XMLUtils::addChild(doc, node, "FlatLookback", strFlatLookback_);
1067 if (!strFlatFixingDays_.empty())
1068 XMLUtils::addChild(doc, node, "FlatFixingDays", strFlatFixingDays_);
1069 if (!strFlatRateCutoff_.empty())
1070 XMLUtils::addChild(doc, node, "FlatRateCutoff", strFlatRateCutoff_);
1071 if (!strFlatIsAveraged_.empty())
1072 XMLUtils::addChild(doc, node, "FlatIsAveraged", strFlatIsAveraged_);
1073
1074 return node;
1075}
1076
1077QuantLib::ext::shared_ptr<IborIndex> CrossCcyBasisSwapConvention::flatIndex() const { return parseIborIndex(strFlatIndex_); }
1078QuantLib::ext::shared_ptr<IborIndex> CrossCcyBasisSwapConvention::spreadIndex() const {
1080}
1081
1083 const string& id, const string& settlementDays, const string& settlementCalendar,
1084 const string& settlementConvention, const string& fixedCurrency, const string& fixedFrequency,
1085 const string& fixedConvention, const string& fixedDayCounter, const string& index, const string& eom,
1086 const std::string& strIsResettable, const std::string& strFloatIndexIsResettable)
1087 : Convention(id, Type::CrossCcyFixFloat), strSettlementDays_(settlementDays),
1088 strSettlementCalendar_(settlementCalendar), strSettlementConvention_(settlementConvention),
1089 strFixedCurrency_(fixedCurrency), strFixedFrequency_(fixedFrequency), strFixedConvention_(fixedConvention),
1090 strFixedDayCounter_(fixedDayCounter), strIndex_(index), strEom_(eom),
1091 strIsResettable_(strIsResettable), strFloatIndexIsResettable_(strFloatIndexIsResettable){
1092
1093 build();
1094}
1095
1097 settlementDays_ = lexical_cast<Natural>(strSettlementDays_);
1105 eom_ = strEom_.empty() ? false : parseBool(strEom_);
1108}
1109
1111
1112 XMLUtils::checkNode(node, "CrossCurrencyFixFloat");
1114 id_ = XMLUtils::getChildValue(node, "Id", true);
1115
1116 // Get string values from xml
1117 strSettlementDays_ = XMLUtils::getChildValue(node, "SettlementDays", true);
1118 strSettlementCalendar_ = XMLUtils::getChildValue(node, "SettlementCalendar", true);
1119 strSettlementConvention_ = XMLUtils::getChildValue(node, "SettlementConvention", true);
1120 strFixedCurrency_ = XMLUtils::getChildValue(node, "FixedCurrency", true);
1121 strFixedFrequency_ = XMLUtils::getChildValue(node, "FixedFrequency", true);
1122 strFixedConvention_ = XMLUtils::getChildValue(node, "FixedConvention", true);
1123 strFixedDayCounter_ = XMLUtils::getChildValue(node, "FixedDayCounter", true);
1124
1125 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
1126 strEom_ = XMLUtils::getChildValue(node, "EOM", false);
1127 strIsResettable_ = XMLUtils::getChildValue(node, "IsResettable", false);
1128 strFloatIndexIsResettable_ = XMLUtils::getChildValue(node, "FloatIndexIsResettable", false);
1129
1130 build();
1131}
1132
1134
1135 XMLNode* node = doc.allocNode("CrossCurrencyFixFloat");
1136 XMLUtils::addChild(doc, node, "Id", id_);
1137 XMLUtils::addChild(doc, node, "SettlementDays", strSettlementDays_);
1138 XMLUtils::addChild(doc, node, "SettlementCalendar", strSettlementCalendar_);
1139 XMLUtils::addChild(doc, node, "SettlementConvention", strSettlementConvention_);
1140 XMLUtils::addChild(doc, node, "FixedCurrency", strFixedCurrency_);
1141 XMLUtils::addChild(doc, node, "FixedFrequency", strFixedFrequency_);
1142 XMLUtils::addChild(doc, node, "FixedConvention", strFixedConvention_);
1143 XMLUtils::addChild(doc, node, "FixedDayCounter", strFixedDayCounter_);
1144 XMLUtils::addChild(doc, node, "Index", strIndex_);
1145
1146 if (!strEom_.empty())
1147 XMLUtils::addChild(doc, node, "EOM", strEom_);
1148 if (!strIsResettable_.empty())
1149 XMLUtils::addChild(doc, node, "IsResettable", strIsResettable_);
1150 if (!strFloatIndexIsResettable_.empty())
1151 XMLUtils::addChild(doc, node, "FloatIndexIsResettable", strFloatIndexIsResettable_);
1152
1153 return node;
1154}
1155
1156QuantLib::ext::shared_ptr<QuantLib::IborIndex> CrossCcyFixFloatSwapConvention::index() const {
1157 return parseIborIndex(strIndex_);
1158}
1159
1160CdsConvention::CdsConvention() : settlementDays_(0), frequency_(Quarterly), paymentConvention_(Following),
1161 rule_(DateGeneration::CDS2015), settlesAccrual_(true), paysAtDefaultTime_(true), upfrontSettlementDays_(3) {}
1162
1163CdsConvention::CdsConvention(const string& id, const string& strSettlementDays, const string& strCalendar,
1164 const string& strFrequency, const string& strPaymentConvention, const string& strRule,
1165 const string& strDayCounter, const string& strSettlesAccrual,
1166 const string& strPaysAtDefaultTime, const string& strUpfrontSettlementDays,
1167 const string& lastPeriodDayCounter)
1168 : Convention(id, Type::CDS), strSettlementDays_(strSettlementDays), strCalendar_(strCalendar),
1169 strFrequency_(strFrequency), strPaymentConvention_(strPaymentConvention), strRule_(strRule),
1170 strDayCounter_(strDayCounter), strSettlesAccrual_(strSettlesAccrual),
1171 strPaysAtDefaultTime_(strPaysAtDefaultTime), strUpfrontSettlementDays_(strUpfrontSettlementDays),
1172 strLastPeriodDayCounter_(lastPeriodDayCounter) {
1173 build();
1174}
1175
1177 settlementDays_ = lexical_cast<Natural>(strSettlementDays_);
1185
1187 if (!strUpfrontSettlementDays_.empty())
1188 upfrontSettlementDays_ = lexical_cast<Natural>(strUpfrontSettlementDays_);
1189
1190 lastPeriodDayCounter_ = DayCounter();
1191 if (!strLastPeriodDayCounter_.empty())
1193}
1194
1196
1197 XMLUtils::checkNode(node, "CDS");
1198 type_ = Type::CDS;
1199 id_ = XMLUtils::getChildValue(node, "Id", true);
1200
1201 // Get string values from xml
1202 strSettlementDays_ = XMLUtils::getChildValue(node, "SettlementDays", true);
1203 strCalendar_ = XMLUtils::getChildValue(node, "Calendar", true);
1204 strFrequency_ = XMLUtils::getChildValue(node, "Frequency", true);
1205 strPaymentConvention_ = XMLUtils::getChildValue(node, "PaymentConvention", true);
1206 strRule_ = XMLUtils::getChildValue(node, "Rule", true);
1207 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
1208 strSettlesAccrual_ = XMLUtils::getChildValue(node, "SettlesAccrual", true);
1209 strPaysAtDefaultTime_ = XMLUtils::getChildValue(node, "PaysAtDefaultTime", true);
1210 strUpfrontSettlementDays_ = XMLUtils::getChildValue(node, "UpfrontSettlementDays", false);
1211 strLastPeriodDayCounter_ = XMLUtils::getChildValue(node, "LastPeriodDayCounter", false);
1212
1213 build();
1214}
1215
1217
1218 XMLNode* node = doc.allocNode("CDS");
1219 XMLUtils::addChild(doc, node, "Id", id_);
1220 XMLUtils::addChild(doc, node, "SettlementDays", strSettlementDays_);
1221 XMLUtils::addChild(doc, node, "Calendar", strCalendar_);
1222 XMLUtils::addChild(doc, node, "Frequency", strFrequency_);
1223 XMLUtils::addChild(doc, node, "PaymentConvention", strPaymentConvention_);
1224 XMLUtils::addChild(doc, node, "Rule", strRule_);
1225 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
1226 XMLUtils::addChild(doc, node, "SettlesAccrual", strSettlesAccrual_);
1227 XMLUtils::addChild(doc, node, "PaysAtDefaultTime", strPaysAtDefaultTime_);
1228 if (!strUpfrontSettlementDays_.empty())
1229 XMLUtils::addChild(doc, node, "UpfrontSettlementDays", strUpfrontSettlementDays_);
1230 if (!strLastPeriodDayCounter_.empty())
1231 XMLUtils::addChild(doc, node, "LastPeriodDayCounter", strLastPeriodDayCounter_);
1232 return node;
1233}
1234
1236 : fixConvention_(Following), interpolated_(false), adjustInfObsDates_(false),
1237 infConvention_(Following), publicationRoll_(PublicationRoll::None) {}
1238
1239InflationSwapConvention::InflationSwapConvention(const string& id, const string& strFixCalendar,
1240 const string& strFixConvention, const string& strDayCounter,
1241 const string& strIndex, const string& strInterpolated,
1242 const string& strObservationLag, const string& strAdjustInfObsDates,
1243 const string& strInfCalendar, const string& strInfConvention,
1244 PublicationRoll publicationRoll,
1245 const QuantLib::ext::shared_ptr<ScheduleData>& publicationScheduleData)
1246 : Convention(id, Type::InflationSwap), strFixCalendar_(strFixCalendar), strFixConvention_(strFixConvention),
1247 strDayCounter_(strDayCounter), strIndex_(strIndex), strInterpolated_(strInterpolated),
1248 strObservationLag_(strObservationLag), strAdjustInfObsDates_(strAdjustInfObsDates),
1249 strInfCalendar_(strInfCalendar), strInfConvention_(strInfConvention),
1250 publicationRoll_(publicationRoll), publicationScheduleData_(publicationScheduleData) {
1251 build();
1252}
1253
1256 parseZeroInflationIndex(strIndex_, Handle<ZeroInflationTermStructure>());
1260 index_ = parseZeroInflationIndex(strIndex_, Handle<ZeroInflationTermStructure>());
1266 QL_REQUIRE(publicationScheduleData_, "Publication roll is " << publicationRoll_ << " for " << id() <<
1267 " so expect non-null publication schedule data.");
1269 }
1270}
1271
1273
1274 XMLUtils::checkNode(node, "InflationSwap");
1276 id_ = XMLUtils::getChildValue(node, "Id", true);
1277
1278 // Get string values from xml
1279 strFixCalendar_ = XMLUtils::getChildValue(node, "FixCalendar", true);
1280 strFixConvention_ = XMLUtils::getChildValue(node, "FixConvention", true);
1281 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
1282 strIndex_ = XMLUtils::getChildValue(node, "Index", true);
1283 strInterpolated_ = XMLUtils::getChildValue(node, "Interpolated", true);
1284 strObservationLag_ = XMLUtils::getChildValue(node, "ObservationLag", true);
1285 strAdjustInfObsDates_ = XMLUtils::getChildValue(node, "AdjustInflationObservationDates", true);
1286 strInfCalendar_ = XMLUtils::getChildValue(node, "InflationCalendar", true);
1287 strInfConvention_ = XMLUtils::getChildValue(node, "InflationConvention", true);
1288
1290 if (XMLNode* n = XMLUtils::getChildNode(node, "PublicationRoll")) {
1292 }
1293
1295 XMLNode* n = XMLUtils::getChildNode(node, "PublicationSchedule");
1296 QL_REQUIRE(n, "PublicationRoll is " << publicationRoll_ << " for " << id() <<
1297 " so expect non-empty PublicationSchedule.");
1298 publicationScheduleData_ = QuantLib::ext::make_shared<ScheduleData>();
1299 publicationScheduleData_->fromXML(n);
1300 }
1301
1302 build();
1303}
1304
1306
1307 XMLNode* node = doc.allocNode("InflationSwap");
1308 XMLUtils::addChild(doc, node, "Id", id_);
1309 XMLUtils::addChild(doc, node, "FixCalendar", strFixCalendar_);
1310 XMLUtils::addChild(doc, node, "FixConvention", strFixConvention_);
1311 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
1312 XMLUtils::addChild(doc, node, "Index", strIndex_);
1313 XMLUtils::addChild(doc, node, "Interpolated", strInterpolated_);
1314 XMLUtils::addChild(doc, node, "ObservationLag", strObservationLag_);
1315 XMLUtils::addChild(doc, node, "AdjustInflationObservationDates", strAdjustInfObsDates_);
1316 XMLUtils::addChild(doc, node, "InflationCalendar", strInfCalendar_);
1317 XMLUtils::addChild(doc, node, "InflationConvention", strInfConvention_);
1318
1320 XMLUtils::addChild(doc, node, "PublicationRoll", to_string(publicationRoll_));
1321 QL_REQUIRE(publicationScheduleData_, "PublicationRoll is " << publicationRoll_ << " for "
1322 << id() << " so expect PublicationSchedule.");
1323
1324 // Need to change the name from ScheduleData to PublicationSchedule.
1325 XMLNode* n = publicationScheduleData_->toXML(doc);
1326 XMLUtils::setNodeName(doc, n, "PublicationSchedule");
1327 XMLUtils::appendNode(node, n);
1328 }
1329
1330 return node;
1331}
1332
1333QuantLib::ext::shared_ptr<ZeroInflationIndex> InflationSwapConvention::index() const {
1334 return parseZeroInflationIndex(strIndex_, Handle<ZeroInflationTermStructure>());
1335}
1336
1337SecuritySpreadConvention::SecuritySpreadConvention(const string& id, const string& dayCounter,
1338 const string& compounding, const string& compoundingFrequency)
1339 : Convention(id, Type::SecuritySpread), tenorBased_(false), strDayCounter_(dayCounter),
1340 strCompounding_(compounding), strCompoundingFrequency_(compoundingFrequency) {
1341 build();
1342}
1343
1344SecuritySpreadConvention::SecuritySpreadConvention(const string& id, const string& dayCounter,
1345 const string& tenorCalendar, const string& compounding,
1346 const string& compoundingFrequency, const string& spotLag,
1347 const string& spotCalendar, const string& rollConvention,
1348 const string& eom)
1349 : Convention(id, Type::SecuritySpread), tenorBased_(true), strDayCounter_(dayCounter),
1350 strTenorCalendar_(tenorCalendar), strCompounding_(compounding), strCompoundingFrequency_(compoundingFrequency),
1351 strSpotLag_(spotLag), strSpotCalendar_(spotCalendar), strRollConvention_(rollConvention), strEom_(eom) {
1352 build();
1353}
1354
1359 if (tenorBased_) {
1361 spotLag_ = strSpotLag_.empty() ? 0 : lexical_cast<Natural>(strSpotLag_);
1362 spotCalendar_ = strSpotCalendar_.empty() ? NullCalendar() : parseCalendar(strSpotCalendar_);
1364 eom_ = strEom_.empty() ? false : parseBool(strEom_);
1365 }
1366}
1367
1369
1370 XMLUtils::checkNode(node, "BondSpread");
1372 id_ = XMLUtils::getChildValue(node, "Id", true);
1373 tenorBased_ = XMLUtils::getChildValueAsBool(node, "TenorBased", true);
1374
1375 // Get string values from xml
1376 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
1377 strCompoundingFrequency_ = XMLUtils::getChildValue(node, "CompoundingFrequency", false);
1378 strCompounding_ = XMLUtils::getChildValue(node, "Compounding", false);
1379 if (tenorBased_) {
1380 strTenorCalendar_ = XMLUtils::getChildValue(node, "TenorCalendar", true);
1381 strSpotLag_ = XMLUtils::getChildValue(node, "SpotLag", false);
1382 strSpotCalendar_ = XMLUtils::getChildValue(node, "SpotCalendar", false);
1383 strRollConvention_ = XMLUtils::getChildValue(node, "RollConvention", false);
1384 strEom_ = XMLUtils::getChildValue(node, "EOM", false);
1385 }
1386 build();
1387}
1388
1390
1391 XMLNode* node = doc.allocNode("BondSpread");
1392 XMLUtils::addChild(doc, node, "Id", id_);
1393 XMLUtils::addChild(doc, node, "TenorBased", tenorBased_);
1394 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
1395 if (!strCompoundingFrequency_.empty())
1396 XMLUtils::addChild(doc, node, "CompoundingFrequency", strCompoundingFrequency_);
1397 if (!strCompounding_.empty())
1398 XMLUtils::addChild(doc, node, "Compounding", strCompounding_);
1399 if (tenorBased_) {
1400 XMLUtils::addChild(doc, node, "TenorCalendar", strTenorCalendar_);
1401 if (!strSpotLag_.empty())
1402 XMLUtils::addChild(doc, node, "SpotLag", strSpotLag_);
1403 if (!strSpotCalendar_.empty())
1404 XMLUtils::addChild(doc, node, "SpotCalendar", strSpotCalendar_);
1405 if (!strRollConvention_.empty())
1406 XMLUtils::addChild(doc, node, "RollConvention", strRollConvention_);
1407 if (!strEom_.empty())
1408 XMLUtils::addChild(doc, node, "EOM", strEom_);
1409 }
1410
1411 return node;
1412}
1413
1414CmsSpreadOptionConvention::CmsSpreadOptionConvention(const string& id, const string& strForwardStart,
1415 const string& strSpotDays, const string& strSwapTenor,
1416 const string& strFixingDays, const string& strCalendar,
1417 const string& strDayCounter, const string& strConvention)
1418 : Convention(id, Type::CMSSpreadOption), strForwardStart_(strForwardStart), strSpotDays_(strSpotDays),
1419 strSwapTenor_(strSwapTenor), strFixingDays_(strFixingDays), strCalendar_(strCalendar),
1420 strDayCounter_(strDayCounter), strRollConvention_(strConvention) {
1421 build();
1422}
1423
1425
1426 XMLUtils::checkNode(node, "CmsSpreadOption");
1428 id_ = XMLUtils::getChildValue(node, "Id", true);
1429 strForwardStart_ = XMLUtils::getChildValue(node, "ForwardStart", true);
1430 strSpotDays_ = XMLUtils::getChildValue(node, "SpotDays", true);
1431 strSwapTenor_ = XMLUtils::getChildValue(node, "SwapTenor", true);
1432 strFixingDays_ = XMLUtils::getChildValue(node, "FixingDays", true);
1433 strCalendar_ = XMLUtils::getChildValue(node, "Calendar", true);
1434 strDayCounter_ = XMLUtils::getChildValue(node, "DayCounter", true);
1435 strRollConvention_ = XMLUtils::getChildValue(node, "RollConvention", true);
1436
1437 build();
1438}
1439
1441
1445 fixingDays_ = lexical_cast<Natural>(strFixingDays_);
1449}
1450
1452
1453 XMLNode* node = doc.allocNode("CmsSpreadOption");
1454 XMLUtils::addChild(doc, node, "Id", id_);
1455 XMLUtils::addChild(doc, node, "ForwardStart", strForwardStart_);
1456 XMLUtils::addChild(doc, node, "SpotDays", strSpotDays_);
1457 XMLUtils::addChild(doc, node, "SwapTenor", strSwapTenor_);
1458 XMLUtils::addChild(doc, node, "FixingDays", strFixingDays_);
1459 XMLUtils::addChild(doc, node, "Calendar", strCalendar_);
1460 XMLUtils::addChild(doc, node, "DayCounter", strDayCounter_);
1461 XMLUtils::addChild(doc, node, "RollConvention", strRollConvention_);
1462
1463 return node;
1464}
1465
1466CommodityForwardConvention::CommodityForwardConvention(const string& id, const string& spotDays,
1467 const string& pointsFactor, const string& advanceCalendar,
1468 const string& spotRelative, BusinessDayConvention bdc,
1469 bool outright)
1470 : Convention(id, Type::CommodityForward), bdc_(bdc), outright_(outright), strSpotDays_(spotDays),
1471 strPointsFactor_(pointsFactor), strAdvanceCalendar_(advanceCalendar), strSpotRelative_(spotRelative) {
1472 build();
1473}
1474
1476 spotDays_ = strSpotDays_.empty() ? 2 : lexical_cast<Natural>(strSpotDays_);
1480}
1481
1483
1484 XMLUtils::checkNode(node, "CommodityForward");
1486 id_ = XMLUtils::getChildValue(node, "Id", true);
1487
1488 strSpotDays_ = XMLUtils::getChildValue(node, "SpotDays", false);
1489 strPointsFactor_ = XMLUtils::getChildValue(node, "PointsFactor", false);
1490 strAdvanceCalendar_ = XMLUtils::getChildValue(node, "AdvanceCalendar", false);
1491 strSpotRelative_ = XMLUtils::getChildValue(node, "SpotRelative", false);
1492
1493 bdc_ = Following;
1494 if (XMLNode* n = XMLUtils::getChildNode(node, "BusinessDayConvention")) {
1496 }
1497
1498 outright_ = true;
1499 if (XMLNode* n = XMLUtils::getChildNode(node, "Outright")) {
1501 }
1502
1503 build();
1504}
1505
1507
1508 XMLNode* node = doc.allocNode("CommodityForward");
1509 XMLUtils::addChild(doc, node, "Id", id_);
1510
1511 if (!strSpotDays_.empty())
1512 XMLUtils::addChild(doc, node, "SpotDays", strSpotDays_);
1513 if (!strPointsFactor_.empty())
1514 XMLUtils::addChild(doc, node, "PointsFactor", strPointsFactor_);
1515 if (!strAdvanceCalendar_.empty())
1516 XMLUtils::addChild(doc, node, "AdvanceCalendar", strAdvanceCalendar_);
1517 if (!strSpotRelative_.empty())
1518 XMLUtils::addChild(doc, node, "SpotRelative", strSpotRelative_);
1519
1520
1521 XMLUtils::addChild(doc, node, "BusinessDayConvention", ore::data::to_string(bdc_));
1522 XMLUtils::addChild(doc, node, "Outright", outright_);
1523
1524 return node;
1525}
1526
1528 : useBusinessDays_(true), deliveryRollDays_(0), futureMonthOffset_(0),
1529 dailyExpiryOffset_(Null<Natural>()), period_(CalculationPeriod::ExpiryToExpiry) {}
1530
1531CommodityFutureConvention::AveragingData::AveragingData(const string& commodityName, const string& period,
1532 const string& pricingCalendar, bool useBusinessDays, const string& conventionsId,
1533 Natural deliveryRollDays, Natural futureMonthOffset, Natural dailyExpiryOffset)
1534 : commodityName_(commodityName), strPeriod_(period), strPricingCalendar_(pricingCalendar),
1535 useBusinessDays_(useBusinessDays), conventionsId_(conventionsId), deliveryRollDays_(deliveryRollDays),
1536 futureMonthOffset_(futureMonthOffset), dailyExpiryOffset_(dailyExpiryOffset),
1537 period_(CalculationPeriod::ExpiryToExpiry) {
1538 build();
1539}
1540
1542 return commodityName_;
1543}
1544
1546 return period_;
1547}
1548
1550 return pricingCalendar_;
1551}
1552
1554 return useBusinessDays_;
1555}
1556
1558 return conventionsId_;
1559}
1560
1562 return deliveryRollDays_;
1563}
1564
1566 return futureMonthOffset_;
1567}
1568
1570 return dailyExpiryOffset_;
1571}
1572
1574 return commodityName_.empty();
1575}
1576
1578
1579 XMLUtils::checkNode(node, "AveragingData");
1580 commodityName_ = XMLUtils::getChildValue(node, "CommodityName", true);
1581 strPeriod_ = XMLUtils::getChildValue(node, "Period", true);
1582 strPricingCalendar_ = XMLUtils::getChildValue(node, "PricingCalendar", true);
1583 useBusinessDays_ = true;
1584 if (XMLNode* n = XMLUtils::getChildNode(node, "UseBusinessDays")) {
1585 useBusinessDays_ = parseBool(XMLUtils::getNodeValue(n));
1586 }
1587 conventionsId_ = XMLUtils::getChildValue(node, "Conventions", false);
1588
1589 deliveryRollDays_ = 0;
1590 if (XMLNode* n = XMLUtils::getChildNode(node, "DeliveryRollDays")) {
1591 deliveryRollDays_ = parseInteger(XMLUtils::getNodeValue(n));
1592 }
1593
1594 futureMonthOffset_ = 0;
1595 if (XMLNode* n = XMLUtils::getChildNode(node, "FutureMonthOffset")) {
1596 futureMonthOffset_ = parseInteger(XMLUtils::getNodeValue(n));
1597 }
1598
1599 dailyExpiryOffset_ = Null<Natural>();
1600 if (XMLNode* n = XMLUtils::getChildNode(node, "DailyExpiryOffset")) {
1601 dailyExpiryOffset_ = parseInteger(XMLUtils::getNodeValue(n));
1602 }
1603
1604 build();
1605}
1606
1608
1609 XMLNode* node = doc.allocNode("AveragingData");
1610 XMLUtils::addChild(doc, node, "CommodityName", commodityName_);
1611 XMLUtils::addChild(doc, node, "Period", strPeriod_);
1612 XMLUtils::addChild(doc, node, "PricingCalendar", strPricingCalendar_);
1613 XMLUtils::addChild(doc, node, "UseBusinessDays", useBusinessDays_);
1614 if (!conventionsId_.empty())
1615 XMLUtils::addChild(doc, node, "Conventions", conventionsId_);
1616 if (deliveryRollDays_ != 0)
1617 XMLUtils::addChild(doc, node, "DeliveryRollDays", static_cast<int>(deliveryRollDays_));
1618 if (futureMonthOffset_ != 0)
1619 XMLUtils::addChild(doc, node, "FutureMonthOffset", static_cast<int>(futureMonthOffset_));
1620 if (dailyExpiryOffset_ != Null<Natural>())
1621 XMLUtils::addChild(doc, node, "DailyExpiryOffset", static_cast<int>(dailyExpiryOffset_));
1622
1623 return node;
1624}
1625
1627 period_ = parseAveragingDataPeriod(strPeriod_);
1628 pricingCalendar_ = parseCalendar(strPricingCalendar_);
1629}
1630
1632
1634 const string& offPeakIndex,
1635 const string& peakIndex,
1636 const string& offPeakHours,
1637 const string& peakCalendar)
1638 : offPeakIndex_(offPeakIndex),
1639 peakIndex_(peakIndex),
1640 strOffPeakHours_(offPeakHours),
1641 strPeakCalendar_(peakCalendar) {
1642 build();
1643}
1644
1646 offPeakHours_ = parseReal(strOffPeakHours_);
1647 peakCalendar_ = parseCalendar(strPeakCalendar_);
1648}
1649
1651
1652 XMLUtils::checkNode(node, "OffPeakPowerIndexData");
1653 offPeakIndex_ = XMLUtils::getChildValue(node, "OffPeakIndex", true);
1654 peakIndex_ = XMLUtils::getChildValue(node, "PeakIndex", true);
1655 strOffPeakHours_ = XMLUtils::getChildValue(node, "OffPeakHours", true);
1656 strPeakCalendar_ = XMLUtils::getChildValue(node, "PeakCalendar", true);
1657
1658 build();
1659}
1660
1662
1663 XMLNode* node = doc.allocNode("OffPeakPowerIndexData");
1664 XMLUtils::addChild(doc, node, "OffPeakIndex", offPeakIndex_);
1665 XMLUtils::addChild(doc, node, "PeakIndex", peakIndex_);
1666 XMLUtils::addChild(doc, node, "OffPeakHours", strOffPeakHours_);
1667 XMLUtils::addChild(doc, node, "PeakCalendar", strPeakCalendar_);
1668
1669 return node;
1670}
1671
1673 : forFuture_(true), futureBdc_(Preceding), forOption_(true), optionBdc_(Preceding) {}
1674
1676 bool forFuture,
1677 BusinessDayConvention futureBdc,
1678 bool forOption,
1679 BusinessDayConvention optionBdc)
1680 : expiry_(expiry), forFuture_(true), futureBdc_(Preceding),
1681 forOption_(true), optionBdc_(Preceding) {}
1682
1684 XMLUtils::checkNode(node, "Date");
1685 expiry_ = parseDate(XMLUtils::getNodeValue(node));
1686 string tmp = XMLUtils::getAttribute(node, "forFuture");
1687 forFuture_ = tmp.empty() ? true : parseBool(tmp);
1688 tmp = XMLUtils::getAttribute(node, "convention");
1689 futureBdc_ = tmp.empty() ? Preceding : parseBusinessDayConvention(tmp);
1690 tmp = XMLUtils::getAttribute(node, "forOption");
1691 forOption_ = tmp.empty() ? true : parseBool(tmp);
1692 tmp = XMLUtils::getAttribute(node, "optionConvention");
1693 optionBdc_ = tmp.empty() ? Preceding : parseBusinessDayConvention(tmp);
1694}
1695
1697
1698 XMLNode* node = doc.allocNode("Date", to_string(expiry_));
1699 XMLUtils::addAttribute(doc, node, "forFuture", to_string(forFuture_));
1700 XMLUtils::addAttribute(doc, node, "convention", to_string(futureBdc_));
1701 XMLUtils::addAttribute(doc, node, "forOption", to_string(forOption_));
1702 XMLUtils::addAttribute(doc, node, "optionConvention", to_string(optionBdc_));
1703
1704 return node;
1705}
1706
1709 return lhs.expiry() < rhs.expiry();
1710}
1711
1714 dayOfMonth_(1),
1715 nth_(1),
1716 weekday_(Mon),
1718 contractFrequency_(Monthly),
1719 oneContractMonth_(Jan),
1720 offsetDays_(0),
1721 bdc_(Following),
1722 expiryMonthLag_(0),
1723 adjustBeforeOffset_(false),
1724 isAveraging_(false),
1726 optionBdc_(Preceding),
1727 hoursPerDay_(Null<Natural>()),
1729 optionContractFrequency_(Monthly),
1731 optionNth_(1),
1732 optionWeekday_(Mon),
1733 optionExpiryDay_(Null<Natural>()),
1734 balanceOfTheMonth_(false) {}
1735
1736CommodityFutureConvention::CommodityFutureConvention(const string& id, const DayOfMonth& dayOfMonth,
1737 const string& contractFrequency, const string& calendar,
1738 const string& expiryCalendar, Size expiryMonthLag,
1739 const string& oneContractMonth, const string& offsetDays,
1740 const string& bdc, bool adjustBeforeOffset, bool isAveraging,
1741 const OptionExpiryAnchorDateRule& optionExpiryDateRule,
1742 const set<ProhibitedExpiry>& prohibitedExpiries,
1743 Size optionExpiryMonthLag,
1744 const string& optionBdc,
1745 const map<Natural, Natural>& futureContinuationMappings,
1746 const map<Natural, Natural>& optionContinuationMappings,
1747 const AveragingData& averagingData,
1748 Natural hoursPerDay,
1749 const boost::optional<OffPeakPowerIndexData>& offPeakPowerIndexData,
1750 const string& indexName,
1751 const std::string& optionFrequency)
1752 : Convention(id, Type::CommodityFuture), anchorType_(AnchorType::DayOfMonth),
1753 strDayOfMonth_(dayOfMonth.dayOfMonth_), strContractFrequency_(contractFrequency), strCalendar_(calendar),
1754 strExpiryCalendar_(expiryCalendar), expiryMonthLag_(expiryMonthLag), strOneContractMonth_(oneContractMonth),
1755 strOffsetDays_(offsetDays), strBdc_(bdc), adjustBeforeOffset_(adjustBeforeOffset), isAveraging_(isAveraging),
1756 prohibitedExpiries_(prohibitedExpiries),optionExpiryMonthLag_(optionExpiryMonthLag), strOptionBdc_(optionBdc),
1757 futureContinuationMappings_(futureContinuationMappings), optionContinuationMappings_(optionContinuationMappings),
1758 averagingData_(averagingData), hoursPerDay_(hoursPerDay), offPeakPowerIndexData_(offPeakPowerIndexData),
1759 indexName_(indexName), strOptionContractFrequency_(optionFrequency), optionAnchorType_(optionExpiryDateRule.type_), strOptionExpiryOffset_(optionExpiryDateRule.daysBefore_),
1760 strOptionExpiryDay_(optionExpiryDateRule.expiryDay_), strOptionNth_(optionExpiryDateRule.nth_),
1761 strOptionWeekday_(optionExpiryDateRule.weekday_), balanceOfTheMonth_(false) {
1762 build();
1763}
1764
1765CommodityFutureConvention::CommodityFutureConvention(const string& id, const string& nth, const string& weekday,
1766 const string& contractFrequency, const string& calendar,
1767 const string& expiryCalendar, Size expiryMonthLag,
1768 const string& oneContractMonth, const string& offsetDays,
1769 const string& bdc, bool adjustBeforeOffset, bool isAveraging,
1770 const OptionExpiryAnchorDateRule& optionExpiryDateRule,
1771 const set<ProhibitedExpiry>& prohibitedExpiries,
1772 Size optionExpiryMonthLag,
1773 const string& optionBdc,
1774 const map<Natural, Natural>& futureContinuationMappings,
1775 const map<Natural, Natural>& optionContinuationMappings,
1776 const AveragingData& averagingData,
1777 Natural hoursPerDay,
1778 const boost::optional<OffPeakPowerIndexData>& offPeakPowerIndexData,
1779 const string& indexName,
1780 const std::string& optionFrequency)
1781 : Convention(id, Type::CommodityFuture), anchorType_(AnchorType::NthWeekday), strNth_(nth), strWeekday_(weekday),
1782 strContractFrequency_(contractFrequency), strCalendar_(calendar), strExpiryCalendar_(expiryCalendar),
1783 expiryMonthLag_(expiryMonthLag), strOneContractMonth_(oneContractMonth), strOffsetDays_(offsetDays), strBdc_(bdc),
1784 adjustBeforeOffset_(adjustBeforeOffset), isAveraging_(isAveraging),
1785 prohibitedExpiries_(prohibitedExpiries), optionExpiryMonthLag_(optionExpiryMonthLag), strOptionBdc_(optionBdc),
1786 futureContinuationMappings_(futureContinuationMappings), optionContinuationMappings_(optionContinuationMappings),
1787 averagingData_(averagingData), hoursPerDay_(hoursPerDay), offPeakPowerIndexData_(offPeakPowerIndexData),
1788 indexName_(indexName), strOptionContractFrequency_(optionFrequency),
1789 optionAnchorType_(optionExpiryDateRule.type_), strOptionExpiryOffset_(optionExpiryDateRule.daysBefore_),
1790 strOptionExpiryDay_(optionExpiryDateRule.expiryDay_), strOptionNth_(optionExpiryDateRule.nth_),
1791 strOptionWeekday_(optionExpiryDateRule.weekday_), balanceOfTheMonth_(false) {
1792 build();
1793}
1794
1795CommodityFutureConvention::CommodityFutureConvention(const string& id, const CalendarDaysBefore& calendarDaysBefore,
1796 const string& contractFrequency, const string& calendar,
1797 const string& expiryCalendar, Size expiryMonthLag,
1798 const string& oneContractMonth, const string& offsetDays,
1799 const string& bdc, bool adjustBeforeOffset, bool isAveraging,
1800 const OptionExpiryAnchorDateRule& optionExpiryDateRule,
1801 const set<ProhibitedExpiry>& prohibitedExpiries,
1802 Size optionExpiryMonthLag,
1803 const string& optionBdc,
1804 const map<Natural, Natural>& futureContinuationMappings,
1805 const map<Natural, Natural>& optionContinuationMappings,
1806 const AveragingData& averagingData,
1807 Natural hoursPerDay,
1808 const boost::optional<OffPeakPowerIndexData>& offPeakPowerIndexData,
1809 const string& indexName,
1810 const std::string& optionFrequency)
1811 : Convention(id, Type::CommodityFuture), anchorType_(AnchorType::CalendarDaysBefore),
1812 strCalendarDaysBefore_(calendarDaysBefore.calendarDaysBefore_), strContractFrequency_(contractFrequency),
1813 strCalendar_(calendar), strExpiryCalendar_(expiryCalendar), expiryMonthLag_(expiryMonthLag),
1814 strOneContractMonth_(oneContractMonth), strOffsetDays_(offsetDays), strBdc_(bdc),
1815 adjustBeforeOffset_(adjustBeforeOffset), isAveraging_(isAveraging),
1816 prohibitedExpiries_(prohibitedExpiries), optionExpiryMonthLag_(optionExpiryMonthLag), strOptionBdc_(optionBdc),
1817 futureContinuationMappings_(futureContinuationMappings),
1818 optionContinuationMappings_(optionContinuationMappings), averagingData_(averagingData), hoursPerDay_(hoursPerDay), offPeakPowerIndexData_(offPeakPowerIndexData),
1819 indexName_(indexName), strOptionContractFrequency_(optionFrequency),
1820 optionAnchorType_(optionExpiryDateRule.type_), strOptionExpiryOffset_(optionExpiryDateRule.daysBefore_),
1821 strOptionExpiryDay_(optionExpiryDateRule.expiryDay_), strOptionNth_(optionExpiryDateRule.nth_),
1822 strOptionWeekday_(optionExpiryDateRule.weekday_), balanceOfTheMonth_(false) {
1823 build();
1824}
1825
1826CommodityFutureConvention::CommodityFutureConvention(const string& id, const BusinessDaysAfter& businessDaysAfter,
1827 const string& contractFrequency, const string& calendar,
1828 const string& expiryCalendar, Size expiryMonthLag,
1829 const string& oneContractMonth, const string& offsetDays,
1830 const string& bdc, bool adjustBeforeOffset, bool isAveraging,
1831 const OptionExpiryAnchorDateRule& optionExpiryDateRule,
1832 const set<ProhibitedExpiry>& prohibitedExpiries,
1833 Size optionExpiryMonthLag,
1834 const string& optionBdc,
1835 const map<Natural, Natural>& futureContinuationMappings,
1836 const map<Natural, Natural>& optionContinuationMappings,
1837 const AveragingData& averagingData,
1838 Natural hoursPerDay,
1839 const boost::optional<OffPeakPowerIndexData>& offPeakPowerIndexData,
1840 const string& indexName,
1841 const std::string& optionFrequency)
1842 : Convention(id, Type::CommodityFuture), anchorType_(AnchorType::BusinessDaysAfter),
1843 strBusinessDaysAfter_(businessDaysAfter.businessDaysAfter_), strContractFrequency_(contractFrequency),
1844 strCalendar_(calendar), strExpiryCalendar_(expiryCalendar), expiryMonthLag_(expiryMonthLag),
1845 strOneContractMonth_(oneContractMonth), strOffsetDays_(offsetDays), strBdc_(bdc),
1846 adjustBeforeOffset_(adjustBeforeOffset), isAveraging_(isAveraging),
1847 prohibitedExpiries_(prohibitedExpiries), optionExpiryMonthLag_(optionExpiryMonthLag), strOptionBdc_(optionBdc),
1848 futureContinuationMappings_(futureContinuationMappings),
1849 optionContinuationMappings_(optionContinuationMappings), averagingData_(averagingData), hoursPerDay_(hoursPerDay), offPeakPowerIndexData_(offPeakPowerIndexData),
1850 indexName_(indexName), strOptionContractFrequency_(optionFrequency),
1851 optionAnchorType_(optionExpiryDateRule.type_), strOptionExpiryOffset_(optionExpiryDateRule.daysBefore_),
1852 strOptionExpiryDay_(optionExpiryDateRule.expiryDay_), strOptionNth_(optionExpiryDateRule.nth_),
1853 strOptionWeekday_(optionExpiryDateRule.weekday_), balanceOfTheMonth_(false) {
1854 build();
1855}
1856
1857
1859
1860 XMLUtils::checkNode(node, "CommodityFuture");
1862 id_ = XMLUtils::getChildValue(node, "Id", true);
1863
1864 // Parse contract frequency first. If it is Daily, we do not need the AnchorDay node.
1865 strContractFrequency_ = XMLUtils::getChildValue(node, "ContractFrequency", true);
1866 strOptionContractFrequency_ = XMLUtils::getChildValue(node, "OptionContractFrequency", false);
1867 if (strOptionContractFrequency_.empty())
1869
1872
1873 // Variables related to the anchor day in a given month. Not needed if daily.
1874 if (contractFrequency_ == Weekly) {
1875 XMLNode* anchorNode = XMLUtils::getChildNode(node, "AnchorDay");
1876 if (XMLNode* tmp = XMLUtils::getChildNode(anchorNode, "WeeklyDayOfTheWeek")) {
1879 } else {
1880 QL_FAIL("Failed to parse AnchorDay node, the WeeklyDayOfTheWeek node is required for weekly contract expiries.");
1881 }
1882 } else if (contractFrequency_ != Daily || optionContractFrequency_ != Daily) {
1883 XMLNode* anchorNode = XMLUtils::getChildNode(node, "AnchorDay");
1884 QL_REQUIRE(anchorNode, "Expected an AnchorDay node in the FutureExpiry convention");
1885 if (XMLNode* nthNode = XMLUtils::getChildNode(anchorNode, "NthWeekday")) {
1887 strNth_ = XMLUtils::getChildValue(nthNode, "Nth", true);
1888 strWeekday_ = XMLUtils::getChildValue(nthNode, "Weekday", true);
1889 } else if (XMLNode* tmp = XMLUtils::getChildNode(anchorNode, "DayOfMonth")) {
1892 } else if (XMLNode* tmp = XMLUtils::getChildNode(anchorNode, "CalendarDaysBefore")) {
1895 } else if (XMLNode* tmp = XMLUtils::getChildNode(anchorNode, "LastWeekday")) {
1898 } else if (XMLNode* tmp = XMLUtils::getChildNode(anchorNode, "BusinessDaysAfter")) {
1901 } else {
1902 QL_FAIL("Failed to parse AnchorDay node");
1903 }
1904 }
1905
1906 strCalendar_ = XMLUtils::getChildValue(node, "Calendar", true);
1907 strExpiryCalendar_ = XMLUtils::getChildValue(node, "ExpiryCalendar", false);
1908
1909 expiryMonthLag_ = 0;
1910 if (XMLNode* n = XMLUtils::getChildNode(node, "ExpiryMonthLag")) {
1912 }
1913
1914 strOneContractMonth_ = XMLUtils::getChildValue(node, "OneContractMonth", false);
1915 strOffsetDays_ = XMLUtils::getChildValue(node, "OffsetDays", false);
1916 strBdc_ = XMLUtils::getChildValue(node, "BusinessDayConvention", false);
1917
1918 adjustBeforeOffset_ = true;
1919 if (XMLNode* n = XMLUtils::getChildNode(node, "AdjustBeforeOffset")) {
1921 }
1922
1923 isAveraging_ = false;
1924 if (XMLNode* n = XMLUtils::getChildNode(node, "IsAveraging")) {
1926 }
1927
1929 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryMonthLag")) {
1931 }
1932
1933 bool foundOptionExpiryRule = false;
1934 std::string previouslyFoundOptionExpiryRule = "";
1935
1936 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryOffset")) {
1937 QL_REQUIRE(optionContractFrequency_ != Weekly, "OptionExpiryOffset is not allowed for weekly option expiries");
1940 foundOptionExpiryRule = true;
1941 previouslyFoundOptionExpiryRule = "OptionExpiryOffset";
1942 }
1943
1944 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryDay")) {
1945 QL_REQUIRE(!foundOptionExpiryRule, "Expect exactly one option expiry anchor date rule, found "
1946 << previouslyFoundOptionExpiryRule << " and OptionExpiryDay");
1947 QL_REQUIRE(optionContractFrequency_ != Weekly, "OptionExpiryDay is not allowed for weekly option expiries");
1950 foundOptionExpiryRule = true;
1951 previouslyFoundOptionExpiryRule = "OptionExpiryDay";
1952 }
1953
1954 if (XMLNode* optionNthNode = XMLUtils::getChildNode(node, "OptionNthWeekday")) {
1955 QL_REQUIRE(!foundOptionExpiryRule, "Expect exactly one option expiry anchor date rule, found "
1956 << previouslyFoundOptionExpiryRule << " and OptionNthWeekday");
1957 QL_REQUIRE(optionContractFrequency_ != Weekly,
1958 "OptionNthWeekday is not allowed for weekly option expiries");
1960 strOptionNth_ = XMLUtils::getChildValue(optionNthNode, "Nth", true);
1961 strOptionWeekday_ = XMLUtils::getChildValue(optionNthNode, "Weekday", true);
1962 foundOptionExpiryRule = true;
1963 previouslyFoundOptionExpiryRule = "OptionNthWeekday";
1964 }
1965
1966 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryLastWeekdayOfMonth")) {
1967 QL_REQUIRE(!foundOptionExpiryRule, "Expect exactly one option expiry anchor date rule, found "
1968 << previouslyFoundOptionExpiryRule << " and OptionExpiryLastWeekdayOfMonth");
1969 QL_REQUIRE(optionContractFrequency_ != Weekly,
1970 "OptionExpiryLastWeekdayOfMonth is not allowed for weekly option expiries");
1973 foundOptionExpiryRule = true;
1974 previouslyFoundOptionExpiryRule = "OptionExpiryLastWeekdayOfMonth";
1975 }
1976
1977 if (XMLNode* n = XMLUtils::getChildNode(node, "OptionExpiryWeeklyDayOfTheWeek")) {
1978 QL_REQUIRE(!foundOptionExpiryRule, "Expect exactly one option expiry anchor date rule, found "
1979 << previouslyFoundOptionExpiryRule
1980 << " and OptionExpiryWeeklyDayOfTheWeek");
1981 QL_REQUIRE(optionContractFrequency_ == Weekly,
1982 "OptionExpiryWeeklyDayOfTheWeek only allowed for weekly option expiries");
1985 foundOptionExpiryRule = true;
1986 previouslyFoundOptionExpiryRule = "OptionExpiryWeeklyDayOfTheWeek";
1987 }
1988
1989
1990 if (!foundOptionExpiryRule && optionContractFrequency_ == Weekly) {
1993 } else if (!foundOptionExpiryRule) {
1996 }
1997
1998
1999
2000 if (XMLNode* n = XMLUtils::getChildNode(node, "ProhibitedExpiries")) {
2001 auto datesNode = XMLUtils::getChildNode(n, "Dates");
2002 QL_REQUIRE(datesNode, "ProhibitedExpiries node must have a Dates node.");
2003 auto dateNodes = XMLUtils::getChildrenNodes(datesNode, "Date");
2004 for (const auto& dateNode : dateNodes) {
2006 pe.fromXML(dateNode);
2007 if (validateBdc(pe)) {
2008 // First date is inserted, subsequent duplicates are ignored.
2009 prohibitedExpiries_.insert(pe);
2010 }
2011 }
2012 }
2013
2014 if (contractFrequency_ == Monthly) {
2015 auto validContractMonthNode = XMLUtils::getChildNode(node, "ValidContractMonths");
2016 if (validContractMonthNode) {
2017 auto monthNodes = XMLUtils::getChildrenNodes(validContractMonthNode, "Month");
2018 for (const auto& month : monthNodes) {
2020 }
2021 }
2022 }
2023
2024 strOptionBdc_ = XMLUtils::getChildValue(node, "OptionBusinessDayConvention", false);
2025
2027 auto tmp = XMLUtils::getChildrenValues(node, "FutureContinuationMappings",
2028 "ContinuationMapping", "From", "To", false);
2029 for (const auto& kv : tmp) {
2031 }
2032
2034 tmp = XMLUtils::getChildrenValues(node, "OptionContinuationMappings",
2035 "ContinuationMapping", "From", "To", false);
2036 for (const auto& kv : tmp) {
2038 }
2039
2040 if (isAveraging_) {
2041 if (XMLNode* n = XMLUtils::getChildNode(node, "AveragingData")) {
2043 }
2044 }
2045
2046 hoursPerDay_ = Null<Natural>();
2047 if (XMLNode* n = XMLUtils::getChildNode(node, "HoursPerDay")) {
2049 }
2050
2051 if (XMLNode* n = XMLUtils::getChildNode(node, "OffPeakPowerIndexData")) {
2053 offPeakPowerIndexData_->fromXML(n);
2054 }
2055
2056 indexName_ = XMLUtils::getChildValue(node, "IndexName", false);
2057
2058 savingsTime_ = XMLUtils::getChildValue(node, "SavingsTime", false, "US");
2059
2060 balanceOfTheMonth_ = XMLUtils::getChildValueAsBool(node, "BalanceOfTheMonth", false, false);
2061
2062 balanceOfTheMonthPricingCalendarStr_ = XMLUtils::getChildValue(node, "BalanceOfTheMonthPricingCalendar", false, "");
2063
2064 optionUnderlyingFutureConvention_ = XMLUtils::getChildValue(node, "OptionUnderlyingFutureConvention", false, "");
2065
2066 build();
2067}
2068
2070
2071 XMLNode* node = doc.allocNode("CommodityFuture");
2072 XMLUtils::addChild(doc, node, "Id", id_);
2073
2074 if (contractFrequency_ != Daily || optionContractFrequency_ != Daily) {
2075 XMLNode* anchorNode = doc.allocNode("AnchorDay");
2077 XMLUtils::addChild(doc, anchorNode, "DayOfMonth", strDayOfMonth_);
2078 } else if (anchorType_ == AnchorType::NthWeekday) {
2079 XMLNode* nthNode = doc.allocNode("NthWeekday");
2080 XMLUtils::addChild(doc, nthNode, "Nth", strNth_);
2081 XMLUtils::addChild(doc, nthNode, "Weekday", strWeekday_);
2082 XMLUtils::appendNode(anchorNode, nthNode);
2083 } else if (anchorType_ == AnchorType::LastWeekday) {
2084 XMLUtils::addChild(doc, anchorNode, "LastWeekday", strWeekday_);
2086 XMLUtils::addChild(doc, anchorNode, "BusinessDaysAfter", strBusinessDaysAfter_);
2088 XMLUtils::addChild(doc, anchorNode, "WeeklyDayOfTheWeek", strWeekday_);
2089 } else {
2090 XMLUtils::addChild(doc, anchorNode, "CalendarDaysBefore", strCalendarDaysBefore_);
2091 }
2092 XMLUtils::appendNode(node, anchorNode);
2093 }
2094
2095 XMLUtils::addChild(doc, node, "ContractFrequency", strContractFrequency_);
2096 XMLUtils::addChild(doc, node, "Calendar", strCalendar_);
2097 if (!strExpiryCalendar_.empty())
2098 XMLUtils::addChild(doc, node, "ExpiryCalendar", strExpiryCalendar_);
2099 XMLUtils::addChild(doc, node, "ExpiryMonthLag", static_cast<int>(expiryMonthLag_));
2100
2101 if (!strOneContractMonth_.empty())
2102 XMLUtils::addChild(doc, node, "OneContractMonth", strOneContractMonth_);
2103
2104 if (!strOffsetDays_.empty())
2105 XMLUtils::addChild(doc, node, "OffsetDays", strOffsetDays_);
2106
2107 if (!strBdc_.empty())
2108 XMLUtils::addChild(doc, node, "BusinessDayConvention", strBdc_);
2109
2110 XMLUtils::addChild(doc, node, "AdjustBeforeOffset", adjustBeforeOffset_);
2111 XMLUtils::addChild(doc, node, "IsAveraging", isAveraging_);
2112
2114 if (optionExpiryOffset_>0)
2115 XMLUtils::addChild(doc, node, "OptionExpiryOffset", strOptionExpiryOffset_);
2117 XMLUtils::addChild(doc, node, "OptionExpiryDay", static_cast<int>(optionExpiryDay_));
2119 XMLNode* nthNode = doc.allocNode("OptionNthWeekday");
2120 XMLUtils::addChild(doc, nthNode, "Nth", strOptionNth_);
2121 XMLUtils::addChild(doc, nthNode, "Weekday", strOptionWeekday_);
2122 XMLUtils::appendNode(node, nthNode);
2124 XMLUtils::addChild(doc, node, "OptionExpiryLastWeekdayOfMonth", strOptionWeekday_);
2126 XMLUtils::addChild(doc, node, "OptionExpiryWeeklyDayOfTheWeek", strOptionWeekday_);
2127 }
2128
2129 if (!prohibitedExpiries_.empty()) {
2130 XMLNode* prohibitedExpiriesNode = doc.allocNode("ProhibitedExpiries");
2131 XMLNode* datesNode = XMLUtils::addChild(doc, prohibitedExpiriesNode, "Dates");
2133 XMLUtils::appendNode(datesNode, pe.toXML(doc));
2134 }
2135 XMLUtils::appendNode(node, prohibitedExpiriesNode);
2136 }
2137
2138 XMLUtils::addChild(doc, node, "OptionExpiryMonthLag", static_cast<int>(optionExpiryMonthLag_));
2139
2140
2141 if (!strOptionBdc_.empty())
2142 XMLUtils::addChild(doc, node, "OptionBusinessDayConvention", strOptionBdc_);
2143
2144 if (!futureContinuationMappings_.empty()) {
2145 map<string, string> tmp;
2146 for (const auto& kv : futureContinuationMappings_) {
2147 tmp[to_string(kv.first)] = to_string(kv.second);
2148 }
2149 XMLUtils::addChildren(doc, node, "FutureContinuationMappings",
2150 "ContinuationMapping", "From", "To", tmp);
2151 }
2152
2153 if (!optionContinuationMappings_.empty()) {
2154 map<string, string> tmp;
2155 for (const auto& kv : optionContinuationMappings_) {
2156 tmp[to_string(kv.first)] = to_string(kv.second);
2157 }
2158 XMLUtils::addChildren(doc, node, "OptionContinuationMappings",
2159 "ContinuationMapping", "From", "To", tmp);
2160 }
2161
2162 if (!averagingData_.empty()) {
2164 }
2165
2166 if (hoursPerDay_ != Null<Natural>())
2167 XMLUtils::addChild(doc, node, "HoursPerDay", static_cast<int>(hoursPerDay_));
2168
2171 }
2172
2173 if (!indexName_.empty())
2174 XMLUtils::addChild(doc, node, "IndexName", indexName_);
2175
2176 if (!savingsTime_.empty())
2177 XMLUtils::addChild(doc, node, "SavingsTime", savingsTime_);
2178
2179 if (contractFrequency_ == Monthly && !validContractMonths_.empty() && validContractMonths_.size() < 12) {
2180 XMLNode* validContractMonthNode = doc.allocNode("ValidContractMonths");
2181 for (auto month : validContractMonths_) {
2182 XMLUtils::addChild(doc, validContractMonthNode, "Month", to_string(month));
2183 }
2184 XMLUtils::appendNode(node, validContractMonthNode);
2185 }
2186
2187 if (balanceOfTheMonth_) {
2188 XMLUtils::addChild(doc, node, "BalanceOfTheMonth", balanceOfTheMonth_);
2189 }
2190
2191 if (balanceOfTheMonthPricingCalendar_ != Calendar()) {
2192 XMLUtils::addChild(doc, node, "BalanceOfTheMonthPricingCalendar", to_string(balanceOfTheMonthPricingCalendar_));
2193 }
2194
2195 if (!optionUnderlyingFutureConvention_.empty()) {
2196 XMLUtils::addChild(doc, node, "OptionUnderlyingFutureConvention", optionUnderlyingFutureConvention_);
2197 XMLUtils::addChild(doc, node, "OptionContractFrequency", strOptionContractFrequency_);
2198 }
2199
2200 return node;
2201}
2202
2204
2206 if (strOptionContractFrequency_.empty()) {
2208 } else {
2210 }
2211
2212 if (contractFrequency_ != Daily || optionContractFrequency_ != Daily) {
2214 dayOfMonth_ = lexical_cast<Natural>(strDayOfMonth_);
2216 calendarDaysBefore_ = lexical_cast<Natural>(strCalendarDaysBefore_);
2217 } else if (anchorType_ == AnchorType::LastWeekday) {
2220 businessDaysAfter_ = lexical_cast<Integer>(strBusinessDaysAfter_);
2223 } else {
2224 nth_ = lexical_cast<Natural>(strNth_);
2226 }
2227 }
2228
2231
2232 // Optional entries
2234 offsetDays_ = strOffsetDays_.empty() ? 0 : lexical_cast<Integer>(strOffsetDays_);
2235 bdc_ = strBdc_.empty() ? Preceding : parseBusinessDayConvention(strBdc_);
2236
2238 if (strOptionExpiryOffset_.empty())
2240 else
2241 optionExpiryOffset_ = lexical_cast<Natural>(strOptionExpiryOffset_);
2243 optionNth_ = lexical_cast<Natural>(strOptionNth_);
2247 optionExpiryDay_ = lexical_cast<Natural>(strOptionExpiryDay_);
2252 } else {
2255 }
2256
2258
2259 // Check the continuation mappings
2260 checkContinuationMappings(futureContinuationMappings_, "future");
2261 checkContinuationMappings(optionContinuationMappings_, "option");
2262
2263 // Check that neither of the indexes in OffPeakPowerIndexData self reference
2265 const string& opIdx = offPeakPowerIndexData_->offPeakIndex();
2266 QL_REQUIRE(id_ != opIdx, "The off-peak index (" << opIdx << ") cannot equal the index for which" <<
2267 " we are providing conventions (" << id_ << ").");
2268 const string& pIdx = offPeakPowerIndexData_->peakIndex();
2269 QL_REQUIRE(id_ != pIdx, "The peak index (" << pIdx << ") cannot equal the index for which" <<
2270 " we are providing conventions (" << id_ << ").");
2271 }
2272
2275 } else {
2277 }
2278
2279 QL_REQUIRE(!balanceOfTheMonth_ || isAveraging(), "Balance of the month make only sense for averaging futures");
2280
2281}
2282
2283Frequency CommodityFutureConvention::parseAndValidateFrequency(const std::string & strFrequency) {
2284 auto freq = parseFrequency(strFrequency);
2285 QL_REQUIRE(freq == Annual || freq == Quarterly || freq == Monthly || freq == Weekly || freq == Daily,
2286 "Contract frequency should be annual, quarterly, monthly, weekly or daily but got " << freq);
2287 return freq;
2288}
2289
2291 vector<BusinessDayConvention> bdcs{ pe.futureBdc(), pe.optionBdc() };
2292 for (auto bdc : bdcs) {
2293 if (!(bdc == Preceding || bdc == Following || bdc == ModifiedPreceding || bdc == ModifiedFollowing)) {
2294 WLOG("Prohibited expiry bdc must be one of {Preceding, Following, ModifiedPreceding," <<
2295 " ModifiedFollowing} but got " << bdc << " for date " << io::iso_date(pe.expiry()) << ".");
2296 return false;
2297 }
2298 }
2299 return true;
2300}
2301
2302FxOptionConvention::FxOptionConvention(const string& id, const string& atmType, const string& deltaType,
2303 const string& switchTenor, const string& longTermAtmType,
2304 const string& longTermDeltaType, const string& riskReversalInFavorOf,
2305 const string& butterflyStyle, const string& fxConventionID)
2306 : Convention(id, Type::FxOption), fxConventionID_(fxConventionID), strAtmType_(atmType), strDeltaType_(deltaType),
2307 strSwitchTenor_(switchTenor), strLongTermAtmType_(longTermAtmType), strLongTermDeltaType_(longTermDeltaType),
2308 strRiskReversalInFavorOf_(riskReversalInFavorOf), strButterflyStyle_(butterflyStyle) {
2309 build();
2310}
2311
2315 if (!strSwitchTenor_.empty()) {
2319 } else {
2320 switchTenor_ = 0 * Days;
2323 }
2324 if (!strRiskReversalInFavorOf_.empty()) {
2326 } else {
2327 riskReversalInFavorOf_ = Option::Call;
2328 }
2329 if (strButterflyStyle_.empty() || strButterflyStyle_ == "Broker") {
2331 } else if (strButterflyStyle_ == "Smile") {
2333 } else {
2334 QL_FAIL("invalid butterfly style '" << strButterflyStyle_ << "', expected Broker or Smile");
2335 }
2336}
2337
2339
2340 XMLUtils::checkNode(node, "FxOption");
2342 id_ = XMLUtils::getChildValue(node, "Id", true);
2343 fxConventionID_ = XMLUtils::getChildValue(node, "FXConventionID", false);
2344
2345 // Get string values from xml
2346 strAtmType_ = XMLUtils::getChildValue(node, "AtmType", true);
2347 strDeltaType_ = XMLUtils::getChildValue(node, "DeltaType", true);
2348 strSwitchTenor_ = XMLUtils::getChildValue(node, "SwitchTenor", false);
2349 strLongTermAtmType_ = XMLUtils::getChildValue(node, "LongTermAtmType", false);
2350 strLongTermDeltaType_ = XMLUtils::getChildValue(node, "LongTermDeltaType", false);
2351 strRiskReversalInFavorOf_ = XMLUtils::getChildValue(node, "RiskReversalInFavorOf", false);
2352 strButterflyStyle_ = XMLUtils::getChildValue(node, "ButterflyStyle", false);
2353 build();
2354}
2355
2357
2358 XMLNode* node = doc.allocNode("FxOption");
2359 XMLUtils::addChild(doc, node, "Id", id_);
2360 XMLUtils::addChild(doc, node, "FXConventionID", fxConventionID_);
2361 XMLUtils::addChild(doc, node, "AtmType", strAtmType_);
2362 XMLUtils::addChild(doc, node, "DeltaType", strDeltaType_);
2363 XMLUtils::addChild(doc, node, "SwitchTenor", strSwitchTenor_);
2364 XMLUtils::addChild(doc, node, "LongTermAtmType", strLongTermAtmType_);
2365 XMLUtils::addChild(doc, node, "LongTermDeltaType", strLongTermDeltaType_);
2366 XMLUtils::addChild(doc, node, "RiskReversalInFavorOf", strRiskReversalInFavorOf_);
2367 XMLUtils::addChild(doc, node, "ButterflyStyle", strButterflyStyle_);
2368 return node;
2369}
2370
2372 : compounding_(Compounded), compoundingName_("Compounded"),
2373 frequency_(Annual), frequencyName_("Annual"),
2374 priceType_(QuantLib::Bond::Price::Type::Clean), priceTypeName_("Clean"),
2375 accuracy_(1.0e-8), maxEvaluations_(100), guess_(0.05) {}
2376
2378 const string& id,
2379 const string& compoundingName,
2380 const string& frequencyName,
2381 const string& priceTypeName,
2382 Real accuracy,
2383 Size maxEvaluations,
2384 Real guess)
2385 : Convention(id, Type::BondYield),
2386 compoundingName_(compoundingName),
2387 frequencyName_(frequencyName),
2388 priceTypeName_(priceTypeName),
2389 accuracy_(accuracy),
2390 maxEvaluations_(maxEvaluations),
2391 guess_(guess) {
2392 build();
2393}
2394
2399}
2400
2402
2403 XMLUtils::checkNode(node, "BondYield");
2405 id_ = XMLUtils::getChildValue(node, "Id", true);
2406
2407 compoundingName_ = XMLUtils::getChildValue(node, "Compounding", true);
2408 frequencyName_ = XMLUtils::getChildValue(node, "Frequency", false, "Annual");
2409 priceTypeName_ = XMLUtils::getChildValue(node, "PriceType", false, "Clean");
2410 accuracy_ = XMLUtils::getChildValueAsDouble(node, "Accuracy", false, 1.0e-8);
2411 maxEvaluations_ = XMLUtils::getChildValueAsInt(node, "MaxEvaluations", false, 100);
2412 guess_ = XMLUtils::getChildValueAsDouble(node, "Guess", false, 0.05);
2413
2414 build();
2415}
2416
2418
2419 XMLNode* node = doc.allocNode("BondYield");
2420 XMLUtils::addChild(doc, node, "Id", id_);
2421 XMLUtils::addChild(doc, node, "Compounding", compoundingName_);
2422 XMLUtils::addChild(doc, node, "Frequency", frequencyName_);
2423 XMLUtils::addChild(doc, node, "PriceType", priceTypeName_);
2424 XMLUtils::addChild(doc, node, "Accuracy", accuracy_);
2425 XMLUtils::addChild(doc, node, "MaxEvaluations", Integer(maxEvaluations_));
2426 XMLUtils::addChild(doc, node, "Guess", guess_);
2427
2428 return node;
2429}
2430
2432 : revised_(false), frequency_(Monthly) {}
2433
2435 const string& id,
2436 const string& regionName,
2437 const string& regionCode,
2438 bool revised,
2439 const string& frequency,
2440 const string& availabilityLag,
2441 const string& currency)
2442 : Convention(id, Type::ZeroInflationIndex),
2443 regionName_(regionName),
2444 regionCode_(regionCode),
2445 revised_(revised),
2446 strFrequency_(frequency),
2447 strAvailabilityLag_(availabilityLag),
2448 strCurrency_(currency),
2449 frequency_(Monthly) {
2450 build();
2451}
2452
2454 return QuantLib::CustomRegion(regionName_, regionCode_);
2455}
2456
2461}
2462
2464
2465 XMLUtils::checkNode(node, "ZeroInflationIndex");
2467 id_ = XMLUtils::getChildValue(node, "Id", true);
2468
2469 regionName_ = XMLUtils::getChildValue(node, "RegionName", true);
2470 regionCode_ = XMLUtils::getChildValue(node, "RegionCode", true);
2471 revised_ = parseBool(XMLUtils::getChildValue(node, "Revised", true));
2472 strFrequency_ = XMLUtils::getChildValue(node, "Frequency", true);
2473 strAvailabilityLag_ = XMLUtils::getChildValue(node, "AvailabilityLag", true);
2474 strCurrency_ = XMLUtils::getChildValue(node, "Currency", true);
2475
2476 build();
2477}
2478
2480
2481 XMLNode* node = doc.allocNode("ZeroInflationIndex");
2482 XMLUtils::addChild(doc, node, "Id", id_);
2483 XMLUtils::addChild(doc, node, "RegionName", regionName_);
2484 XMLUtils::addChild(doc, node, "RegionCode", regionCode_);
2485 XMLUtils::addChild(doc, node, "Revised", revised_);
2486 XMLUtils::addChild(doc, node, "Frequency", strFrequency_);
2487 XMLUtils::addChild(doc, node, "AvailabilityLag", strAvailabilityLag_);
2488 XMLUtils::addChild(doc, node, "Currency", strCurrency_);
2489
2490 return node;
2491}
2492
2494 XMLUtils::checkNode(node, "Conventions");
2495
2496 for (XMLNode* child = XMLUtils::getChildNode(node); child; child = XMLUtils::getNextSibling(child)) {
2497
2498 string type = XMLUtils::getNodeName(child);
2499 QuantLib::ext::shared_ptr<Convention> convention;
2500
2501 /* we need to build conventions of type
2502
2503 - IborIndex
2504 - OvernightIndex
2505 - FX
2506
2507 immediately because
2508
2509 - for IborIndex other conventions depend on it via parseIborIndex() calls
2510 - the id of IborIndex convention is changed during build (period is normalized)
2511 - FX conventions are searched by currencies, not id */
2512
2513 if (type == "IborIndex") {
2514 convention = QuantLib::ext::make_shared<IborIndexConvention>();
2515 } else if (type == "FX") {
2516 convention = QuantLib::ext::make_shared<FXConvention>();
2517 } else if (type == "OvernightIndex") {
2518 convention = QuantLib::ext::make_shared<OvernightIndexConvention>();
2519 }
2520
2521 string id = "unknown";
2522 if (convention) {
2523 try {
2524 id = XMLUtils::getChildValue(child, "Id", true);
2525 DLOG("Building Convention " << id);
2526 convention->fromXML(child);
2527 add(convention);
2528 } catch (const std::exception& e) {
2529 WLOG("Exception parsing convention "
2530 << id << ": " << e.what() << ". This is only a problem if this convention is used later on.");
2531 }
2532 } else {
2533 try {
2534 id = XMLUtils::getChildValue(child, "Id", true);
2535 DLOG("Reading Convention " << id);
2536 unparsed_[id] = std::make_pair(type, XMLUtils::toString(child));
2537 } catch (const std::exception& e) {
2538 WLOG("Exception during retrieval of convention "
2539 << id << ": " << e.what() << ". This is only a problem if this convention is used later on.");
2540 }
2541 }
2542 }
2543}
2544
2546 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2547
2548 XMLNode* conventionsNode = doc.allocNode("Conventions");
2549
2550 map<string, QuantLib::ext::shared_ptr<Convention>>::const_iterator it;
2551 for (it = data_.begin(); it != data_.end(); ++it) {
2552 if (used_.find(it->first) != used_.end())
2553 XMLUtils::appendNode(conventionsNode, it->second->toXML(doc));
2554 }
2555 return conventionsNode;
2556}
2557
2559 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2560 data_.clear();
2561}
2562
2563namespace {
2564std::string flip(const std::string& id, const std::string& sep = "-") {
2565 boost::tokenizer<boost::escaped_list_separator<char>> tokenSplit(
2566 id, boost::escaped_list_separator<char>("\\", sep, "\""));
2567 std::vector<std::string> tokens(tokenSplit.begin(), tokenSplit.end());
2568
2569 bool eligible = false;
2570 for (auto const& t : tokens) {
2571 eligible = eligible || (t == "XCCY" || t == "FX" || t == "FXOPTION");
2572 }
2573
2574 if (eligible && (tokens.size() > 2 && tokens[0].size() == 3 && tokens[1].size() == 3)) {
2575 std::string id2 = tokens[1] + sep + tokens[0];
2576 for (Size i = 2; i < tokens.size(); ++i)
2577 id2 += sep + tokens[i];
2578 return id2;
2579 }
2580
2581 return id;
2582}
2583}
2584
2585QuantLib::ext::shared_ptr<Convention> Conventions::get(const string& id) const {
2586
2587 {
2588 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2589 if (auto it = data_.find(id); it != data_.end()) {
2590 used_.insert(id);
2591 return it->second;
2592 }
2593 if (auto it = data_.find(flip(id)); it != data_.end()) {
2594 used_.insert(flip(id));
2595 return it->second;
2596 }
2597 }
2598
2599 std::string type, unparsed;
2600 {
2601 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2602 if (auto it = unparsed_.find(id); it != unparsed_.end()) {
2603 std::tie(type, unparsed) = it->second;
2604 unparsed_.erase(id);
2605 } else if (auto it = unparsed_.find(flip(id)); it != unparsed_.end()) {
2606 std::tie(type, unparsed) = it->second;
2607 unparsed_.erase(flip(id));
2608 }
2609 }
2610
2611 if (unparsed.empty()) {
2612 QL_FAIL("Convention '" << id << "' not found.");
2613 }
2614
2615 QuantLib::ext::shared_ptr<Convention> convention;
2616 if (type == "Zero") {
2617 convention = QuantLib::ext::make_shared<ZeroRateConvention>();
2618 } else if (type == "Deposit") {
2619 convention = QuantLib::ext::make_shared<DepositConvention>();
2620 } else if (type == "Future") {
2621 convention = QuantLib::ext::make_shared<FutureConvention>();
2622 } else if (type == "FRA") {
2623 convention = QuantLib::ext::make_shared<FraConvention>();
2624 } else if (type == "OIS") {
2625 convention = QuantLib::ext::make_shared<OisConvention>();
2626 } else if (type == "Swap") {
2627 convention = QuantLib::ext::make_shared<IRSwapConvention>();
2628 } else if (type == "AverageOIS") {
2629 convention = QuantLib::ext::make_shared<AverageOisConvention>();
2630 } else if (type == "TenorBasisSwap") {
2631 convention = QuantLib::ext::make_shared<TenorBasisSwapConvention>();
2632 } else if (type == "TenorBasisTwoSwap") {
2633 convention=QuantLib::ext::make_shared<TenorBasisTwoSwapConvention>();
2634 } else if (type == "BMABasisSwap") {
2635 convention = QuantLib::ext::make_shared<BMABasisSwapConvention>();
2636 } else if (type == "CrossCurrencyBasis") {
2637 convention=QuantLib::ext::make_shared<CrossCcyBasisSwapConvention>();
2638 } else if (type == "CrossCurrencyFixFloat") {
2639 convention=QuantLib::ext::make_shared<CrossCcyFixFloatSwapConvention>();
2640 } else if (type == "CDS") {
2641 convention=QuantLib::ext::make_shared<CdsConvention>();
2642 } else if (type == "SwapIndex") {
2643 convention=QuantLib::ext::make_shared<SwapIndexConvention>();
2644 } else if (type == "InflationSwap") {
2645 convention=QuantLib::ext::make_shared<InflationSwapConvention>();
2646 } else if (type == "CmsSpreadOption") {
2647 convention=QuantLib::ext::make_shared<CmsSpreadOptionConvention>();
2648 } else if (type == "CommodityForward") {
2649 convention = QuantLib::ext::make_shared<CommodityForwardConvention>();
2650 } else if (type == "CommodityFuture") {
2651 convention = QuantLib::ext::make_shared<CommodityFutureConvention>();
2652 } else if (type == "FxOption") {
2653 convention = QuantLib::ext::make_shared<FxOptionConvention>();
2654 } else if (type == "ZeroInflationIndex") {
2655 convention = QuantLib::ext::make_shared<ZeroInflationIndexConvention>();
2656 } else if (type == "BondYield") {
2657 convention = QuantLib::ext::make_shared<BondYieldConvention>();
2658 } else {
2659 QL_FAIL("Convention '" << id << "' has unknown type '" + type + "' not recognized.");
2660 }
2661
2662 try {
2663 DLOG("Building Convention " << id);
2664 convention->fromXMLString(unparsed);
2665 add(convention);
2666 used_.insert(id);
2667 } catch (exception& e) {
2668 WLOG("Convention '" << id << "' could not be built: " << e.what());
2669 QL_FAIL("Convention '" << id << "' could not be built: " << e.what());
2670 }
2671
2672 return convention;
2673}
2674
2675QuantLib::ext::shared_ptr<Convention> Conventions::getFxConvention(const string& ccy1, const string& ccy2) const {
2676 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2677 for (auto c : data_) {
2678 auto fxCon = QuantLib::ext::dynamic_pointer_cast<FXConvention>(c.second);
2679 if (fxCon) {
2680 string source = fxCon->sourceCurrency().code();
2681 string target = fxCon->targetCurrency().code();
2682 if ((source == ccy1 && target == ccy2) || (target == ccy1 && source == ccy2)) {
2683 used_.insert(c.first);
2684 return fxCon;
2685 }
2686 }
2687 }
2688 QL_FAIL("FX convention for ccys '" << ccy1 << "' and '" << ccy2 << "' not found.");
2689}
2690
2691pair<bool, QuantLib::ext::shared_ptr<Convention>> Conventions::get(const string& id, const Convention::Type& type) const {
2692 try {
2693 auto c = get(id);
2694 if (c->type() == type) {
2695 used_.insert(id);
2696 return std::make_pair(true, c);
2697 }
2698 } catch (const std::exception& e) {
2699 }
2700 return make_pair(false, nullptr);
2701}
2702
2703std::set<QuantLib::ext::shared_ptr<Convention>> Conventions::get(const Convention::Type& type) const {
2704 std::set<QuantLib::ext::shared_ptr<Convention>> result;
2705 std::set<std::string> unparsedIds;
2706 std::string typeStr = ore::data::to_string(type);
2707 {
2708 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2709 for (auto const& d : data_) {
2710 if (d.second->type() == type) {
2711 used_.insert(d.first);
2712 result.insert(d.second);
2713 }
2714 }
2715 for (auto const& u : unparsed_) {
2716 if (u.second.first == typeStr)
2717 unparsedIds.insert(u.first);
2718 }
2719 }
2720 for (auto const& id : unparsedIds) {
2721 result.insert(get(id));
2722 }
2723 return result;
2724}
2725
2726bool Conventions::has(const string& id) const {
2727 try {
2728 get(id);
2729 } catch (const std::exception& e) {
2730 return false;
2731 }
2732 boost::shared_lock<boost::shared_mutex> lock(mutex_);
2733 return data_.find(id) != data_.end() || unparsed_.find(id) != unparsed_.end() ||
2734 data_.find(flip(id)) != data_.end() || unparsed_.find(flip(id)) != unparsed_.end();
2735}
2736
2737bool Conventions::has(const std::string& id, const Convention::Type& type) const {
2738 return get(id, type).first;
2739}
2740
2741void Conventions::add(const QuantLib::ext::shared_ptr<Convention>& convention) const {
2742 boost::unique_lock<boost::shared_mutex> lock(mutex_);
2743 const string& id = convention->id();
2744 QL_REQUIRE(data_.find(id) == data_.end(), "Convention already exists for id " << id);
2745 data_[id] = convention;
2746}
2747
2748std::ostream& operator<<(std::ostream& out, Convention::Type type) {
2749 switch (type) {
2751 return out << "Zero";
2753 return out << "Deposit";
2755 return out << "Future";
2757 return out << "FRA";
2759 return out << "OIS";
2761 return out << "Swap";
2763 return out << "AverageOIS";
2765 return out << "TenorBasisSwap";
2767 return out << "TenorBasisTwoSwap";
2769 return out << "BMABasisSwap";
2771 return out << "FX";
2773 return out << "CrossCcyBasis";
2775 return out << "CrossCcyFixFloat";
2777 return out << "CDS";
2779 return out << "IborIndex";
2781 return out << "OvernightIndex";
2783 return out << "SwapIndex";
2785 return out << "ZeroInflationIndex";
2787 return out << "InflationSwap";
2789 return out << "SecuritySpread";
2791 return out << "CMSSpreadOption";
2793 return out << "CommodityForward";
2795 return out << "CommodityFuture";
2797 return out << "FxOption";
2799 return out << "BondYield";
2800 default:
2801 return out << "unknown convention type (" << static_cast<int>(type) << ")";
2802 }
2803}
2804
2805} // namespace data
2806} // namespace ore
BusinessDayConvention fixedConvention_
AverageOisConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
QuantLib::ext::shared_ptr< OvernightIndex > index() const
BusinessDayConvention fixedPaymentConvention_
BMABasisSwapConvention()
Default constructor.
QuantLib::ext::shared_ptr< QuantExt::BMAIndexWrapper > bmaIndex() const
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
QuantLib::ext::shared_ptr< IborIndex > liborIndex() const
Serializable Bond.
Definition: bond.hpp:153
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
QuantLib::Bond::Price::Type priceType_
virtual void fromXML(XMLNode *node0) override
virtual XMLNode * toXML(XMLDocument &doc) const override
DateGeneration::Rule rule_
virtual void build() override
BusinessDayConvention paymentConvention_
CdsConvention()
Default constructor.
CmsSpreadOptionConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
BusinessDayConvention rollConvention_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
CommodityForwardConvention()
Default constructor.
const QuantLib::Calendar & pricingCalendar() const
bool empty() const
Returns true if the data has not been populated.
void fromXML(XMLNode *node) override
Serialisation.
CalculationPeriod
Indicate location of calculation period relative to the future expiry date.
XMLNode * toXML(XMLDocument &doc) const override
Class to store conventions for creating an off peak power index.
XMLNode * toXML(XMLDocument &doc) const override
Class to hold prohibited expiry information.
QuantLib::BusinessDayConvention optionBdc() const
QuantLib::BusinessDayConvention futureBdc() const
XMLNode * toXML(XMLDocument &doc) const override
boost::optional< OffPeakPowerIndexData > offPeakPowerIndexData_
std::string optionUnderlyingFutureConvention_
Option Underlying Future convention.
QuantLib::BusinessDayConvention optionBdc_
std::map< QuantLib::Natural, QuantLib::Natural > futureContinuationMappings_
Frequency parseAndValidateFrequency(const std::string &strFrequency)
Populate and check frequency.
void fromXML(XMLNode *node) override
Serialisation.
std::set< ProhibitedExpiry > prohibitedExpiries_
XMLNode * toXML(XMLDocument &doc) const override
void build() override
Implementation.
std::map< QuantLib::Natural, QuantLib::Natural > optionContinuationMappings_
std::set< QuantLib::Month > validContractMonths_
QuantLib::BusinessDayConvention bdc_
QuantLib::Frequency optionContractFrequency_
CommodityFutureConvention()
Default constructor.
bool validateBdc(const ProhibitedExpiry &pe) const
Validate the business day conventions in the ProhibitedExpiry.
Abstract base class for convention objects.
Definition: conventions.hpp:55
Type
Supported convention types.
Definition: conventions.hpp:58
Repository for currency dependent market conventions.
bool has(const std::string &id) const
Checks if we have a convention with the given id.
QuantLib::ext::shared_ptr< Convention > get(const string &id) const
map< string, QuantLib::ext::shared_ptr< Convention > > data_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
std::set< string > used_
map< string, std::pair< string, string > > unparsed_
boost::shared_mutex mutex_
QuantLib::ext::shared_ptr< Convention > getFxConvention(const string &ccy1, const string &ccy2) const
void add(const QuantLib::ext::shared_ptr< Convention > &convention) const
boost::optional< bool > flatIncludeSpread_
QuantLib::ext::shared_ptr< IborIndex > spreadIndex() const
boost::optional< QuantLib::Size > fixingDays_
QuantLib::ext::shared_ptr< IborIndex > flatIndex() const
boost::optional< QuantLib::Size > flatFixingDays_
boost::optional< QuantLib::Period > lookback_
boost::optional< bool > isAveraged_
CrossCcyBasisSwapConvention()
Default constructor.
boost::optional< Size > flatRateCutoff_
boost::optional< Size > rateCutoff_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
boost::optional< QuantLib::Period > flatLookback_
boost::optional< bool > includeSpread_
boost::optional< bool > flatIsAveraged_
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< QuantLib::IborIndex > index() const
QuantLib::BusinessDayConvention settlementConvention_
QuantLib::BusinessDayConvention fixedConvention_
CrossCcyFixFloatSwapConvention()
Default constructor.
DepositConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
BusinessDayConvention convention_
virtual void build() override
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
BusinessDayConvention convention_
virtual void build() override
FXConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< IborIndex > index() const
FraConvention()
Default constructor.
Container for storing Money Market Futures conventions.
QuantLib::RateAveraging::Type overnightIndexFutureNettingType_
FutureConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
Serialisation.
virtual XMLNode * toXML(XMLDocument &doc) const override
DateGenerationRule dateGenerationRule_
QuantLib::ext::shared_ptr< IborIndex > index() const
DeltaVolQuote::AtmType atmType_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
DeltaVolQuote::AtmType longTermAtmType_
DeltaVolQuote::DeltaType deltaType_
DeltaVolQuote::DeltaType longTermDeltaType_
QuantLib::Option::Type riskReversalInFavorOf_
Serializable FX Option.
Definition: fxoption.hpp:38
BusinessDayConvention fixedConvention_
IRSwapConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
QuantLib::ext::shared_ptr< IborIndex > index() const
SubPeriodsCoupon1::Type subPeriodsCouponType_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
QuantLib::ext::shared_ptr< ScheduleData > publicationScheduleData_
BusinessDayConvention infConvention_
QuantLib::ext::shared_ptr< ZeroInflationIndex > index() const
virtual void fromXML(XMLNode *node) override
QuantLib::ext::shared_ptr< ZeroInflationIndex > index_
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
PublicationRoll
Rule for determining when inflation swaps roll to observing latest inflation index release.
BusinessDayConvention fixConvention_
Serializable Cross Currency Swap contract.
const QuantLib::ext::shared_ptr< ore::data::Conventions > & conventions(QuantLib::Date d=QuantLib::Date()) const
Definition: conventions.cpp:72
std::map< QuantLib::Date, QuantLib::ext::shared_ptr< ore::data::Conventions > > conventions_
void setConventions(const QuantLib::ext::shared_ptr< ore::data::Conventions > &conventions, QuantLib::Date d=QuantLib::Date())
Definition: conventions.cpp:92
BusinessDayConvention fixedConvention_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
DateGeneration::Rule rule_
virtual void build() override
QuantLib::Calendar paymentCal_
QuantLib::ext::shared_ptr< OvernightIndex > index() const
OisConvention()
Default constructor.
BusinessDayConvention fixedPaymentConvention_
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
SecuritySpreadConvention()
Default constructor.
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
BusinessDayConvention rollConvention_
Serializable Swap, Single and Cross Currency.
Definition: swap.hpp:36
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void fromXML(XMLNode *node) override
virtual XMLNode * toXML(XMLDocument &doc) const override
QuantLib::ext::shared_ptr< IborIndex > receiveIndex() const
virtual void build() override
QuantLib::ext::shared_ptr< IborIndex > payIndex() const
TenorBasisSwapConvention()
Default constructor.
SubPeriodsCoupon1::Type subPeriodsCouponType_
BusinessDayConvention longFixedConvention_
virtual void fromXML(XMLNode *node) override
BusinessDayConvention shortFixedConvention_
virtual XMLNode * toXML(XMLDocument &doc) const override
TenorBasisTwoSwapConvention()
Default constructor.
QuantLib::ext::shared_ptr< IborIndex > shortIndex() const
QuantLib::ext::shared_ptr< IborIndex > longIndex() const
Small XML Document wrapper class.
Definition: xmlutils.hpp:65
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
Definition: xmlutils.cpp:412
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
Definition: xmlutils.cpp:291
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
Definition: xmlutils.cpp:478
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static string toString(XMLNode *node)
Write a node out as a string.
Definition: xmlutils.cpp:714
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
void fromXML(XMLNode *node) override
XMLNode * toXML(XMLDocument &doc) const override
virtual void fromXML(XMLNode *node) override
ZeroRateConvention()
Default constructor.
virtual XMLNode * toXML(XMLDocument &doc) const override
virtual void build() override
BusinessDayConvention rollConvention_
Currency and instrument specific conventions/defaults.
QuantLib::ext::shared_ptr< ZeroInflationIndex > parseZeroInflationIndex(const string &s, const Handle< ZeroInflationTermStructure > &h)
Convert std::string to QuantLib::ZeroInflationIndex.
DateGeneration::Rule parseDateGenerationRule(const string &s)
Convert text to QuantLib::DateGeneration::Rule.
Definition: parsers.cpp:328
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Definition: parsers.cpp:157
Month parseMonth(const string &s)
Definition: parsers.cpp:613
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
BusinessDayConvention parseBusinessDayConvention(const string &s)
Convert text to QuantLib::BusinessDayConvention.
Definition: parsers.cpp:173
Period parsePeriod(const string &s)
Convert text to QuantLib::Period.
Definition: parsers.cpp:171
Frequency parseFrequency(const string &s)
Convert text to QuantLib::Frequency.
Definition: parsers.cpp:348
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
QuantLib::Bond::Price::Type parseBondPriceType(const string &s)
Convert text to QuantLib::Bond::Price::Type.
Definition: parsers.cpp:392
Compounding parseCompounding(const string &s)
Convert text to QuantLib::Compounding;.
Definition: parsers.cpp:376
Weekday parseWeekday(const string &s)
Definition: parsers.cpp:599
DeltaVolQuote::AtmType parseAtmType(const std::string &s)
Convert text to QuantLib::DeltaVolQuote::AtmType.
Definition: parsers.cpp:746
Real parseReal(const string &s)
Convert text to Real.
Definition: parsers.cpp:112
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
DayCounter parseDayCounter(const string &s)
Convert text to QuantLib::DayCounter.
Definition: parsers.cpp:209
Option::Type parseOptionType(const std::string &s)
Convert text to QuantLib::Option::Type.
Definition: parsers.cpp:481
DeltaVolQuote::DeltaType parseDeltaType(const std::string &s)
Convert text to QuantLib::DeltaVolQuote::DeltaType.
Definition: parsers.cpp:763
Map text representations to QuantLib/QuantExt types.
Classes and functions for log message handling.
@ data
Definition: log.hpp:77
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Calendar calendar
Definition: utilities.cpp:441
bool operator<(const Dividend &d1, const Dividend &d2)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
ADCP parseAveragingDataPeriod(const string &s)
Convert text to CommodityFutureConvention::AveragingData::CalculationPeriod.
Definition: parsers.cpp:1136
FutureConvention::DateGenerationRule parseFutureDateGenerationRule(const std::string &s)
Convert text to FutureConvention::DateGeneration.
Definition: parsers.cpp:991
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
InflationSwapConvention::PublicationRoll parseInflationSwapPublicationRoll(const string &s)
Convert text to InflationSwapConvention::PublicationRoll.
Definition: parsers.cpp:1012
QuantLib::RateAveraging::Type parseOvernightIndexFutureNettingType(const std::string &s)
Convert text to QuantLib::RateAveraging::Type.
Definition: parsers.cpp:970
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.
Classes to differentiate constructors below.
string conversion utilities
string name
XML utility functions.