Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
parametricsmileconfiguration.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2024 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
28 XMLUtils::checkNode(node, "Parameter");
29 name = XMLUtils::getChildValue(node, "Name", true);
30 initialValue = parseListOfValues<Real>(XMLUtils::getChildValue(node, "InitialValue", true), parseReal);
31 isFixed = parseBool(XMLUtils::getChildValue(node, "IsFixed", true));
32}
33
35 XMLNode* n = doc.allocNode("Parameter");
36 XMLUtils::addChild(doc, n, "Name", name);
37 XMLUtils::addChild(doc, n, "InitialValue", initialValue);
38 XMLUtils::addChild(doc, n, "IsFixed", isFixed);
39 return n;
40}
41
43 XMLUtils::checkNode(node, "Calibration");
44 maxCalibrationAttempts = parseInteger(XMLUtils::getChildValue(node, "MaxCalibrationAttempts", true));
45 exitEarlyErrorThreshold = parseReal(XMLUtils::getChildValue(node, "ExitEarlyErrorThreshold", true));
46 maxAcceptableError = parseReal(XMLUtils::getChildValue(node, "MaxAcceptableError", true));
47}
48
50 XMLNode* n = doc.allocNode("Calibration");
51 XMLUtils::addChild(doc, n, "MaxCalibrationAttempts", (Integer)maxCalibrationAttempts);
52 XMLUtils::addChild(doc, n, "ExitEarlyErrorThreshold", exitEarlyErrorThreshold);
53 XMLUtils::addChild(doc, n, "MaxAcceptableError", maxAcceptableError);
54 return n;
55}
56
58 : parameters_(std::move(parameters)), calibration_(std::move(calibration)) {}
59
61
62 XMLUtils::checkNode(node, "ParametricSmileConfiguration");
63
64 parameters_.clear();
65
66 if (XMLNode* n = XMLUtils::getChildNode(node, "Parameters")) {
67 for (auto m : XMLUtils::getChildrenNodes(n, "Parameter")) {
69 p.fromXML(m);
70 parameters_.push_back(p);
71 }
72 }
73
74 if (XMLNode* n = XMLUtils::getChildNode(node, "Calibration")) {
76 }
77}
78
80
81 XMLNode* node = doc.allocNode("ParametricSmileConfiguration");
82
83 XMLNode* m = XMLUtils::addChild(doc, node, "Parameters");
84 for (auto const& p : parameters_) {
85 XMLUtils::appendNode(m, p.toXML(doc));
86 }
87
89
90 return node;
91}
92
94 auto p =
95 std::find_if(parameters_.begin(), parameters_.end(), [&name](const Parameter& p) { return p.name == name; });
96 QL_REQUIRE(p != parameters_.end(), "ParametricSmileConfiguration: parameter '" << name << "' is not present.");
97 return *p;
98}
99
101 return calibration_;
102}
103
104} // namespace data
105} // namespace ore
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
void fromXML(ore::data::XMLNode *node) override
const Parameter & parameter(const std::string &name) const
ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
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 vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
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
Class for holding parametric smile configurations.
Map text representations to QuantLib/QuantExt types.
string name