Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BasicReferenceDataManager Class Reference

Basic Concrete impl that loads an big XML and keeps data in memory. More...

#include <ored/portfolio/referencedata.hpp>

+ Inheritance diagram for BasicReferenceDataManager:
+ Collaboration diagram for BasicReferenceDataManager:

Public Member Functions

 BasicReferenceDataManager ()
 
 BasicReferenceDataManager (const string &filename)
 
void appendData (const string &filename)
 
QuantLib::ext::shared_ptr< ReferenceDatumbuildReferenceDatum (const string &refDataType)
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void clear ()
 
bool hasData (const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >()) override
 
QuantLib::ext::shared_ptr< ReferenceDatumgetData (const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >()) override
 
void add (const QuantLib::ext::shared_ptr< ReferenceDatum > &referenceDatum) override
 
QuantLib::ext::shared_ptr< ReferenceDatumaddFromXMLNode (XMLNode *node, const std::string &id=std::string(), const QuantLib::Date &validFrom=QuantLib::Null< QuantLib::Date >())
 
- Public Member Functions inherited from ReferenceDataManager
virtual ~ReferenceDataManager ()
 
virtual bool hasData (const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >())=0
 
virtual QuantLib::ext::shared_ptr< ReferenceDatumgetData (const string &type, const string &id, const QuantLib::Date &asof=QuantLib::Null< QuantLib::Date >())=0
 
virtual void add (const QuantLib::ext::shared_ptr< ReferenceDatum > &referenceDatum)=0
 
- Public Member Functions inherited from XMLSerializable
virtual ~XMLSerializable ()
 
virtual void fromXML (XMLNode *node)=0
 
virtual XMLNodetoXML (XMLDocument &doc) const =0
 
void fromFile (const std::string &filename)
 
void toFile (const std::string &filename) const
 
void fromXMLString (const std::string &xml)
 Parse from XML string. More...
 
std::string toXMLString () const
 Parse from XML string. More...
 

Protected Member Functions

std::tuple< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > latestValidFrom (const string &type, const string &id, const QuantLib::Date &asof) const
 
void check (const string &type, const string &id, const QuantLib::Date &asof) const
 

Protected Attributes

map< std::pair< string, string >, std::map< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > > data_
 
std::set< std::tuple< string, string, QuantLib::Date > > duplicates_
 
map< std::pair< string, string >, std::map< QuantLib::Date, string > > buildErrors_
 

Detailed Description

Basic Concrete impl that loads an big XML and keeps data in memory.

Definition at line 560 of file referencedata.hpp.

Constructor & Destructor Documentation

◆ BasicReferenceDataManager() [1/2]

Definition at line 562 of file referencedata.hpp.

562{}

◆ BasicReferenceDataManager() [2/2]

BasicReferenceDataManager ( const string &  filename)

Definition at line 563 of file referencedata.hpp.

563{ fromFile(filename); }
void fromFile(const std::string &filename)
Definition: xmlutils.cpp:150
+ Here is the call graph for this function:

Member Function Documentation

◆ appendData()

void appendData ( const string &  filename)

Definition at line 566 of file referencedata.hpp.

566{ fromFile(filename); }
+ Here is the call graph for this function:

◆ buildReferenceDatum()

QuantLib::ext::shared_ptr< ReferenceDatum > buildReferenceDatum ( const string &  refDataType)

Definition at line 688 of file referencedata.cpp.

688 {
689 auto refData = ReferenceDatumFactory::instance().build(refDataType);
690 QL_REQUIRE(refData,
691 "Reference data type " << refDataType << " has not been registered with the reference data factory.");
692 return refData;
693}
+ Here is the caller graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 620 of file referencedata.cpp.

