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

#include <ored/portfolio/commodityspreadoption.hpp>

+ Inheritance diagram for CommoditySpreadOptionData:
+ Collaboration diagram for CommoditySpreadOptionData:

Classes

class  OptionStripData
 

Public Member Functions

 CommoditySpreadOptionData ()
 
 CommoditySpreadOptionData (const std::vector< ore::data::LegData > &legData, const ore::data::OptionData &optionData, QuantLib::Real strike)
 
- 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::vector< ore::data::LegDatalegData_
 
ore::data::OptionData optionData_
 
QuantLib::Real strike_
 
boost::optional< OptionStripDataoptionStrip_
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
const std::vector< ore::data::LegData > & legData () const
 
const ore::data::OptionDataoptionData () const
 
QuantLib::Real strike () const
 
boost::optional< OptionStripDataoptionStrip ()
 
QuantLib::ext::shared_ptr< ore::data::LegDatacreateLegData () const
 

Detailed Description

Definition at line 26 of file commodityspreadoption.hpp.

Constructor & Destructor Documentation

◆ CommoditySpreadOptionData() [1/2]

Definition at line 47 of file commodityspreadoption.hpp.

47{}

◆ CommoditySpreadOptionData() [2/2]

CommoditySpreadOptionData ( const std::vector< ore::data::LegData > &  legData,
const ore::data::OptionData optionData,
QuantLib::Real  strike 
)

Definition at line 48 of file commodityspreadoption.hpp.

Member Function Documentation

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Implements XMLSerializable.

Definition at line 339 of file commodityspreadoption.cpp.

339 {
340 XMLUtils::checkNode(csoNode, "CommoditySpreadOptionData");
341
342 XMLNode* optionDataNode = XMLUtils::getChildNode(csoNode, "OptionData");
343 QL_REQUIRE(optionDataNode, "Invalid CommmoditySpreadOption trade xml: found no OptionData Node");
344
345 optionData_.fromXML(optionDataNode);
346 strike_ = XMLUtils::getChildValueAsDouble(csoNode, "SpreadStrike", true);
347
348 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(csoNode, "LegData");
349 QL_REQUIRE(nodes.size() == 2, "CommoditySpreadOption: Exactly two LegData nodes expected");
350 for (auto& node : nodes) {
351 auto ld = createLegData();
352 ld->fromXML(node);
353 legData_.push_back(*ld);
354 }
355
356 XMLNode* optionStripNode = XMLUtils::getChildNode(csoNode, "OptionStripPaymentDates");
357 if (optionStripNode) {
358 optionStrip_ = OptionStripData();
359 optionStrip_->fromXML(optionStripNode);
360 }
361
362 QL_REQUIRE(legData_[0].isPayer() != legData_[1].isPayer(),
363 "CommoditySpreadOption: both a long and a short Assets are required.");
364}
boost::optional< OptionStripData > optionStrip_
QuantLib::ext::shared_ptr< ore::data::LegData > createLegData() const
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
static void checkNode(XMLNode *n, const string &expectedName)
Definition: xmlutils.cpp:175
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Implements XMLSerializable.

Definition at line 366 of file commodityspreadoption.cpp.

366 {
367 XMLNode* csoNode = doc.allocNode("CommoditySpreadOptionData");
368 for (size_t i = 0; i < legData_.size(); ++i) {
369 XMLUtils::appendNode(csoNode, legData_[i].toXML(doc));
370 }
372 XMLUtils::addChild(doc, csoNode, "SpreadStrike", strike_);
373 if (optionStrip_.has_value()) {
374 XMLUtils::appendNode(csoNode, optionStrip_->toXML(doc));
375 }
376 return csoNode;
377}
XMLNode * toXML(XMLDocument &doc) const override
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
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:

◆ legData()

const std::vector< ore::data::LegData > & legData ( ) const

Definition at line 57 of file commodityspreadoption.hpp.

57{ return legData_; }

◆ optionData()

const ore::data::OptionData & optionData ( ) const

Definition at line 58 of file commodityspreadoption.hpp.

58{ return optionData_; }
+ Here is the caller graph for this function:

◆ strike()

QuantLib::Real strike ( ) const

Definition at line 59 of file commodityspreadoption.hpp.

59{ return strike_; }
+ Here is the caller graph for this function:

◆ optionStrip()

boost::optional< OptionStripData > optionStrip ( )

Definition at line 60 of file commodityspreadoption.hpp.

60{ return optionStrip_; }
+ Here is the caller graph for this function:

◆ createLegData()

QuantLib::ext::shared_ptr< ore::data::LegData > createLegData ( ) const
private

Definition at line 63 of file commodityspreadoption.hpp.

63{ return QuantLib::ext::make_shared<ore::data::LegData>(); }

Member Data Documentation

◆ legData_

std::vector<ore::data::LegData> legData_
private

Definition at line 65 of file commodityspreadoption.hpp.

◆ optionData_

ore::data::OptionData optionData_
private

Definition at line 66 of file commodityspreadoption.hpp.

◆ strike_

QuantLib::Real strike_
private

Definition at line 67 of file commodityspreadoption.hpp.

◆ optionStrip_

boost::optional<OptionStripData> optionStrip_
private

Definition at line 69 of file commodityspreadoption.hpp.