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

Commodity option trade representation. More...

#include <ored/portfolio/commodityoption.hpp>

+ Inheritance diagram for CommodityOption:
+ Collaboration diagram for CommodityOption:

Public Member Functions

 CommodityOption ()
 Default constructor. More...
 
 CommodityOption (const Envelope &env, const OptionData &optionData, const std::string &commodityName, const std::string &currency, QuantLib::Real quantity, TradeStrike strike, const boost::optional< bool > &isFuturePrice=boost::none, const QuantLib::Date &futureExpiryDate=QuantLib::Date())
 Detailed constructor. More...
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory) override
 Build underlying instrument and link pricing engine. More...
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Commodity names. More...
 
Serialisation
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
Trade
bool hasCashflows () const override
 
- Public Member Functions inherited from VanillaOptionTrade
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
void setNotionalAndCurrencies ()
 
const OptionDataoption () const
 
const string & asset () const
 
const string & currency () const
 
TradeStrike strike () const
 
double quantity () const
 
const QuantLib::Date forwardDate () const
 
const QuantLib::Date paymentDate () const
 
- Public Member Functions inherited from Trade
 Trade ()
 Default constructor. More...
 
 Trade (const string &tradeType, const Envelope &env=Envelope(), const TradeActions &ta=TradeActions())
 Base class constructor. More...
 
virtual ~Trade ()
 Default destructor. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &)=0
 
virtual std::map< std::string, RequiredFixings::FixingDatesfixings (const QuantLib::Date &settlementDate=QuantLib::Date()) const
 
const RequiredFixingsrequiredFixings () const
 
virtual std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const
 
void reset ()
 Reset trade, clear all base class data. This does not reset accumulated timings for this trade. More...
 
void resetPricingStats (const std::size_t numberOfPricings=0, const boost::timer::nanosecond_type cumulativePricingTime=0)
 Reset accumulated timings to given values. More...
 
string & id ()
 Set the trade id. More...
 
void setEnvelope (const Envelope &envelope)
 Set the envelope with counterparty and portfolio info. More...
 
void setAdditionalData (const std::map< std::string, boost::any > &additionalData)
 
TradeActionstradeActions ()
 Set the trade actions. More...
 
const string & id () const
 
const string & tradeType () const
 
const Envelopeenvelope () const
 
const set< string > & portfolioIds () const
 
const TradeActionstradeActions () const
 
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument () const
 
const std::vector< QuantLib::Leg > & legs () const
 
const std::vector< string > & legCurrencies () const
 
const std::vector< bool > & legPayers () const
 
const string & npvCurrency () const
 
virtual QuantLib::Real notional () const
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
virtual string notionalCurrency () const
 
const Date & maturity () const
 
virtual bool isExpired (const Date &d)
 
const string & issuer () const
 
template<typename T >
additionalDatum (const std::string &tag) const
 returns any additional datum. More...
 
virtual const std::map< std::string, boost::any > & additionalData () const
 returns all additional data returned by the trade once built More...
 
const std::string & sensitivityTemplate () const
 
void validate () const
 Utility to validate that everything that needs to be set in this base class is actually set. More...
 
boost::timer::nanosecond_type getCumulativePricingTime () const
 Get cumulative timing spent on pricing. More...
 
std::size_t getNumberOfPricings () const
 Get number of pricings. More...
 
- 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...
 

Inspectors

boost::optional< boolisFuturePrice_
 
QuantLib::Date futureExpiryDate_
 
const boost::optional< bool > & isFuturePrice () const
 
const QuantLib::Date & futureExpiryDate () const
 

Additional Inherited Members

- Protected Member Functions inherited from VanillaOptionTrade
 VanillaOptionTrade (AssetClass assetClassUnderlying)
 
 VanillaOptionTrade (const Envelope &env, AssetClass assetClassUnderlying, OptionData option, string assetName, string currency, double quantity, TradeStrike strike, const QuantLib::ext::shared_ptr< QuantLib::Index > &index=nullptr, const std::string &indexName="", QuantLib::Date forwardDate=QuantLib::Date())
 
- Protected Member Functions inherited from Trade
Date addPremiums (std::vector< QuantLib::ext::shared_ptr< Instrument > > &instruments, std::vector< Real > &multipliers, const Real tradeMultiplier, const PremiumData &premiumData, const Real premiumMultiplier, const Currency &tradeCurrency, const QuantLib::ext::shared_ptr< EngineFactory > &factory, const string &configuration)
 
void setLegBasedAdditionalData (const Size legNo, Size resultLegId=Null< Size >()) const
 
void setSensitivityTemplate (const EngineBuilder &builder)
 
void setSensitivityTemplate (const std::string &id)
 
- Protected Attributes inherited from VanillaOptionTrade
AssetClass assetClassUnderlying_
 
OptionData option_
 
string assetName_
 
string currency_
 
Currency underlyingCurrency_
 
double quantity_
 
TradeStrike strike_
 
QuantLib::ext::shared_ptr< QuantLib::Index > index_
 An index is needed if the option is to be automatically exercised on expiry. More...
 
