Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bootstrapconfig.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
21
22using namespace QuantLib;
23
24namespace ore {
25namespace data {
26
27BootstrapConfig::BootstrapConfig(Real accuracy, Real globalAccuracy, bool dontThrow, Size maxAttempts, Real maxFactor,
28 Real minFactor, Size dontThrowSteps)
29 : accuracy_(accuracy), globalAccuracy_(globalAccuracy == Null<Real>() ? accuracy_ : globalAccuracy),
30 dontThrow_(dontThrow), maxAttempts_(maxAttempts), maxFactor_(maxFactor), minFactor_(minFactor),
31 dontThrowSteps_(dontThrowSteps) {}
32
34
35 XMLUtils::checkNode(node, "BootstrapConfig");
36
37 accuracy_ = 1e-12;
38 if (XMLNode* n = XMLUtils::getChildNode(node, "Accuracy")) {
40 QL_REQUIRE(accuracy_ > 0, "Accuracy (" << accuracy_ << ") must be a positive number");
41 }
42
44 if (XMLNode* n = XMLUtils::getChildNode(node, "GlobalAccuracy")) {
46 QL_REQUIRE(globalAccuracy_ > 0, "GlobalAccuracy (" << globalAccuracy_ << ") must be a positive number");
47 }
48
49 dontThrow_ = false;
50 if (XMLNode* n = XMLUtils::getChildNode(node, "DontThrow")) {
52 }
53
54 maxAttempts_ = 5;
55 if (XMLNode* n = XMLUtils::getChildNode(node, "MaxAttempts")) {
57 QL_REQUIRE(maxAttempts > 0, "MaxAttempts (" << maxAttempts << ") must be a positive integer");
58 maxAttempts_ = static_cast<Size>(maxAttempts);
59 }
60
61 maxFactor_ = 2.0;
62 if (XMLNode* n = XMLUtils::getChildNode(node, "MaxFactor")) {
64 }
65
66 minFactor_ = 2.0;
67 if (XMLNode* n = XMLUtils::getChildNode(node, "MinFactor")) {
69 }
70
71 dontThrowSteps_ = 10;
72 if (XMLNode* n = XMLUtils::getChildNode(node, "DontThrowSteps")) {
74 QL_REQUIRE(dontThrowSteps > 0, "DontThrowSteps (" << dontThrowSteps << ") must be a positive integer");
75 dontThrowSteps_ = static_cast<Size>(dontThrowSteps);
76 }
77}
78
80
81 XMLNode* node = doc.allocNode("BootstrapConfig");
82 XMLUtils::addChild(doc, node, "Accuracy", accuracy_);
83 XMLUtils::addChild(doc, node, "GlobalAccuracy", globalAccuracy_);
84 XMLUtils::addChild(doc, node, "DontThrow", dontThrow_);
85 XMLUtils::addChild(doc, node, "MaxAttempts", static_cast<int>(maxAttempts_));
86 XMLUtils::addChild(doc, node, "MaxFactor", maxFactor_);
87 XMLUtils::addChild(doc, node, "MinFactor", minFactor_);
88 XMLUtils::addChild(doc, node, "DontThrowSteps", static_cast<int>(dontThrowSteps_));
89
90 return node;
91}
92
93} // namespace data
94} // namespace ore
Class for holding bootstrap configurations.
QuantLib::Size dontThrowSteps() const
void fromXML(ore::data::XMLNode *node) override
BootstrapConfig(QuantLib::Real accuracy=1.0e-12, QuantLib::Real globalAccuracy=QuantLib::Null< QuantLib::Real >(), bool dontThrow=false, QuantLib::Size maxAttempts=5, QuantLib::Real maxFactor=2.0, QuantLib::Real minFactor=2.0, QuantLib::Size dontThrowSteps=10)
Constructor.
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::Size maxAttempts() 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 checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
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 XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
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
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23
Map text representations to QuantLib/QuantExt types.