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

#include <ored/portfolio/referencedata.hpp>

+ Inheritance diagram for PortfolioBasketReferenceDatum:
+ Collaboration diagram for PortfolioBasketReferenceDatum:

Public Member Functions

 PortfolioBasketReferenceDatum ()
 
 PortfolioBasketReferenceDatum (const string &id)
 
 PortfolioBasketReferenceDatum (const string &id, const QuantLib::Date &validFrom)
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
const vector< QuantLib::ext::shared_ptr< Trade > > & getTrades () const
 
- Public Member Functions inherited from ReferenceDatum
 ReferenceDatum ()
 Default Constructor. More...
 
 ReferenceDatum (const std::string &type, const std::string &id)
 Base class constructor. More...
 
 ReferenceDatum (const std::string &type, const std::string &id, const QuantLib::Date &validFrom)
 Base class constructor. More...
 
void setType (const string &type)
 setters More...
 
void setId (const string &id)
 
void setValidFrom (const QuantLib::Date &validFrom)
 
const std::string & type () const
 getters More...
 
const std::string & id () const
 
const QuantLib::Date & validFrom () const
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
- 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...
 

Static Public Attributes

static constexpr const char * TYPE = "PortfolioBasket"
 

Private Attributes

vector< QuantLib::ext::shared_ptr< Trade > > tradecomponents_
 

Detailed Description

Definition at line 401 of file referencedata.hpp.

Constructor & Destructor Documentation

◆ PortfolioBasketReferenceDatum() [1/3]

Definition at line 406 of file referencedata.hpp.

406 {
407 setType(TYPE);
408 }
static constexpr const char * TYPE
void setType(const string &type)
setters
+ Here is the call graph for this function:

◆ PortfolioBasketReferenceDatum() [2/3]

PortfolioBasketReferenceDatum ( const string &  id)

Definition at line 410 of file referencedata.hpp.

410: ReferenceDatum(TYPE, id) {}
ReferenceDatum()
Default Constructor.

◆ PortfolioBasketReferenceDatum() [3/3]

PortfolioBasketReferenceDatum ( const string &  id,
const QuantLib::Date &  validFrom 
)

Definition at line 412 of file referencedata.hpp.

413 : ReferenceDatum(TYPE, id, validFrom) {}
const QuantLib::Date & validFrom() const

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from ReferenceDatum.

Definition at line 455 of file referencedata.cpp.

455 {
457 XMLNode* innerNode = XMLUtils::getChildNode(node, type() + "ReferenceData");
458 QL_REQUIRE(innerNode, "No " + type() + "ReferenceData node");
459
460 // Get the "Components" node
461 XMLNode* componentsNode = XMLUtils::getChildNode(innerNode, "Components");
462 QL_REQUIRE(componentsNode, "No Components node");
463
464 tradecomponents_.clear();
465 auto c = XMLUtils::getChildrenNodes(componentsNode, "Trade");
466 int k = 0;
467 for (auto const n : c) {
468
469 string tradeType = XMLUtils::getChildValue(n, "TradeType", true);
470 string id = XMLUtils::getAttribute(n, "id");
471 if (id == "") {
472 id = std::to_string(k);
473 }
474
475 DLOG("Parsing composite trade " << this->id() << " node " << k << " with id: " << id);
476
477 QuantLib::ext::shared_ptr<Trade> trade;
478 try {
479 trade = TradeFactory::instance().build(tradeType);
480 trade->id() = id;
481 Envelope componentEnvelope;
482 if (XMLNode* envNode = XMLUtils::getChildNode(n, "Envelope")) {
483 componentEnvelope.fromXML(envNode);
484 }
485 Envelope env;
486 // the component trade's envelope is the main trade's envelope with possibly overwritten add fields
487 for (auto const& [k, v] : componentEnvelope.fullAdditionalFields()) {
488 env.setAdditionalField(k, v);
489 }
490
491 trade->setEnvelope(env);
492 trade->fromXML(n);
493 tradecomponents_.push_back(trade);
494 DLOG("Added Trade " << id << " (" << trade->id() << ")"
495 << " type:" << tradeType << " to composite trade " << this->id() << ".");
496 k += 1;
497 } catch (const std::exception& e) {
498 StructuredTradeErrorMessage(
499 id, tradeType,
500 "Failed to build subtrade with id '" + id + "' inside composite trade: ", e.what())
501 .log();
502 }
503
504 }
505}
vector< QuantLib::ext::shared_ptr< Trade > > tradecomponents_
const std::string & id() const
const std::string & type() const
getters
void fromXML(XMLNode *node) override
static string getAttribute(XMLNode *node, const string &attrName)
Definition: xmlutils.cpp:419
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
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

Reimplemented from ReferenceDatum.

Definition at line 507 of file referencedata.cpp.

507 {
508 XMLNode* node = ReferenceDatum::toXML(doc);
509 XMLNode* rdNode = XMLUtils::addChild(doc, node, type() + "ReferenceData");
510 XMLUtils::appendNode(node, rdNode);
511 XMLNode* cNode = XMLUtils::addChild(doc, rdNode, "Components");
512 for (auto& u : tradecomponents_) {
513 auto test = u->toXML(doc);
514 XMLUtils::appendNode(cNode, test);
515 }
516
517 return node;
518 }
XMLNode * toXML(ore::data::XMLDocument &doc) const override
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
static void appendNode(XMLNode *parent, XMLNode *child)
Definition: xmlutils.cpp:406
+ Here is the call graph for this function:

◆ getTrades()

const vector< QuantLib::ext::shared_ptr< Trade > > & getTrades ( ) const

Definition at line 418 of file referencedata.hpp.

418{ return tradecomponents_; }
+ Here is the caller graph for this function:

Member Data Documentation

◆ TYPE

constexpr const char* TYPE = "PortfolioBasket"
staticconstexpr

Definition at line 403 of file referencedata.hpp.

◆ tradecomponents_

vector<QuantLib::ext::shared_ptr<Trade> > tradecomponents_
private

Definition at line 421 of file referencedata.hpp.