std::string indexName_
 Hold the external index name if needed e.g. in the case of an FX index. More...
 
QuantLib::Date expiryDate_
 Store the option expiry date. More...
 
QuantLib::Date forwardDate_
 Store the (optional) forward date. More...
 
QuantLib::Date paymentDate_
 Store the (optional) payment date. More...
 
- Protected Attributes inherited from Trade
string tradeType_
 
QuantLib::ext::shared_ptr< InstrumentWrapperinstrument_
 
std::vector< QuantLib::Leg > legs_
 
std::vector< string > legCurrencies_
 
std::vector< boollegPayers_
 
string npvCurrency_
 
QuantLib::Real notional_
 
string notionalCurrency_
 
Date maturity_
 
string issuer_
 
string sensitivityTemplate_
 
bool sensitivityTemplateSet_ = false
 
std::size_t savedNumberOfPricings_ = 0
 
boost::timer::nanosecond_type savedCumulativePricingTime_ = 0
 
RequiredFixings requiredFixings_
 
std::map< std::string, boost::any > additionalData_
 

Detailed Description

Commodity option trade representation.

Definition at line 35 of file commodityoption.hpp.

Constructor & Destructor Documentation

◆ CommodityOption() [1/2]

Default constructor.

Definition at line 41 of file commodityoption.cpp.

41: VanillaOptionTrade(AssetClass::COM) { tradeType_ = "CommodityOption"; }
string tradeType_
Definition: trade.hpp:196
VanillaOptionTrade(AssetClass assetClassUnderlying)

◆ CommodityOption() [2/2]

CommodityOption ( const Envelope env,
const OptionData optionData,
const std::string &  commodityName,
const std::string &  currency,
QuantLib::Real  quantity,
TradeStrike  strike,
const boost::optional< bool > &  isFuturePrice = boost::none,
const QuantLib::Date &  futureExpiryDate = QuantLib::Date() 
)

Detailed constructor.

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< EngineFactory > &  engineFactory)
overridevirtual

Build underlying instrument and link pricing engine.

Implements Trade.

Definition at line 51 of file commodityoption.cpp.

51 {
52
53 // ISDA taxonomy, assuming Commodity follows the Equity template
54 additionalData_["isdaAssetClass"] = std::string("Commodity");
55 additionalData_["isdaBaseProduct"] = std::string("Option");
56 additionalData_["isdaSubProduct"] = std::string("Price Return Basic Performance");
57 // skip the transaction level mapping for now
58 additionalData_["isdaTransaction"] = std::string("");
59
60 additionalData_["quantity"] = quantity_;
61 additionalData_["strike"] = strike_.value();
62 additionalData_["strikeCurrency"] = currency_;
63
64 // Checks
65 QL_REQUIRE((strike_.value() > 0) || close_enough(strike_.value(),0.0), "Commodity option requires a non-negative strike");
66 if (close_enough(strike_.value(), 0.0)) {
67 strike_.setValue(0.0);
68 }
69
70 // This is called in VanillaOptionTrade::build(), but we want to call it first here,
71 // in case the build fails before it reaches VanillaOptionTrade::build()
73
74 // Populate the index_ in case the option is automatic exercise.
75 // Intentionally use null calendar because we will ask for index value on the expiry date without adjustment.
76 const QuantLib::ext::shared_ptr<Market>& market = engineFactory->market();
77 index_ = *market->commodityIndex(assetName_, engineFactory->configuration(MarketContext::pricing));
79
80 // Assume future price if isFuturePrice_ is not explicitly set or if it is and true.
81
82 auto index = *market->commodityIndex(assetName_, engineFactory->configuration(MarketContext::pricing));
83
84 // If we are given an explicit future contract expiry date, use it, otherwise use option's expiry.
85 Date expiryDate;
86 if (futureExpiryDate_ != Date()) {
87 expiryDate = futureExpiryDate_;
88 } else {
89 // Get the expiry date of the option. This is the expiry date of the commodity future index.
90 const vector<string>& expiryDates = option_.exerciseDates();
91 QL_REQUIRE(expiryDates.size() == 1,
92 "Expected exactly one expiry date for CommodityOption but got " << expiryDates.size() << ".");
93 expiryDate = parseDate(expiryDates[0]);
94 }
95
96 // Clone the index with the relevant expiry date.
97 index_ = index->clone(expiryDate);
98
99 // Set the VanillaOptionTrade forwardDate_ if the index is a CommodityFuturesIndex - we possibly still have a
100 // CommoditySpotIndex at this point so check. Also, will only work for European exercise.
101 auto et = parseExerciseType(option_.style());
102 if (et == Exercise::European && QuantLib::ext::dynamic_pointer_cast<CommodityFuturesIndex>(index_)) {
103 forwardDate_ = expiryDate;
104 }
105
106 }
107
108 VanillaOptionTrade::build(engineFactory);
109
110 // LOG the volatility if the trade expiry date is in the future.
111 if (expiryDate_ > Settings::instance().evaluationDate()) {
112 DLOG("Implied vol for " << tradeType_ << " on " << assetName_ << " with expiry " << expiryDate_
113 << " and strike " << strike_.value() << " is "
114 << market->commodityVolatility(assetName_)->blackVol(expiryDate_, strike_.value()));
115 }
116}
boost::optional< bool > isFuturePrice_
const string & style() const
Definition: optiondata.hpp:74
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
QuantLib::Real value() const
void setValue(const QuantLib::Real &value)
QuantLib::Date expiryDate_
Store the option expiry date.
QuantLib::Date forwardDate_
Store the (optional) forward date.
QuantLib::ext::shared_ptr< QuantLib::Index > index_
An index is needed if the option is to be automatically exercised on expiry.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Exercise::Type parseExerciseType(const std::string &s)
Convert text to QuantLib::Exercise::Type.
Definition: parsers.cpp:466
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ underlyingIndices()

