36 if (!dateStr.empty()) {
45 QL_REQUIRE(node,
"Failed to create ReferenceDatum node");
55 QL_REQUIRE(node,
"BondReferenceDatum::BondData::fromXML(): no node given");
71 while (legNode !=
nullptr) {
93 for (
auto& bd : legData)
112 : weight_(Null<Real>()), priorWeight_(Null<Real>()), recovery_(Null<Real>()) {}
115 const Date& auctionDate,
const Date& auctionSettlementDate,
const Date& defaultDate,
116 const Date& eventDeterminationDate)
117 : name_(
name), weight_(weight), priorWeight_(priorWeight), recovery_(recovery), auctionDate_(auctionDate),
118 auctionSettlementDate_(auctionSettlementDate), defaultDate_(defaultDate),
119 eventDeterminationDate_(eventDeterminationDate) {}
213 QL_REQUIRE(cird,
"Expected a CreditIndexReferenceData node.");
235 auto cNode = c.toXML(doc);
245 DLOG(
"Constituent " << c.
name() <<
" not added to credit index " <<
id() <<
" because already present.");
248 DLOG(
"Constituent " << c.
name() <<
" added to credit index " <<
id() <<
".");
258 QL_REQUIRE(innerNode,
"No " +
type() +
"ReferenceData node");
276 for (
auto d :
data_) {
311 QL_REQUIRE(innerNode,
"No " +
type() +
"ReferenceData node");
316 if (rebalancingStr ==
"EndOfMonth") {
319 QL_FAIL(
"unexpected rebalancing strategy " << rebalancingStr);
338 if (hedgeAdjStr ==
"None") {
340 }
else if (hedgeAdjStr ==
"Daily") {
343 QL_FAIL(
"unexpected rebalancing strategy " << hedgeAdjStr);
350 if (currencyWeightNode) {
351 double totalWeight = 0.0;
356 QL_REQUIRE(weight > 0 || QuantLib::close_enough(weight, 0.0),
357 "Try to add negtive weight for Underlying" <<
name);
359 totalWeight += weight;
361 QL_REQUIRE(
data_.empty() || QuantLib::close_enough(totalWeight, 1.0),
362 "Sum of underlying weights at last rebalancing date (" << totalWeight <<
") is not 1.0");
388 if (!
data_.empty()) {
390 for (
auto d :
data_) {
458 QL_REQUIRE(innerNode,
"No " +
type() +
"ReferenceData node");
462 QL_REQUIRE(componentsNode,
"No Components node");
467 for (
auto const n : c) {
472 id = std::to_string(k);
475 DLOG(
"Parsing composite trade " << this->
id() <<
" node " << k <<
" with id: " <<
id);
477 QuantLib::ext::shared_ptr<Trade> trade;
479 trade = TradeFactory::instance().build(tradeType);
483 componentEnvelope.
fromXML(envNode);
491 trade->setEnvelope(env);
494 DLOG(
"Added Trade " <<
id <<
" (" << trade->id() <<
")"
495 <<
" type:" << tradeType <<
" to composite trade " << this->id() <<
".");
497 }
catch (
const std::exception& e) {
500 "Failed to build subtrade with id '" +
id +
"' inside composite trade: ", e.what())
513 auto test = u->toXML(doc);
524 QL_REQUIRE(innerNode,
"No CreditReferenceData node");
562 QL_REQUIRE(innerNode,
"No EquityReferenceData node");
599 QL_REQUIRE(b,
"No BondBasketData node");
602 for (
auto const n : c) {
630 data_[make_pair(rd->type(), rd->id())][rd->validFrom()] = rd;
634 const QuantLib::Date& inputValidFrom) {
636 QuantLib::ext::shared_ptr<ReferenceDatum> refData;
638 if (refDataType.empty()) {
639 ALOG(
"Found referenceDatum without Type - skipping");
646 QuantLib::Date validFrom;
647 if (validFromStr.empty()) {
648 validFrom = QuantLib::Date::minDate();
653 validFrom = inputValidFrom == QuantLib::Null<QuantLib::Date>() ? validFrom : inputValidFrom;
656 ALOG(
"Found referenceDatum without id - skipping");
660 if (
auto it =
data_.find(make_pair(refDataType,
id)); it !=
data_.end()) {
661 if (it->second.count(validFrom) > 0) {
662 duplicates_.insert(make_tuple(refDataType,
id, validFrom));
663 ALOG(
"Found duplicate referenceDatum for type='" << refDataType <<
"', id='" <<
id <<
"', validFrom='"
664 << validFrom <<
"'");
671 refData->fromXML(node);
673 refData->setType(refDataType);
675 refData->setValidFrom(validFrom);
676 data_[make_pair(refDataType,
id)][validFrom] = refData;
677 TLOG(
"added referenceDatum for type='" << refDataType <<
"', id='" <<
id <<
"', validFrom='" << validFrom
679 }
catch (
const std::exception& e) {
680 buildErrors_[make_pair(refDataType,
id)][validFrom] = e.what();
681 ALOG(
"Error building referenceDatum for type='" << refDataType <<
"', id='" <<
id <<
"', validFrom='" << validFrom
682 <<
"': " << e.what());
689 auto refData = ReferenceDatumFactory::instance().build(refDataType);
691 "Reference data type " << refDataType <<
" has not been registered with the reference data factory.");
697 for (
const auto& kv :
data_) {
698 for (
const auto& [_, refData] : kv.second) {
706 const QuantLib::Date& asof)
const {
707 auto it =
data_.find(make_pair(type,
id));
708 if (it !=
data_.end() && !it->second.empty()){
709 auto uB = it->second.upper_bound(asof);
710 if (uB != it->second.begin()) {
714 return {QuantLib::Date(),
nullptr};
718 auto key = make_tuple(type,
id, validFrom);
720 ALOG(
"BasicReferenceDataManager: duplicate entries for type='" << type <<
"', id='" <<
id <<
"', validFrom='"
721 << validFrom <<
"'");
724 for (
const auto& [validFrom,
error] : err->second) {
725 ALOG(
"BasicReferenceDataManager: Build error for type='" << type <<
"', id='" <<
id <<
"', validFrom='"
726 << validFrom <<
"': " <<
error);
733 Date asofDate = asof;
734 if (asofDate == QuantLib::Null<QuantLib::Date>()) {
735 asofDate = Settings::instance().evaluationDate();
738 check(type,
id, validFrom);
739 return refData !=
nullptr;
743 const QuantLib::Date& asof) {
744 Date asofDate = asof;
745 if (asofDate == QuantLib::Null<QuantLib::Date>()) {
746 asofDate = Settings::instance().evaluationDate();
749 check(type,
id, validFrom);
750 QL_REQUIRE(refData !=
nullptr,
"BasicReferenceDataManager::getData(): No Reference data for type='"
751 << type <<
"', id='" <<
id <<
"', asof='" << asof <<
"'");
bool hasData(const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >()) override
map< std::pair< string, string >, std::map< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > > data_
map< std::pair< string, string >, std::map< QuantLib::Date, string > > buildErrors_
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::tuple< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > latestValidFrom(const string &type, const string &id, const QuantLib::Date &asof) const
QuantLib::ext::shared_ptr< ReferenceDatum > buildReferenceDatum(const string &refDataType)
void add(const QuantLib::ext::shared_ptr< ReferenceDatum > &referenceDatum) override
std::set< std::tuple< string, string, QuantLib::Date > > duplicates_
QuantLib::ext::shared_ptr< ReferenceDatum > getData(const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >()) override
void check(const string &type, const string &id, const QuantLib::Date &asof) const
QuantLib::ext::shared_ptr< ReferenceDatum > addFromXMLNode(XMLNode *node, const std::string &id=std::string(), const QuantLib::Date &validFrom=QuantLib::Null< QuantLib::Date >())
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::vector< BondUnderlying > underlyingData_
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::Date eventDeterminationDate_
QuantLib::Date auctionDate_
const QuantLib::Date & defaultDate() const
QuantLib::Real weight() const
const QuantLib::Date & eventDeterminationDate() const
QuantLib::Date defaultDate_
QuantLib::Real recovery() const
void fromXML(XMLNode *node) override
const QuantLib::Date & auctionDate() const
XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::Real priorWeight_
QuantLib::Real priorWeight() const
const QuantLib::Date & auctionSettlementDate() const
QuantLib::Date auctionSettlementDate_
const std::string & name() const
const std::set< CreditIndexConstituent > & constituents() const
Get all of the underlying constituents.
CreditIndexReferenceDatum()
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::set< CreditIndexConstituent > constituents_
void add(const CreditIndexConstituent &c)
Add a constituent. The constituent is not added if already present.
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
HedgeAdjustment::Rule hedgeAdjustmentRule_
QuantLib::Calendar hedgeCalendar_
std::string underlyingIndexName_
RebalancingDate::Strategy rebalancingStrategy_
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::map< std::string, std::string > fxIndexes_
map< string, double > data_
Serializable object holding generic trade data, reporting dimensions.
virtual void fromXML(XMLNode *node) override
void setAdditionalField(const std::string &key, const boost::any &value)
const map< string, boost::any > & fullAdditionalFields() const
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
std::map< std::string, double > data_
void fromXML(XMLNode *node) override
void addUnderlying(const string &name, double weight)
XMLNode * toXML(ore::data::XMLDocument &doc) const override
void log() const
generate Boost log record to pass to corresponding sinks
Serializable object holding leg data.
virtual void fromXML(XMLNode *node) override
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
vector< QuantLib::ext::shared_ptr< Trade > > tradecomponents_
Base class for reference data.
const std::string & id() const
const std::string & type() const
getters
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
QuantLib::Date validFrom_
Utility class for Structured Trade errors, contains the Trade ID and Type.
Small XML Document wrapper class.
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
static string getAttribute(XMLNode *node, const string &attrName)
static void checkNode(XMLNode *n, const string &expectedName)
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static string getNodeValue(XMLNode *node)
Get a node's value.
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static void appendNode(XMLNode *parent, XMLNode *child)
Calendar parseCalendar(const string &s)
Convert text to QuantLib::Calendar.
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Real parseReal(const string &s)
Convert text to Real.
leg data model and serialization
#define DLOG(text)
Logging Macro (Level = Debug)
#define ALOG(text)
Logging Macro (Level = Alert)
#define TLOG(text)
Logging Macro (Level = Data)
bool operator<(const Dividend &d1, const Dividend &d2)
std::string to_string(const LocationInfo &l)
Serializable Credit Default Swap.
Map text representations to QuantLib/QuantExt types.
Reference data model and serialization.
std::vector< LegData > legData
void fromXML(XMLNode *node) override
XMLNode * toXML(ore::data::XMLDocument &doc) const override
string priceQuoteBaseValue
QuantLib::Date successorImplementationDate
QuantLib::Date predecessorImplementationDate
std::string proxyIdentifier
QuantLib::Date equityStartDate
std::string proxyVolatilityId
QuantLib::Size scalingFactor
std::string crifQualifier
Structured Trade Error class.
string conversion utilities