Skip to content

Commit bce6d9a

Browse files
pcaspersjenkins
authored andcommitted
QPR-12325 add parametric smile config
1 parent 5889741 commit bce6d9a

3 files changed

Lines changed: 184 additions & 0 deletions

File tree

OREData/ored/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ configuration/iborfallbackconfig.cpp
1919
configuration/inflationcapfloorvolcurveconfig.cpp
2020
configuration/inflationcurveconfig.cpp
2121
configuration/onedimsolverconfig.cpp
22+
configuration/parametricsmileconfiguration.cpp
2223
configuration/reportconfig.cpp
2324
configuration/volatilityconfig.cpp
2425
configuration/yieldcurveconfig.cpp
@@ -399,6 +400,7 @@ configuration/iborfallbackconfig.hpp
399400
configuration/inflationcapfloorvolcurveconfig.hpp
400401
configuration/inflationcurveconfig.hpp
401402
configuration/onedimsolverconfig.hpp
403+
configuration/parametricsmileconfiguration.hpp
402404
configuration/reportconfig.hpp
403405
configuration/securityconfig.hpp
404406
configuration/swaptionvolcurveconfig.hpp
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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+
19+
#include <ored/configuration/parametricsmileconfiguration.hpp>
20+
#include <ored/utilities/parsers.hpp>
21+
22+
using namespace QuantLib;
23+
24+
namespace ore {
25+
namespace data {
26+
27+
void ParametricSmileConfiguration::Parameter::fromXML(XMLNode* node) {
28+
XMLUtils::checkNode(node, "Parameter");
29+
name = XMLUtils::getChildValue(node, "Name", true);
30+
initialValue = parseReal(XMLUtils::getChildValue(node, "InitialValue", true));
31+
isFixed = parseBool(XMLUtils::getChildValue(node, "IsFixed", true));
32+
}
33+
34+
XMLNode* ParametricSmileConfiguration::Parameter::toXML(XMLDocument& doc) const {
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+
42+
void ParametricSmileConfiguration::Calibration::fromXML(XMLNode* node) {
43+
XMLUtils::checkNode(node, "Calibration");
44+
maxCalibrationAttempts = parseInteger(XMLUtils::getChildValue(node, "MaxCalibrationAttempts", true));
45+
exitEarlyErrorThreshold = parseReal(XMLUtils::getChildValue(node, "ExitEarlyErrorThreshold", true));
46+
maxAcceptableError = parseBool(XMLUtils::getChildValue(node, "MaxAcceptableError", true));
47+
}
48+
49+
XMLNode* ParametricSmileConfiguration::Calibration::toXML(XMLDocument& doc) const {
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+
57+
ParametricSmileConfiguration::ParametricSmileConfiguration(std::vector<Parameter> parameters, Calibration calibration)
58+
: parameters_(std::move(parameters)), calibration_(std::move(calibration)) {}
59+
60+
void ParametricSmileConfiguration::fromXML(XMLNode* node) {
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")) {
68+
ParametricSmileConfiguration::Parameter p;
69+
p.fromXML(m);
70+
parameters_.push_back(p);
71+
}
72+
}
73+
74+
if (XMLNode* n = XMLUtils::getChildNode(node, "Calibration")) {
75+
calibration_.fromXML(n);
76+
}
77+
}
78+
79+
XMLNode* ParametricSmileConfiguration::toXML(XMLDocument& doc) const {
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+
88+
XMLUtils::appendNode(node, calibration_.toXML(doc));
89+
90+
return node;
91+
}
92+
93+
const ParametricSmileConfiguration::Parameter& ParametricSmileConfiguration::parameter(const std::string& name) const {
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->second;
98+
}
99+
100+
const ParametricSmileConfiguration::Calibration& ParametricSmileConfiguration::calibration() const {
101+
return calibration_;
102+
}
103+
104+
} // namespace data
105+
} // namespace ore
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
19+
/*! \file ored/configuration/parametricsmileconfiguration.hpp
20+
\brief Class for holding parametric smile configurations
21+
\ingroup configuration
22+
*/
23+
24+
#pragma once
25+
26+
#include <ored/utilities/xmlutils.hpp>
27+
#include <ql/utilities/null.hpp>
28+
29+
namespace ore {
30+
namespace data {
31+
32+
/*! Serializable parametric smile configuration
33+
\ingroup configuration
34+
*/
35+
class ParametricSmileConfiguration : public XMLSerializable {
36+
public:
37+
class Parameter : public XMLSerializable {
38+
public:
39+
void fromXML(ore::data::XMLNode* node) override;
40+
ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
41+
42+
std::string name;
43+
double initialValue;
44+
bool isFixed;
45+
};
46+
47+
class Calibration : public XMLSerializable {
48+
public:
49+
void fromXML(ore::data::XMLNode* node) override;
50+
ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
51+
52+
std::size_t maxCalibrationAttempts;
53+
double exitEarlyErrorThreshold;
54+
double maxAcceptableError;
55+
};
56+
57+
ParametricSmileConfiguration(std::vector<Parameter> parameters, Calibration calibration);
58+
59+
//! \name XMLSerializable interface
60+
//@{
61+
void fromXML(ore::data::XMLNode* node) override;
62+
ore::data::XMLNode* toXML(ore::data::XMLDocument& doc) const override;
63+
//@}
64+
65+
//! \name Inspectors
66+
//@{
67+
const Parameter& parameter(const std::string& name) const;
68+
const Calibration& calibration() const;
69+
//@}
70+
71+
private:
72+
std::vector<Parameter> parameters_;
73+
Calibration calibration_;
74+
};
75+
76+
} // namespace data
77+
} // namespace ore

0 commit comments

Comments
 (0)