std::map< AssetClass, std::set< std::string > > underlyingIndices ( const QuantLib::ext::shared_ptr< ReferenceDataManager > &  referenceDataManager = nullptr) const
overridevirtual

Add underlying Commodity names.

Reimplemented from Trade.

Definition at line 119 of file commodityoption.cpp.

119 {
120 return {{AssetClass::COM, std::set<std::string>({assetName_})}};
121}

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 123 of file commodityoption.cpp.

123 {
124
125 Trade::fromXML(node);
126
127 XMLNode* commodityNode = XMLUtils::getChildNode(node, "CommodityOptionData");
128 QL_REQUIRE(commodityNode, "A commodity option needs a 'CommodityOptionData' node");
129
130 option_.fromXML(XMLUtils::getChildNode(commodityNode, "OptionData"));
131
132 assetName_ = XMLUtils::getChildValue(commodityNode, "Name", true);
133 currency_ = XMLUtils::getChildValue(commodityNode, "Currency", true);
134 strike_.fromXML(commodityNode);
135 quantity_ = XMLUtils::getChildValueAsDouble(commodityNode, "Quantity", true);
136
137 isFuturePrice_ = boost::none;
138 if (XMLNode* n = XMLUtils::getChildNode(commodityNode, "IsFuturePrice"))
140
141 futureExpiryDate_ = Date();
142 if (XMLNode* n = XMLUtils::getChildNode(commodityNode, "FutureExpiryDate"))
144}
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
void fromXML(XMLNode *node, const bool isRequired=true, const bool allowYieldStrike=false)
Definition: tradestrike.cpp:50
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
Definition: xmlutils.cpp:286
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
bool parseBool(const string &s)
Convert text to bool.
Definition: parsers.cpp:144
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60
+ Here is the call graph for this function:

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 146 of file commodityoption.cpp.

146 {
147
148 XMLNode* node = Trade::toXML(doc);
149
150 XMLNode* eqNode = doc.allocNode("CommodityOptionData");
151 XMLUtils::appendNode(node, eqNode);
152
153 XMLUtils::appendNode(eqNode, option_.toXML(doc));
154
155 XMLUtils::addChild(doc, eqNode, "Name", assetName_);
156 XMLUtils::addChild(doc, eqNode, "Currency", currency_);
157 XMLUtils::appendNode(eqNode, strike_.toXML(doc));
158 XMLUtils::addChild(doc, eqNode, "Quantity", quantity_);
159
160 if (isFuturePrice_)
161 XMLUtils::addChild(doc, eqNode, "IsFuturePrice", *isFuturePrice_);
162
163 if (futureExpiryDate_ != Date())
164 XMLUtils::addChild(doc, eqNode, "FutureExpiryDate", to_string(futureExpiryDate_));
165
166 return node;
167}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
XMLNode * toXML(XMLDocument &doc) const
Definition: tradestrike.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
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ hasCashflows()

bool hasCashflows ( ) const
overridevirtual

Utility method indicating if the trade has cashflows for the cashflow report. The default implementation returns true so that a trade is automatically considered when cashflows are being written. To prevent a trade from being asked for its cashflows, the method can be overridden to return false.

Reimplemented from Trade.

Definition at line 61 of file commodityoption.hpp.

61{ return false; }

◆ isFuturePrice()

const boost::optional< bool > & isFuturePrice ( ) const

Definition at line 66 of file commodityoption.hpp.

66{ return isFuturePrice_; }

◆ futureExpiryDate()

const QuantLib::Date & futureExpiryDate ( ) const

Definition at line 67 of file commodityoption.hpp.

67{ return futureExpiryDate_; }

Member Data Documentation

◆ isFuturePrice_

boost::optional<bool> isFuturePrice_
private

Indicates if the option underlying is a commodity future settlement price, true, or a spot price false. If not explicitly set, it is assumed to be true.

Definition at line 74 of file commodityoption.hpp.

◆ futureExpiryDate_

QuantLib::Date futureExpiryDate_
private

An explicit expiry date for the underlying future contract. This can be used if the option trade references a future contract settlement price and the option's expiry date does not match the future contract expiry date.

Definition at line 79 of file commodityoption.hpp.