Skip to content

Commit 006d28a

Browse files
committed
Merge branch 'feature/QPR-13651_output' into 'master'
QPR-13651 Overrides for curve config, conventions and reference data Closes QPR-13651 See merge request qs/oreplus!3104
2 parents b3c608e + 56b97b5 commit 006d28a

11 files changed

Lines changed: 121 additions & 22 deletions

File tree

OREAnalytics/orea/app/inputparameters.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,26 @@ vector<string> getFileNames(const string& fileString, const std::filesystem::pat
6767
InputParameters::InputParameters() {
6868
iborFallbackConfig_ = QuantLib::ext::make_shared<IborFallbackConfig>(IborFallbackConfig::defaultConfig());
6969
simmBucketMapper_ = QuantLib::ext::make_shared<SimmBucketMapperBase>();
70-
loadParameters();
70+
}
71+
72+
void InputParameters::loadParameters() {
73+
74+
// load Override parameters
75+
QuantLib::ext::shared_ptr<CurveConfigurations> ccOverride;
76+
loadParameterXML<CurveConfigurations>(ccOverride, "setup", "curveConfigOverride");
77+
if (ccOverride)
78+
curveConfigs_.setOverride(ccOverride);
79+
80+
QuantLib::ext::shared_ptr<Conventions> conventionsOverride;
81+
loadParameterXML<Conventions>(conventionsOverride, "setup", "conventionsOverride");
82+
if (conventions_ && conventionsOverride)
83+
conventions_->setConventionsOverride(conventionsOverride);
84+
85+
QuantLib::ext::shared_ptr<BasicReferenceDataManager> rdmOverride;
86+
loadParameterXML<BasicReferenceDataManager>(rdmOverride, "setup", "referenceDataOverride");
87+
if (refDataManager_ && rdmOverride)
88+
refDataManager_->setRDMOverride(rdmOverride);
89+
7190
}
7291

7392
bool checkString(const std::string& obj) { return true; }

OREAnalytics/orea/app/inputparameters.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class InputParameters {
8989
QuantLib::ext::shared_ptr<T>& obj, const std::string& analytic,
9090
const std::string& param, const bool mandatory = false) {
9191
string str = loadParameterXMLString(analytic, param, mandatory);
92+
if (str.empty() && !mandatory)
93+
return false;
9294
obj = QuantLib::ext::make_shared<T>();
9395
obj->fromXMLString(str);
9496
return true;
@@ -1072,7 +1074,7 @@ class InputParameters {
10721074
*************************************/
10731075
const std::set<std::string>& analytics() const { return analytics_; }
10741076

1075-
virtual void loadParameters(){}
1077+
virtual void loadParameters();
10761078
virtual void writeOutParameters(){}
10771079

10781080
protected:

OREAnalytics/orea/app/oreapp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ std::string OREAppInputParameters::loadParameterString(const std::string& analyt
640640
std::string OREAppInputParameters::loadParameterXMLString(const std::string& analytic, const std::string& param,
641641
bool mandatory) {
642642
string filename = loadParameterString(analytic, param, mandatory);
643+
if (filename.empty())
644+
return filename;
643645
filesystem::path filepath = inputPath_ / filename;
644646
XMLDocument doc(filepath.generic_string());
645647
return doc.toString();
@@ -3316,6 +3318,8 @@ void OREAppInputParameters::loadParameters() {
33163318
for (auto a : analytics())
33173319
LOG("analytic: " << a);
33183320

3321+
InputParameters::loadParameters();
3322+
33193323
LOG("buildInputParameters done");
33203324
}
33213325

OREData/ored/configuration/conventions.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,6 +2824,14 @@ QuantLib::ext::shared_ptr<Convention> Conventions::get(const string& id) const {
28242824
}
28252825
}
28262826

2827+
if (conventionsOverride_ && conventionsOverride_->has(id)) {
2828+
DLOG("Convention '" << id << "' found in override map.");
2829+
auto convention = conventionsOverride_->get(id);
2830+
add(convention);
2831+
used_.insert(id);
2832+
return convention;
2833+
}
2834+
28272835
std::string type, unparsed;
28282836
{
28292837
boost::unique_lock<boost::shared_mutex> lock(mutex_);
@@ -2932,6 +2940,7 @@ pair<bool, QuantLib::ext::shared_ptr<Convention>> Conventions::get(const string&
29322940

29332941
std::set<QuantLib::ext::shared_ptr<Convention>> Conventions::get(const Convention::Type& type) const {
29342942
std::set<QuantLib::ext::shared_ptr<Convention>> result;
2943+
29352944
std::set<std::string> unparsedIds;
29362945
std::string typeStr = ore::data::to_string(type);
29372946
{
@@ -2950,6 +2959,7 @@ std::set<QuantLib::ext::shared_ptr<Convention>> Conventions::get(const Conventio
29502959
for (auto const& id : unparsedIds) {
29512960
result.insert(get(id));
29522961
}
2962+
29532963
return result;
29542964
}
29552965

OREData/ored/configuration/conventions.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ std::ostream& operator<<(std::ostream& out, Convention::Type type);
115115
class Conventions : public XMLSerializable {
116116
public:
117117
//! Default constructor
118-
Conventions() {}
118+
Conventions(const QuantLib::ext::shared_ptr<Conventions>& conventionsOverride = nullptr) {}
119+
120+
/*! add an override to the conventions */
121+
void setConventionsOverride(const QuantLib::ext::shared_ptr<Conventions>& conventionsOverride) {
122+
boost::unique_lock<boost::shared_mutex> lock(mutex_);
123+
conventionsOverride_ = conventionsOverride;
124+
}
119125

120126
/*! Returns the convention if found and throws if not */
121127
QuantLib::ext::shared_ptr<Convention> get(const string& id) const;
@@ -157,6 +163,7 @@ class Conventions : public XMLSerializable {
157163
mutable map<string, std::pair<string, string>> unparsed_;
158164
mutable std::set<string> used_;
159165
mutable boost::shared_mutex mutex_;
166+
QuantLib::ext::shared_ptr<Conventions> conventionsOverride_;
160167
};
161168

162169
//! Singleton to hold conventions

OREData/ored/configuration/curveconfigurations.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void addMinimalCurves(const char* nodeName, const map<string, QuantLib::ext::sha
4747

4848
void CurveConfigurations::addNodes(XMLDocument& doc, XMLNode* parent, const char* nodeName) const {
4949
const auto& ct = parseCurveConfigurationType(nodeName);
50+
5051
const auto& it = configs_.find(ct);
5152
if (it != configs_.end()) {
5253
XMLNode* node = doc.allocNode(nodeName);
@@ -142,15 +143,18 @@ void CurveConfigurations::parseNode(const CurveSpec::CurveType& type, const stri
142143
config->fromXMLString(itc->second);
143144
configs_[type][curveId] = config;
144145
unparsed_.at(type).erase(curveId);
145-
} catch (std::exception& ex) {
146+
}
147+
catch (std::exception& ex) {
146148
string err = "Curve config " + curveId + " under node '" + to_string(type) + "' was requested, but could not be parsed.";
147149
StructuredCurveErrorMessage(curveId, err, ex.what()).log();
148150
QL_FAIL(err);
149151
}
150-
} else
151-
QL_FAIL("Could not find curveId " << curveId << " of type " << type << " in unparsed curve configurations");
152-
} else
153-
QL_FAIL("Could not find CurveType " << type << " in unparsed curve configurations");
152+
}
153+
else
154+
QL_FAIL("Could not find curveId " << curveId << " of type " << type << " in unparsed curve configurations");
155+
}
156+
else
157+
QL_FAIL("Could not find CurveType " << type << " in unparsed curve configurations");
154158
}
155159

156160
void CurveConfigurations::add(const CurveSpec::CurveType& type, const string& curveId,
@@ -159,19 +163,30 @@ void CurveConfigurations::add(const CurveSpec::CurveType& type, const string& cu
159163
}
160164

161165
bool CurveConfigurations::has(const CurveSpec::CurveType& type, const string& curveId) const {
162-
return (configs_.count(type) > 0 && configs_.at(type).count(curveId) > 0) ||
163-
(unparsed_.count(type) > 0 && unparsed_.at(type).count(curveId) > 0);
166+
return (curveConfigOverride_ && curveConfigOverride_->has(type, curveId)) ||
167+
(configs_.count(type) > 0 && configs_.at(type).count(curveId) > 0) ||
168+
(unparsed_.count(type) > 0 && unparsed_.at(type).count(curveId) > 0);
164169
}
165170

166171
const QuantLib::ext::shared_ptr<CurveConfig>& CurveConfigurations::get(const CurveSpec::CurveType& type,
167-
const string& curveId) const {
172+
const string& curveId) const {
173+
168174
const auto& it = configs_.find(type);
169175
if (it != configs_.end()) {
170176
const auto& itc = it->second.find(curveId);
171177
if (itc != it->second.end()) {
172178
return itc->second;
173179
}
174180
}
181+
182+
// check if is in the overrides first, and then add to configs_ if so
183+
if (curveConfigOverride_ && curveConfigOverride_->has(type, curveId)) {
184+
auto cc = curveConfigOverride_->get(type, curveId);
185+
configs_[type][curveId] = cc;
186+
return configs_.at(type).at(curveId);
187+
}
188+
189+
// next check the unparsed configs
175190
parseNode(type, curveId);
176191
return configs_.at(type).at(curveId);
177192
}
@@ -783,7 +798,16 @@ void CurveConfigurations::addAdditionalCurveConfigs(const CurveConfigurations& c
783798
}
784799
}
785800

801+
void CurveConfigurationsManager::setOverride(const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigOverride) {
802+
override_ = curveConfigOverride;
803+
for (auto& it : configs_) {
804+
it.second->setCurveConfigOverride(override_);
805+
}
806+
}
807+
786808
void CurveConfigurationsManager::add(const QuantLib::ext::shared_ptr<CurveConfigurations>& config, std::string id) {
809+
if (override_)
810+
config->setCurveConfigOverride(override_);
787811
configs_[id] = config;
788812
}
789813

OREData/ored/configuration/curveconfigurations.hpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ class CurveConfigurations : public XMLSerializable {
6262
public:
6363
//! Default constructor
6464
CurveConfigurations(const QuantLib::ext::shared_ptr<ReferenceDataManager>& refDataManager = nullptr,
65-
const QuantLib::ext::shared_ptr<IborFallbackConfig>& iborFallbackConfig = nullptr)
66-
: refDataManager_(refDataManager), iborFallbackConfig_(iborFallbackConfig) {}
65+
const QuantLib::ext::shared_ptr<IborFallbackConfig>& iborFallbackConfig = nullptr,
66+
const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigOverride = nullptr)
67+
: refDataManager_(refDataManager), iborFallbackConfig_(iborFallbackConfig), curveConfigOverride_(curveConfigOverride) {}
6768

6869
//! \name Setters and Getters
6970
//@{
@@ -75,6 +76,10 @@ class CurveConfigurations : public XMLSerializable {
7576
const ReportConfig& reportConfigYieldCurves() const { return reportConfigYieldCurves_; }
7677
const ReportConfig& reportConfigInflationCapFloorVols() const { return reportConfigInflationCapFloorVols_; }
7778

79+
void setCurveConfigOverride(const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigOverride) {
80+
curveConfigOverride_ = curveConfigOverride;
81+
}
82+
7883
bool hasYieldCurveConfig(const std::string& curveID) const;
7984
QuantLib::ext::shared_ptr<YieldCurveConfig> yieldCurveConfig(const string& curveID) const;
8085

@@ -181,6 +186,7 @@ class CurveConfigurations : public XMLSerializable {
181186
private:
182187
QuantLib::ext::shared_ptr<ReferenceDataManager> refDataManager_;
183188
QuantLib::ext::shared_ptr<IborFallbackConfig> iborFallbackConfig_;
189+
QuantLib::ext::shared_ptr<CurveConfigurations> curveConfigOverride_;
184190

185191
ReportConfig reportConfigEqVols_;
186192
ReportConfig reportConfigFxVols_;
@@ -206,9 +212,10 @@ class CurveConfigurations : public XMLSerializable {
206212

207213
class CurveConfigurationsManager {
208214
public:
209-
CurveConfigurationsManager() {}
215+
CurveConfigurationsManager(const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigOverride = nullptr) : override_(curveConfigOverride) {}
210216

211217
// add a curve config, if no id provided it gets added as a default
218+
void setOverride(const QuantLib::ext::shared_ptr<CurveConfigurations>& curveConfigOverride);
212219
void add(const QuantLib::ext::shared_ptr<CurveConfigurations>& config, std::string id = std::string());
213220
const QuantLib::ext::shared_ptr<CurveConfigurations>& get(std::string id = std::string()) const;
214221
const bool has(std::string id = std::string()) const;
@@ -217,6 +224,7 @@ class CurveConfigurationsManager {
217224

218225
private:
219226
std::map<std::string, QuantLib::ext::shared_ptr<CurveConfigurations>> configs_;
227+
QuantLib::ext::shared_ptr<CurveConfigurations> override_;
220228
};
221229

222230
} // namespace data

OREData/ored/portfolio/referencedata.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,9 @@ void BasicReferenceDataManager::check(const string& type, const string& id, cons
797797
}
798798

799799
bool BasicReferenceDataManager::hasData(const string& type, const string& id, const QuantLib::Date& asof) {
800+
if (rdmOverride_ && rdmOverride_->hasData(type, id, asof))
801+
return true;
802+
800803
Date asofDate = asof;
801804
if (asofDate == QuantLib::Null<QuantLib::Date>()) {
802805
asofDate = Settings::instance().evaluationDate();
@@ -808,6 +811,10 @@ bool BasicReferenceDataManager::hasData(const string& type, const string& id, co
808811

809812
QuantLib::ext::shared_ptr<ReferenceDatum> BasicReferenceDataManager::getData(const string& type, const string& id,
810813
const QuantLib::Date& asof) {
814+
815+
if (rdmOverride_ && rdmOverride_->hasData(type, id, asof))
816+
return rdmOverride_->getData(type, id, asof);
817+
811818
Date asofDate = asof;
812819
if (asofDate == QuantLib::Null<QuantLib::Date>()) {
813820
asofDate = Settings::instance().evaluationDate();

OREData/ored/portfolio/referencedata.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,15 @@ class ReferenceDataManager {
605605
class BasicReferenceDataManager : public ReferenceDataManager, public XMLSerializable {
606606
public:
607607
BasicReferenceDataManager() {}
608-
BasicReferenceDataManager(const string& filename) { fromFile(filename); }
608+
BasicReferenceDataManager(const string& filename,
609+
const QuantLib::ext::shared_ptr<ReferenceDataManager>& rdmOverride = nullptr)
610+
: rdmOverride_(rdmOverride) {
611+
fromFile(filename);
612+
}
613+
614+
void setRDMOverride(const QuantLib::ext::shared_ptr<ReferenceDataManager>& rdmOverride) {
615+
rdmOverride_ = rdmOverride;
616+
}
609617

610618
// Load extra data and append to this manger
611619
void appendData(const string& filename) { fromFile(filename); }
@@ -634,6 +642,9 @@ class BasicReferenceDataManager : public ReferenceDataManager, public XMLSeriali
634642
map<std::pair<string, string>, std::map<QuantLib::Date, QuantLib::ext::shared_ptr<ReferenceDatum>>> data_;
635643
std::set<std::tuple<string, string, QuantLib::Date>> duplicates_;
636644
map<std::pair<string, string>, std::map<QuantLib::Date, string>> buildErrors_;
645+
646+
private:
647+
QuantLib::ext::shared_ptr<ReferenceDataManager> rdmOverride_;
637648
};
638649

639650
} // namespace data

OREData/ored/utilities/xmlutils.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ void handle_rapidxml_parse_error(const rapidxml::parse_error& e) {
7474
XMLDocument::XMLDocument() : _doc(new rapidxml::xml_document<char>()), _buffer(NULL) {}
7575

7676
XMLDocument::XMLDocument(const string& fileName) : _doc(new rapidxml::xml_document<char>()), _buffer(NULL) {
77+
fromFile(fileName);
78+
}
79+
80+
XMLDocument::~XMLDocument() {
81+
if (_buffer != NULL)
82+
delete[] _buffer;
83+
if (_doc != NULL)
84+
delete _doc;
85+
}
86+
87+
void XMLDocument::fromFile(const string& fileName) {
7788
// Need to load the entire file into memory to pass to doc.parse().
7889
ifstream t(fileName.c_str());
7990
QL_REQUIRE(t.is_open(), "Failed to open file " << fileName);
@@ -92,13 +103,6 @@ XMLDocument::XMLDocument(const string& fileName) : _doc(new rapidxml::xml_docume
92103
}
93104
}
94105

95-
XMLDocument::~XMLDocument() {
96-
if (_buffer != NULL)
97-
delete[] _buffer;
98-
if (_doc != NULL)
99-
delete _doc;
100-
}
101-
102106
void XMLDocument::fromXMLString(const string& xmlString) {
103107
QL_REQUIRE(!_buffer, "XML Document is already loaded");
104108
Size length = xmlString.size();

0 commit comments

Comments
 (0)