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

#include <ored/portfolio/commodityswaption.hpp>

+ Inheritance diagram for CommoditySwaption:
+ Collaboration diagram for CommoditySwaption:

Public Member Functions

 CommoditySwaption ()
 
 CommoditySwaption (const ore::data::Envelope &env, const ore::data::OptionData &option, const std::vector< ore::data::LegData > &legData)
 
void build (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &engineFactory) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Commodity names. More...
 
Inspectors
const ore::data::OptionDataoption ()
 
const std::vector< ore::data::LegData > & legData () const
 
Serialisation
virtual void fromXML (ore::data::XMLNode *node) override
 
virtual ore::data::XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
- 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 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...
 

Trade

ore::data::OptionData option_
 
vector< ore::data::LegDatalegData_
 
QuantLib::ext::shared_ptr< QuantLib::Exercise > exercise_
 
std::string name_
 
std::string ccy_
 
QuantLib::Date startDate_
 
QuantLib::ext::shared_ptr< CommoditySwapcommoditySwap_
 
bool hasCashflows () const override
 
QuantLib::ext::shared_ptr< ore::data::LegDatacreateLegData () const
 
QuantLib::ext::shared_ptr< QuantLib::Swap > buildSwap (const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &engineFactory)
 

Additional Inherited Members

- 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 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

Serializable Commodity Swap

Definition at line 35 of file commodityswaption.hpp.

Constructor & Destructor Documentation

◆ CommoditySwaption() [1/2]

Definition at line 37 of file commodityswaption.hpp.

37: ore::data::Trade("CommoditySwaption") {}
Trade base class.
Definition: trade.hpp:55

◆ CommoditySwaption() [2/2]

CommoditySwaption ( const ore::data::Envelope env,
const ore::data::OptionData option,
const std::vector< ore::data::LegData > &  legData 
)

Definition at line 39 of file commodityswaption.hpp.

41 : Trade("CommoditySwaption", env), legData_(legData) {}
const std::vector< ore::data::LegData > & legData() const
vector< ore::data::LegData > legData_
Trade()
Default constructor.
Definition: trade.hpp:59

Member Function Documentation

◆ build()

void build ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  engineFactory)
override

Definition at line 44 of file commodityswaption.cpp.

44 {
45
46 reset();
47
48 DLOG("CommoditySwaption::build() called for trade " << id());
49
50 // ISDA taxonomy
51 additionalData_["isdaAssetClass"] = std::string("Commodity");
52 additionalData_["isdaBaseProduct"] = std::string("Other");
53 additionalData_["isdaSubProduct"] = std::string("");
54 // skip the transaction level mapping for now
55 additionalData_["isdaTransaction"] = std::string("");
56
57 // Swaption details
58 Settlement::Type settleType = parseSettlementType(option_.settlement());
59
60 // Just set a consistent method here if it is left empty
61 Settlement::Method settleMethod = Settlement::PhysicalOTC;
62 if (option_.settlementMethod().empty()) {
63 if (settleType == Settlement::Cash) {
64 settleMethod = Settlement::CollateralizedCashPrice;
65 }
66 } else {
68 }
69
70 QL_REQUIRE(option_.exerciseDates().size() == 1, "Commodity swaption must be European");
71 Date exDate = parseDate(option_.exerciseDates().front());
72 QL_REQUIRE(exDate >= Settings::instance().evaluationDate(),
73 "Exercise date, " << io::iso_date(exDate) << ", should be in the future relative to the valuation date "
74 << io::iso_date(Settings::instance().evaluationDate()));
75
76 // Build the underyling swap and check exercise date
77 QuantLib::ext::shared_ptr<QuantLib::Swap> swap = buildSwap(engineFactory);
78 QL_REQUIRE(exDate <= startDate_, "Expected the expiry date, " << io::iso_date(exDate)
79 << " to be on or before the swap start date "
80 << io::iso_date(startDate_));
81
82 // Build the swaption
83 exercise_ = QuantLib::ext::make_shared<EuropeanExercise>(exDate);
84 QuantLib::ext::shared_ptr<QuantExt::GenericSwaption> swaption =
85 QuantLib::ext::make_shared<QuantExt::GenericSwaption>(swap, exercise_, settleType, settleMethod);
86
87 // Set the swaption's pricing engine
88 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
89 QuantLib::ext::shared_ptr<CommoditySwaptionEngineBuilder> engineBuilder =
90 QuantLib::ext::dynamic_pointer_cast<CommoditySwaptionEngineBuilder>(builder);
91 auto configuration = builder->configuration(MarketContext::pricing);
92 Currency currency = parseCurrency(ccy_);
93 QuantLib::ext::shared_ptr<PricingEngine> engine = engineBuilder->engine(currency, name_);
94 setSensitivityTemplate(*engineBuilder);
95 swaption->setPricingEngine(engine);
96
97 // Set the instrument wrapper properly
98 Position::Type positionType = parsePositionType(option_.longShort());
99 if (settleType == Settlement::Cash) {
100 Real multiplier = positionType == Position::Long ? 1.0 : -1.0;
101 instrument_ = QuantLib::ext::make_shared<VanillaInstrument>(swaption, multiplier);
102 } else {
103 instrument_ = QuantLib::ext::make_shared<EuropeanOptionWrapper>(swaption, positionType == Position::Long, exDate,
104 settleType == Settlement::Physical, swap);
105 }
106 // use underlying maturity independent of settlement type, following ISDA GRID/AANA guidance
107 maturity_ = swap->maturityDate();
108}
ore::data::OptionData option_
QuantLib::ext::shared_ptr< QuantLib::Exercise > exercise_
QuantLib::ext::shared_ptr< QuantLib::Swap > buildSwap(const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &engineFactory)
const string & settlementMethod() const
Definition: optiondata.hpp:82
const string & longShort() const
Definition: optiondata.hpp:70
const string & settlement() const
Definition: optiondata.hpp:81
const vector< string > & exerciseDates() const
Definition: optiondata.hpp:76
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
string tradeType_
Definition: trade.hpp:196
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
void reset()
Reset trade, clear all base class data. This does not reset accumulated timings for this trade.
Definition: trade.cpp:130
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Settlement::Method parseSettlementMethod(const std::string &s)
Convert text to QuantLib::Settlement::Method.
Definition: parsers.cpp:450
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:290
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
Settlement::Type parseSettlementType(const std::string &s)
Convert text to QuantLib::Settlement::Type.
Definition: parsers.cpp:434
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
+ Here is the call graph for this function:

