@@ -47,6 +47,7 @@ void addMinimalCurves(const char* nodeName, const map<string, QuantLib::ext::sha
4747
4848void 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
156160void 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
161165bool 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
166171const 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+
786808void 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
0 commit comments