620 {
621 XMLUtils::checkNode(node, "ReferenceData");
622 for (XMLNode* child = XMLUtils::getChildNode(node, "ReferenceDatum"); child;
623 child = XMLUtils::getNextSibling(child, "ReferenceDatum")) {
624 addFromXMLNode(child);
625 }
626}
QuantLib::ext::shared_ptr< ReferenceDatum > addFromXMLNode(XMLNode *node, const std::string &id=std::string(), const QuantLib::Date &validFrom=QuantLib::Null< QuantLib::Date >())
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
Definition: xmlutils.cpp:484
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( ore::data::XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 695 of file referencedata.cpp.

695 {
696 XMLNode* node = doc.allocNode("ReferenceData");
697 for (const auto& kv : data_) {
698 for (const auto& [_, refData] : kv.second) {
699 XMLUtils::appendNode(node, refData->toXML(doc));
700 }
701 }
702 return node;
703}
map< std::pair< string, string >, std::map< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > > data_
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
Definition: xmlutils.cpp:132
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:

◆ clear()

void clear ( )

Definition at line 574 of file referencedata.hpp.

574{ data_.clear(); }

◆ hasData()

bool hasData ( const string &  type,
const string &  id,
const QuantLib::Date &  asof = QuantLib::Null<QuantLib::Date>() 
)
overridevirtual

Implements ReferenceDataManager.

Definition at line 732 of file referencedata.cpp.

732 {
733 Date asofDate = asof;
734 if (asofDate == QuantLib::Null<QuantLib::Date>()) {
735 asofDate = Settings::instance().evaluationDate();
736 }
737 auto [validFrom, refData] = latestValidFrom(type, id, asofDate);
738 check(type, id, validFrom);
739 return refData != nullptr;
740}
std::tuple< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > latestValidFrom(const string &type, const string &id, const QuantLib::Date &asof) const
+ Here is the call graph for this function:

◆ getData()

QuantLib::ext::shared_ptr< ReferenceDatum > getData ( const string &  type,
const string &  id,
const QuantLib::Date &  asof = QuantLib::Null<QuantLib::Date>() 
)
overridevirtual

Implements ReferenceDataManager.

Definition at line 742 of file referencedata.cpp.

743 {
744 Date asofDate = asof;
745 if (asofDate == QuantLib::Null<QuantLib::Date>()) {
746 asofDate = Settings::instance().evaluationDate();
747 }
748 auto [validFrom, refData] = latestValidFrom(type, id, asofDate);
749 check(type, id, validFrom);
750 QL_REQUIRE(refData != nullptr, "BasicReferenceDataManager::getData(): No Reference data for type='"
751 << type << "', id='" << id << "', asof='" << asof << "'");
752 return refData;
753}
+ Here is the call graph for this function:

◆ add()

void add ( const QuantLib::ext::shared_ptr< ReferenceDatum > &  referenceDatum)
overridevirtual

Implements ReferenceDataManager.

Definition at line 628 of file referencedata.cpp.

628 {
629 // Add reference datum, it is overwritten if it is already present.
630 data_[make_pair(rd->type(), rd->id())][rd->validFrom()] = rd;
631}

◆ addFromXMLNode()

QuantLib::ext::shared_ptr< ReferenceDatum > addFromXMLNode ( XMLNode node,
const std::string &  id = std::string(),
const QuantLib::Date &  validFrom = QuantLib::Null<QuantLib::Date>() 
)

Definition at line 633 of file referencedata.cpp.

634 {
635 string refDataType = XMLUtils::getChildValue(node, "Type", false);
636 QuantLib::ext::shared_ptr<ReferenceDatum> refData;
637
638 if (refDataType.empty()) {
639 ALOG("Found referenceDatum without Type - skipping");
640 return refData;
641 }
642
643 string id = inputId.empty() ? XMLUtils::getAttribute(node, "id") : inputId;
644
645 string validFromStr = XMLUtils::getAttribute(node, "validFrom");
646 QuantLib::Date validFrom;
647 if (validFromStr.empty()) {
648 validFrom = QuantLib::Date::minDate();
649 } else {
650 validFrom = ore::data::parseDate(validFromStr);
651 }
652
653 validFrom = inputValidFrom == QuantLib::Null<QuantLib::Date>() ? validFrom : inputValidFrom;
654
655 if (id.empty()) {
656 ALOG("Found referenceDatum without id - skipping");
657 return refData;
658 }
659
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 << "'");
665 return refData;
666 }
667 }
668
669 try {
670 refData = buildReferenceDatum(refDataType);
671 refData->fromXML(node);
672 // set the type and id at top level (is this needed?)
673 refData->setType(refDataType);
674 refData->setId(id);
675 refData->setValidFrom(validFrom);
676 data_[make_pair(refDataType, id)][validFrom] = refData;
677 TLOG("added referenceDatum for type='" << refDataType << "', id='" << id << "', validFrom='" << validFrom
678 << "'");
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());
683 }
684
685 return refData;
686}
map< std::pair< string, string >, std::map< QuantLib::Date, string > > buildErrors_
QuantLib::ext::shared_ptr< ReferenceDatum > buildReferenceDatum(const string &refDataType)
std::set< std::tuple< string, string, QuantLib::Date > > duplicates_
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544
#define TLOG(text)
Logging Macro (Level = Data)
Definition: log.hpp:556
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ latestValidFrom()

std::tuple< QuantLib::Date, QuantLib::ext::shared_ptr< ReferenceDatum > > latestValidFrom ( const string &  type,
const string &  id,
const QuantLib::Date &  asof 
) const
protected

Definition at line 705 of file referencedata.cpp.

706 {
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()) {
711 return *(--uB);
712 }
713 }
714 return {QuantLib::Date(), nullptr};
715}
+ Here is the caller graph for this function:

◆ check()

void check ( const string &  type,
const string &  id,
const QuantLib::Date &  asof 
) const
protected

Definition at line 717 of file referencedata.cpp.

717 {
718 auto key = make_tuple(type, id, validFrom);
719 if (duplicates_.find(key) != duplicates_.end())
720 ALOG("BasicReferenceDataManager: duplicate entries for type='" << type << "', id='" << id << "', validFrom='"
721 << validFrom << "'");
722 auto err = buildErrors_.find(make_pair(type, id));
723 if (err != buildErrors_.end()) {
724 for (const auto& [validFrom, error] : err->second) {
725 ALOG("BasicReferenceDataManager: Build error for type='" << type << "', id='" << id << "', validFrom='"
726 << validFrom << "': " << error);
727 }
728 }
729
730}
Real error
Definition: utilities.cpp:65

Member Data Documentation

◆ data_

map<std::pair<string, string>, std::map<QuantLib::Date, QuantLib::ext::shared_ptr<ReferenceDatum> > > data_
protected

Definition at line 589 of file referencedata.hpp.

◆ duplicates_

std::set<std::tuple<string, string, QuantLib::Date> > duplicates_
protected

Definition at line 590 of file referencedata.hpp.

◆ buildErrors_

map<std::pair<string, string>, std::map<QuantLib::Date, string> > buildErrors_
protected

Definition at line 591 of file referencedata.hpp.