◆ notional()

QuantLib::Real notional ( ) const
overridevirtual

Return the current notional in npvCurrency. See individual sub-classes for the precise definition.

Reimplemented from Trade.

Definition at line 110 of file commodityswaption.cpp.

110 {
111 return commoditySwap_->notional();
112}
QuantLib::ext::shared_ptr< CommoditySwap > commoditySwap_

◆ 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 159 of file commodityswaption.cpp.

159 {
160
161 std::map<AssetClass, std::set<std::string>> result;
162
163 for (auto ld : legData_) {
164 set<string> indices = ld.indices();
165 for (auto ind : indices) {
166 QuantLib::ext::shared_ptr<Index> index = parseIndex(ind);
167 // only handle commodity
168 if (auto ci = QuantLib::ext::dynamic_pointer_cast<QuantExt::CommodityIndex>(index)) {
169 result[AssetClass::COM].insert(ci->name());
170 }
171 }
172 }
173 return result;
174}
QuantLib::ext::shared_ptr< Index > parseIndex(const string &s)
Convert std::string to QuantLib::Index.
+ Here is the call graph for this function:

◆ option()

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

Definition at line 52 of file commodityswaption.hpp.

52{ return option_; }

◆ legData()

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

Definition at line 53 of file commodityswaption.hpp.

53{ return legData_; }

◆ fromXML()

