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

#include <ored/portfolio/underlying.hpp>

+ Inheritance diagram for CommodityUnderlying:
+ Collaboration diagram for CommodityUnderlying:

Public Member Functions

 CommodityUnderlying ()
 Default Constructor. More...
 
 CommodityUnderlying (const std::string &name, const QuantLib::Real weight, const std::string &priceType, const QuantLib::Size futureMonthOffset, const QuantLib::Size deliveryRollDays, const std::string &deliveryRollCalendar)
 Constructor with identifier information. More...
 
const std::string & priceType () const
 
QuantLib::Size futureMonthOffset () const
 
QuantLib::Size deliveryRollDays () const
 
const std::string & deliveryRollCalendar () const
 
const std::string & futureContractMonth () const
 
const std::string & futureExpiryDate () const
 
- Public Member Functions inherited from Underlying
 Underlying ()
 Default Constructor. More...
 
 Underlying (const std::string &type, const std::string &name, const QuantLib::Real weight=QuantLib::Null< QuantLib::Real >())
 Constructor with type, name, weight. More...
 
void setType (const string &type)
 
void setName (const string &name)
 
void setWeight (const QuantLib::Real weight)
 
void setNodeName (const string &nodeName)
 
void setBasicUnderlyingNodeName (const string &basicUnderlyingNodeName)
 
const std::string & type () const
 
virtual const std::string & name () const
 
Real weight () const
 
- 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...
 

Serialisation

std::string priceType_
 
QuantLib::Size futureMonthOffset_ = QuantLib::Null<QuantLib::Size>()
 
QuantLib::Size deliveryRollDays_ = QuantLib::Null<QuantLib::Size>()
 
std::string deliveryRollCalendar_
 
std::string futureContractMonth_
 
std::string futureExpiryDate_
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 

Additional Inherited Members

- Protected Attributes inherited from Underlying
std::string type_
 
std::string name_
 
Real weight_ = QuantLib::Null<QuantLib::Real>()
 
std::string nodeName_
 
std::string basicUnderlyingNodeName_
 
bool isBasic_ = false
 

Detailed Description

Definition at line 127 of file underlying.hpp.

Constructor & Destructor Documentation

◆ CommodityUnderlying() [1/2]

Default Constructor.

Definition at line 130 of file underlying.hpp.

130: Underlying() { setType("Commodity"); }
Underlying()
Default Constructor.
Definition: underlying.hpp:40
void setType(const string &type)
Definition: underlying.hpp:53
+ Here is the call graph for this function:

◆ CommodityUnderlying() [2/2]

CommodityUnderlying ( const std::string &  name,
const QuantLib::Real  weight,
const std::string &  priceType,
const QuantLib::Size  futureMonthOffset,
const QuantLib::Size  deliveryRollDays,
const std::string &  deliveryRollCalendar 
)

Constructor with identifier information.

Definition at line 133 of file underlying.hpp.

QuantLib::Size deliveryRollDays() const
Definition: underlying.hpp:141
const std::string & deliveryRollCalendar() const
Definition: underlying.hpp:142
const std::string & priceType() const
Definition: underlying.hpp:139
QuantLib::Size futureMonthOffset() const
Definition: underlying.hpp:140
Real weight() const
Definition: underlying.hpp:65
virtual const std::string & name() const
Definition: underlying.hpp:64

Member Function Documentation

◆ priceType()

const std::string & priceType ( ) const

Definition at line 139 of file underlying.hpp.

139{ return priceType_; }

◆ futureMonthOffset()

QuantLib::Size futureMonthOffset ( ) const

Definition at line 140 of file underlying.hpp.

140{ return futureMonthOffset_; }

◆ deliveryRollDays()

QuantLib::Size deliveryRollDays ( ) const

Definition at line 141 of file underlying.hpp.

141{ return deliveryRollDays_; }

◆ deliveryRollCalendar()

const std::string & deliveryRollCalendar ( ) const

Definition at line 142 of file underlying.hpp.

142{ return deliveryRollCalendar_; }

◆ futureContractMonth()

const std::string & futureContractMonth ( ) const

Definition at line 143 of file underlying.hpp.

143{ return futureContractMonth_; }

