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

#include <ored/portfolio/performanceoption_01.hpp>

+ Inheritance diagram for PerformanceOption_01:
+ Collaboration diagram for PerformanceOption_01:

Public Member Functions

 PerformanceOption_01 (const QuantLib::ext::shared_ptr< Conventions > &conventions=nullptr)
 
 PerformanceOption_01 (const Envelope &env, const string &notionalAmount, const string &participationRate, const string &valuationDate, const string &settlementDate, const vector< QuantLib::ext::shared_ptr< Underlying > > &underlyings, const vector< string > &strikePrices, const string &strike, const bool strikeIncluded, const string &position, const string &payCcy, const QuantLib::ext::shared_ptr< Conventions > &conventions=nullptr)
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
void setIsdaTaxonomyFields () override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (XMLDocument &doc) const override
 
- Public Member Functions inherited from ScriptedTrade
 ScriptedTrade (const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::map< std::string, ScriptedTradeScriptData > &script, const std::string &productTag, const std::string &tradeType="ScriptedTrade")
 
 ScriptedTrade (const Envelope &env, const std::vector< ScriptedTradeEventData > &events, const std::vector< ScriptedTradeValueTypeData > &numbers, const std::vector< ScriptedTradeValueTypeData > &indices, const std::vector< ScriptedTradeValueTypeData > &currencies, const std::vector< ScriptedTradeValueTypeData > &daycounters, const std::string &scriptName, const std::string &tradeType="ScriptedTrade")
 
void clear ()
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
QuantLib::Real notional () const override
 Return the current notional in npvCurrency. See individual sub-classes for the precise definition. More...
 
std::string notionalCurrency () const override
 
void fromXML (XMLNode *node) override
 
XMLNodetoXML (ore::data::XMLDocument &doc) const override
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &engineFactory, const PremiumData &premiumData, const Real premiumMultiplier)
 
std::map< ore::data::AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 
virtual void setIsdaTaxonomyFields ()
 
const std::vector< ScriptedTradeEventData > & events () const
 
const std::vector< ScriptedTradeValueTypeData > & numbers () const
 
const std::vector< ScriptedTradeValueTypeData > & indices () const
 
const std::vector< ScriptedTradeValueTypeData > & currencies () const
 
const std::vector< ScriptedTradeValueTypeData > & daycounters () const
 
const std::map< std::string, ScriptedTradeScriptData > & script () const
 
const std::string & productTag () const
 
const std::string & scriptName () const
 
const std::string & simmProductClass () const
 
const std::string & scheduleProductClass () const
 
const ScriptedTradeScriptDatascript (const std::string &purpose, const bool fallBackOnEmptyPurpose=true) 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
 
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...
 
virtual bool hasCashflows () const
 
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...
 

Private Member Functions

void initIndices ()
 

Private Attributes

string notionalAmount_
 
string participationRate_
 
string valuationDate_
 
string settlementDate_
 
vector< QuantLib::ext::shared_ptr< Underlying > > underlyings_
 
vector< string > strikePrices_
 
string strike_
 
bool strikeIncluded_ = true
 
string position_
 
string payCcy_
 

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 ScriptedTrade
std::vector< ScriptedTradeEventDataevents_
 
std::vector< ScriptedTradeValueTypeDatanumbers_
 
std::vector< ScriptedTradeValueTypeDataindices_
 
std::vector< ScriptedTradeValueTypeDatacurrencies_
 
std::vector< ScriptedTradeValueTypeDatadaycounters_
 
std::map< std::string, ScriptedTradeScriptDatascript_
 
std::string productTag_
 
std::string scriptName_
 
std::string simmProductClass_
 
std::string scheduleProductClass_
 
- 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

Definition at line 35 of file performanceoption_01.hpp.

Constructor & Destructor Documentation

◆ PerformanceOption_01() [1/2]

PerformanceOption_01 ( const QuantLib::ext::shared_ptr< Conventions > &  conventions = nullptr)
explicit

Definition at line 37 of file performanceoption_01.hpp.

38 : ScriptedTrade("PerformanceOption_01") {}
ScriptedTrade(const std::string &tradeType="ScriptedTrade", const Envelope &env=Envelope())

◆ PerformanceOption_01() [2/2]

PerformanceOption_01 ( const Envelope env,
const string &  notionalAmount,
const string &  participationRate,
const string &  valuationDate,
const string &  settlementDate,
const vector< QuantLib::ext::shared_ptr< Underlying > > &  underlyings,
const vector< string > &  strikePrices,
const string &  strike,
const bool  strikeIncluded,
const string &  position,
const string &  payCcy,
const QuantLib::ext::shared_ptr< Conventions > &  conventions = nullptr 
)

Definition at line 39 of file performanceoption_01.hpp.