void fromXML ( ore::data::XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 176 of file commodityswaption.cpp.

176 {
177
178 Trade::fromXML(node);
179
180 XMLNode* swapNode = XMLUtils::getChildNode(node, "CommoditySwaptionData");
181 QL_REQUIRE(swapNode, "No CommoditySwaptionData node");
182
183 // Get the option data
184 option_.fromXML(XMLUtils::getChildNode(swapNode, "OptionData"));
185
186 // Get the leg data i.e. the leg data describing the underlying swap
187 vector<XMLNode*> nodes = XMLUtils::getChildrenNodes(swapNode, "LegData");
188 QL_REQUIRE(nodes.size() == 2, "Two commodity swap legs expected, found " << nodes.size());
189 legData_.clear();
190 for (Size i = 0; i < nodes.size(); i++) {
191 auto ld = createLegData();
192 ld->fromXML(nodes[i]);
193 legData_.push_back(*ld);
194 }
195}
QuantLib::ext::shared_ptr< ore::data::LegData > createLegData() const
virtual void fromXML(XMLNode *node) override
Definition: optiondata.cpp:32
virtual void fromXML(XMLNode *node) override
Definition: trade.cpp:34
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
Definition: xmlutils.cpp:428
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 ( ore::data::XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 197 of file commodityswaption.cpp.

197 {
198 XMLNode* node = Trade::toXML(doc);
199
200 // Add the root CommoditySwaptionData node
201 XMLNode* swaptionNode = doc.allocNode("CommoditySwaptionData");
202 XMLUtils::appendNode(node, swaptionNode);
203
204 // Add the OptionData node
205 XMLUtils::appendNode(swaptionNode, option_.toXML(doc));
206
207 // Add the LegData nodes
208 for (Size i = 0; i < legData_.size(); i++)
209 XMLUtils::appendNode(swaptionNode, legData_[i].toXML(doc));
210
211 return node;
212}
virtual ore::data::XMLNode * toXML(ore::data::XMLDocument &doc) const override
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: optiondata.cpp:86
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
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:
+ Here is the caller 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 64 of file commodityswaption.hpp.

64{ return false; }

◆ createLegData()

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

Definition at line 68 of file commodityswaption.hpp.

68{ return QuantLib::ext::make_shared<ore::data::LegData>(); }
+ Here is the caller graph for this function:

◆ buildSwap()

QuantLib::ext::shared_ptr< QuantLib::Swap > buildSwap ( const QuantLib::ext::shared_ptr< ore::data::EngineFactory > &  engineFactory)
private

Definition at line 114 of file commodityswaption.cpp.

114 {
115
116 // Some checks to make sure the underlying swap is supported
117 QL_REQUIRE(legData_.size() == 2, "Expected two commodity legs but found " << legData_.size());
118 QL_REQUIRE(legData_[0].currency() == legData_[1].currency(), "Cross currency commodity swap not supported");
119 QL_REQUIRE(legData_[0].isPayer() != legData_[1].isPayer(),
120 "Both commodity legs are " << (legData_[0].isPayer() ? "paying" : "receiving"));
121
122 QL_REQUIRE(legData_[0].legType() == "CommodityFixed" || legData_[0].legType() == "CommodityFloating",
123 "Leg type needs to be CommodityFixed or CommodityFloating but 1st leg has type "
124 << legData_[0].legType());
125 QL_REQUIRE(legData_[1].legType() == "CommodityFixed" || legData_[1].legType() == "CommodityFloating",
126 "Leg type needs to be CommodityFixed or CommodityFloating but 2nd leg has type "
127 << legData_[1].legType());
128
129 if (legData_[0].legType() == "CommodityFixed") {
130 QL_REQUIRE(legData_[1].legType() == "CommodityFloating",
131 "1st leg is CommodityFixed so 2nd leg should be CommodityFloating but is " << legData_[1].legType());
132 auto floatLeg = QuantLib::ext::dynamic_pointer_cast<CommodityFloatingLegData>(legData_[1].concreteLegData());
133 name_ = floatLeg->name();
134 } else {
135 auto floatLeg = QuantLib::ext::dynamic_pointer_cast<CommodityFloatingLegData>(legData_[0].concreteLegData());
136 QL_REQUIRE(floatLeg, "first leg has type " << legData_[0].legType() << ", expected CommodityFloating");
137 name_ = floatLeg->name();
138 }
139
140 // Build the underlying commodity swap
141 commoditySwap_ = QuantLib::ext::make_shared<CommoditySwap>(envelope(), legData_);
142 commoditySwap_->build(engineFactory);
143
144 // Get the QuantLib::Swap from the commodity swap
145 auto qlInstrument = commoditySwap_->instrument()->qlInstrument();
146 QuantLib::ext::shared_ptr<QuantLib::Swap> swap = QuantLib::ext::dynamic_pointer_cast<QuantLib::Swap>(qlInstrument);
147 QL_REQUIRE(swap, "Expected an underlying swap instrument from CommoditySwap");
148
149 // Populate relevant member variables, notonal and notional currency are set by the underlying Swap build already.
150 startDate_ = swap->startDate();
151 ccy_ = npvCurrency_ = legData_[0].currency();
152 notional_ = Null<Real>();
153 notionalCurrency_ = commoditySwap_->notionalCurrency();
154
155 return swap;
156}
string npvCurrency_
Definition: trade.hpp:201
QuantLib::Real notional_
Definition: trade.hpp:202
const Envelope & envelope() const
Definition: trade.hpp:135
string notionalCurrency_
Definition: trade.hpp:203
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ option_

ore::data::OptionData option_
private

Definition at line 72 of file commodityswaption.hpp.

◆ legData_

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

Definition at line 73 of file commodityswaption.hpp.

◆ exercise_

QuantLib::ext::shared_ptr<QuantLib::Exercise> exercise_
private

Definition at line 74 of file commodityswaption.hpp.

◆ name_

std::string name_
private

Definition at line 75 of file commodityswaption.hpp.

◆ ccy_

std::string ccy_
private

Definition at line 76 of file commodityswaption.hpp.

◆ startDate_

QuantLib::Date startDate_
private

Definition at line 77 of file commodityswaption.hpp.

◆ commoditySwap_

QuantLib::ext::shared_ptr<CommoditySwap> commoditySwap_
private

Definition at line 78 of file commodityswaption.hpp.