◆ futureExpiryDate()

const std::string & futureExpiryDate ( ) const

Definition at line 144 of file underlying.hpp.

144{ return futureExpiryDate_; }

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Underlying.

Definition at line 118 of file underlying.cpp.

118 {
121 isBasic_ = true;
122 } else if (XMLUtils::getNodeName(node) == nodeName_) {
124 QL_REQUIRE(type_ == "Commodity", "Underlying must be of type 'Commodity'.");
125 priceType_ = XMLUtils::getChildValue(node, "PriceType", false);
126 if (auto n = XMLUtils::getChildNode(node, "FutureMonthOffset"))
128 else
129 futureMonthOffset_ = Null<Size>();
130 if (auto n = XMLUtils::getChildNode(node, "DeliveryRollDays"))
132 else
133 deliveryRollDays_ = Null<Size>();
134 deliveryRollCalendar_ = XMLUtils::getChildValue(node, "DeliveryRollCalendar", false);
135 isBasic_ = false;
136 futureExpiryDate_ = XMLUtils::getChildValue(node, "FutureExpiryDate", false);
137 futureContractMonth_ = XMLUtils::getChildValue(node, "FutureContractMonth", false);
138 QL_REQUIRE(futureExpiryDate_.empty() || futureContractMonth_.empty(),
139 "Only futureExpiryDate or futureContractMonth are allowed not both");
140 } else {
141 QL_FAIL("Need either a Name or Underlying node for CommodityUnderlying.");
142 }
143 setType("Commodity");
144}
std::string basicUnderlyingNodeName_
Definition: underlying.hpp:71
std::string nodeName_
Definition: underlying.hpp:71
virtual void fromXML(ore::data::XMLNode *node) override
Definition: underlying.cpp:33
static string getNodeName(XMLNode *n)
Get and set a node's name.
Definition: xmlutils.cpp:473
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
static string getNodeValue(XMLNode *node)
Get a node's value.
Definition: xmlutils.cpp:489
Integer parseInteger(const string &s)
Convert text to QuantLib::Integer.
Definition: parsers.cpp:136
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Underlying.

Definition at line 146 of file underlying.cpp.

146 {
147 XMLNode* node;
148 if (isBasic_) {
149 node = doc.allocNode(basicUnderlyingNodeName_, name_);
150 } else {
151 node = Underlying::toXML(doc);
152 if (!priceType_.empty())
153 XMLUtils::addChild(doc, node, "PriceType", priceType_);
154 if (futureMonthOffset_ != Null<Size>())
155 XMLUtils::addChild(doc, node, "FutureMonthOffset", (int)futureMonthOffset_);
156 if (deliveryRollDays_ != Null<Size>())
157 XMLUtils::addChild(doc, node, "DeliveryRollDays", (int)deliveryRollDays_);
158 if (!deliveryRollCalendar_.empty())
159 XMLUtils::addChild(doc, node, "DeliveryRollCalendar", deliveryRollCalendar_);
160 if (!futureExpiryDate_.empty())
161 XMLUtils::addChild(doc, node, "FutureExpiryDate", futureExpiryDate_);
162 if (!futureContractMonth_.empty())
163 XMLUtils::addChild(doc, node, "FutureContractMonth", futureContractMonth_);
164 }
165 return node;
166}
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
Definition: underlying.cpp:42
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
Definition: xmlutils.cpp:181
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

Member Data Documentation

◆ priceType_

std::string priceType_
private

Definition at line 152 of file underlying.hpp.

◆ futureMonthOffset_

QuantLib::Size futureMonthOffset_ = QuantLib::Null<QuantLib::Size>()
private

Definition at line 153 of file underlying.hpp.

◆ deliveryRollDays_

QuantLib::Size deliveryRollDays_ = QuantLib::Null<QuantLib::Size>()
private

Definition at line 154 of file underlying.hpp.

◆ deliveryRollCalendar_

std::string deliveryRollCalendar_
private

Definition at line 155 of file underlying.hpp.

◆ futureContractMonth_

std::string futureContractMonth_
private

Definition at line 156 of file underlying.hpp.

◆ futureExpiryDate_

std::string futureExpiryDate_
private

Definition at line 157 of file underlying.hpp.