44 : ScriptedTrade("PerformanceOption_01", env), notionalAmount_(notionalAmount),
45 participationRate_(participationRate), valuationDate_(valuationDate), settlementDate_(settlementDate),
46 underlyings_(underlyings), strikePrices_(strikePrices), strike_(strike), strikeIncluded_(strikeIncluded),
47 position_(position), payCcy_(payCcy) {
49 }
vector< QuantLib::ext::shared_ptr< Underlying > > underlyings_
+ Here is the call graph for this function:

Member Function Documentation

◆ build()

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

Build QuantLib/QuantExt instrument, link pricing engine. If build() is called multiple times, reset() should be called between these calls.

Implements Trade.

Definition at line 27 of file performanceoption_01.cpp.

27 {
28
29 // set script parameters
30
31 clear();
33
34 numbers_.emplace_back("Number", "NotionalAmount", notionalAmount_);
35 numbers_.emplace_back("Number", "ParticipationRate", participationRate_);
36
37 events_.emplace_back("ValuationDate", valuationDate_);
38 events_.emplace_back("SettlementDate", settlementDate_);
39
40 numbers_.emplace_back("Number", "StrikePrices", strikePrices_);
41
42 numbers_.emplace_back("Number", "Strike", strike_);
43
44 Position::Type position = parsePositionType(position_);
45 numbers_.emplace_back("Number", "LongShort", position == Position::Long ? "1" : "-1");
46
47 currencies_.emplace_back("Currency", "PayCcy", payCcy_);
48
49 // set product tag
50
51 productTag_ = "MultiAssetOption({AssetClass})";
52
53 // set script
54
55 // clang-format off
56 script_ = {{"", ScriptedTradeScriptData(std::string("NUMBER i, p, currentNotional;\n") +
57 "FOR i IN (1, SIZE(Underlyings), 1) DO\n" +
58 (strikeIncluded_ ? " p = p + Weights[i] * ( Underlyings[i](ValuationDate) / StrikePrices[i] - Strike );\n" :
59 " p = p + Weights[i] * Underlyings[i](ValuationDate) / StrikePrices[i];\n") +
60 "END;\n"
61 "Option = LOGPAY( LongShort * NotionalAmount * ParticipationRate *\n" +
62 (strikeIncluded_ ? " max( p, 0 ), ValuationDate, SettlementDate, PayCcy );\n" :
63 " max( p - Strike, 0 ), ValuationDate, SettlementDate, PayCcy );\n") +
64 "currentNotional = NotionalAmount * ParticipationRate;\n",
65 "Option", {{"currentNotional", "currentNotional"}, {"notionalCurrency", "PayCcy"}}, {})}};
66 // clang-format on
67
68 // build trade
69
70 ScriptedTrade::build(factory);
71}
std::vector< ScriptedTradeEventData > events_
std::vector< ScriptedTradeValueTypeData > currencies_
std::vector< ScriptedTradeValueTypeData > numbers_
std::map< std::string, ScriptedTradeScriptData > script_
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
+ Here is the call graph for this function:

◆ setIsdaTaxonomyFields()

void setIsdaTaxonomyFields ( )
overridevirtual

Reimplemented from ScriptedTrade.

Definition at line 73 of file performanceoption_01.cpp.

73 {
75
76 // ISDA taxonomy
77 // asset class set in the base class already
78 std::string assetClass = boost::any_cast<std::string>(additionalData_["isdaAssetClass"]);
79 if (assetClass == "Equity") {
80 additionalData_["isdaBaseProduct"] = string("Other");
81 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
82 } else if (assetClass == "Commodity") {
83 // isda taxonomy missing for this class, using the same as equity
84 additionalData_["isdaBaseProduct"] = string("Other");
85 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
86 } else if (assetClass == "Foreign Exchange") {
87 additionalData_["isdaBaseProduct"] = string("Complex Exotic");
88 additionalData_["isdaSubProduct"] = string("Generic");
89 } else {
90 WLOG("ISDA taxonomy incomplete for trade " << id());
91 }
92 additionalData_["isdaTransaction"] = string("Basket");
93}
virtual void setIsdaTaxonomyFields()
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
+ Here is the call graph for this function:

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 106 of file performanceoption_01.cpp.

106 {
107 Trade::fromXML(node);
108 XMLNode* tradeDataNode = XMLUtils::getChildNode(node, "PerformanceOption01Data");
109 QL_REQUIRE(tradeDataNode, "PerformanceOption01Data node not found");
110 notionalAmount_ = XMLUtils::getChildValue(tradeDataNode, "NotionalAmount", true);
111 participationRate_ = XMLUtils::getChildValue(tradeDataNode, "ParticipationRate", true);
112 valuationDate_ = XMLUtils::getChildValue(tradeDataNode, "ValuationDate", true);
113 settlementDate_ = XMLUtils::getChildValue(tradeDataNode, "SettlementDate", true);
114 auto underlyingsNode = XMLUtils::getChildNode(tradeDataNode, "Underlyings");
115 QL_REQUIRE(underlyingsNode, "No Underlyings node");
116 auto underlyings = XMLUtils::getChildrenNodes(underlyingsNode, "Underlying");
117 for (auto const& n : underlyings) {
118 UnderlyingBuilder underlyingBuilder;
119 underlyingBuilder.fromXML(n);
120 underlyings_.push_back(underlyingBuilder.underlying());
121 }
122 strikePrices_ = XMLUtils::getChildrenValues(tradeDataNode, "StrikePrices", "StrikePrice", true);
123 strike_ = XMLUtils::getChildValue(tradeDataNode, "Strike", true);
124 strikeIncluded_ = XMLUtils::getChildValueAsBool(tradeDataNode, "StrikeIncluded", false, true);
125 position_ = XMLUtils::getChildValue(tradeDataNode, "Position", true);
126 payCcy_ = XMLUtils::getChildValue(tradeDataNode, "PayCcy", true);
127 initIndices();
128}
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 string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
Definition: xmlutils.cpp:277
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
Definition: xmlutils.cpp:296
static XMLNode * getChildNode(XMLNode *n, const string &name="")
Definition: xmlutils.cpp:387
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
Definition: xmlutils.cpp:306
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 130 of file performanceoption_01.cpp.

130 {
131 XMLNode* node = Trade::toXML(doc);
132 XMLNode* tradeNode = doc.allocNode("PerformanceOption01Data");
133 XMLUtils::appendNode(node, tradeNode);
134 XMLUtils::addChild(doc, tradeNode, "NotionalAmount", notionalAmount_);
135 XMLUtils::addChild(doc, tradeNode, "ParticipationRate", participationRate_);
136 XMLUtils::addChild(doc, tradeNode, "ValuationDate", valuationDate_);
137 XMLUtils::addChild(doc, tradeNode, "SettlementDate", settlementDate_);
138 XMLNode* underlyingsNode = doc.allocNode("Underlyings");
139 XMLUtils::appendNode(tradeNode, underlyingsNode);
140 for (auto& n : underlyings_) {
141 XMLUtils::appendNode(underlyingsNode, n->toXML(doc));
142 }
143 XMLUtils::addChildren(doc, tradeNode, "StrikePrices", "StrikePrice", strikePrices_);
144 XMLUtils::addChild(doc, tradeNode, "Strike", strike_);
145 XMLUtils::addChild(doc, tradeNode, "StrikeIncluded", strikeIncluded_);
146 XMLUtils::addChild(doc, tradeNode, "Position", position_);
147 XMLUtils::addChild(doc, tradeNode, "PayCcy", payCcy_);
148 return node;
149}
virtual XMLNode * toXML(XMLDocument &doc) const override
Definition: trade.cpp:46
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
Definition: xmlutils.cpp:502
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:

◆ initIndices()

void initIndices ( )
private

Definition at line 95 of file performanceoption_01.cpp.

95 {
96 std::vector<std::string> underlyingNames, weights;
97 for (auto const& u : underlyings_) {
98 underlyingNames.push_back(scriptedIndexName(u));
99 QL_REQUIRE(u->weight() != Null<Real>(), "underlying '" << u->name() << "' has no weight");
100 weights.push_back(boost::lexical_cast<std::string>(u->weight()));
101 }
102 indices_.emplace_back("Index", "Underlyings", underlyingNames);
103 numbers_.emplace_back("Number", "Weights", weights);
104}
std::vector< ScriptedTradeValueTypeData > indices_
QL_DEPRECATED_ENABLE_WARNING std::string scriptedIndexName(const QuantLib::ext::shared_ptr< Underlying > &underlying)
Definition: utilities.cpp:614
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ notionalAmount_

string notionalAmount_
private

Definition at line 57 of file performanceoption_01.hpp.

◆ participationRate_

string participationRate_
private

Definition at line 57 of file performanceoption_01.hpp.

◆ valuationDate_

string valuationDate_
private

Definition at line 57 of file performanceoption_01.hpp.

◆ settlementDate_

string settlementDate_
private

Definition at line 57 of file performanceoption_01.hpp.

◆ underlyings_

vector<QuantLib::ext::shared_ptr<Underlying> > underlyings_
private

Definition at line 58 of file performanceoption_01.hpp.

◆ strikePrices_

vector<string> strikePrices_
private

Definition at line 59 of file performanceoption_01.hpp.

◆ strike_

string strike_
private

Definition at line 60 of file performanceoption_01.hpp.

◆ strikeIncluded_

bool strikeIncluded_ = true
private

Definition at line 61 of file performanceoption_01.hpp.

◆ position_

string position_
private

Definition at line 62 of file performanceoption_01.hpp.

◆ payCcy_

string payCcy_
private

Definition at line 62 of file performanceoption_01.hpp.