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

Serializable Equity Forward contract. More...

#include <ored/portfolio/equityforward.hpp>

+ Inheritance diagram for EquityForward:
+ Collaboration diagram for EquityForward:

Public Member Functions

 EquityForward ()
 
 EquityForward (Envelope &env, string longShort, EquityUnderlying equityUnderlying, string currency, QuantLib::Real quantity, string maturityDate, QuantLib::Real strike, string strikeCurrency="")
 
void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying Equity names. More...
 
string longShort ()
 
const string & eqName () const
 
string currency ()
 
double quantity ()
 
string maturityDate ()
 
double strike ()
 
string strikeCurrency ()
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (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 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...
 
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 Attributes

string longShort_
 
EquityUnderlying equityUnderlying_
 
string currency_
 
QuantLib::Real quantity_
 
string maturityDate_
 
QuantLib::Real strike_
 
string strikeCurrency_
 

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 Equity Forward contract.

Definition at line 38 of file equityforward.hpp.

Constructor & Destructor Documentation

◆ EquityForward() [1/2]

Definition at line 40 of file equityforward.hpp.

40: Trade("EquityForward"), quantity_(0.0), strike_(0.0) {}
Trade()
Default constructor.
Definition: trade.hpp:59

◆ EquityForward() [2/2]

EquityForward ( Envelope env,
string  longShort,
EquityUnderlying  equityUnderlying,
string  currency,
QuantLib::Real  quantity,
string  maturityDate,
QuantLib::Real  strike,
string  strikeCurrency = "" 
)

Definition at line 41 of file equityforward.hpp.

43 : Trade("EquityForward", env), longShort_(longShort), equityUnderlying_(equityUnderlying), currency_(currency),
Position::Type longShort_
Date maturityDate() const
Position::Type longShort() const
Currency currency() const
EquityUnderlying equityUnderlying_
+ 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 39 of file equityforward.cpp.

39 {
40
41 // ISDA taxonomy
42 additionalData_["isdaAssetClass"] = string("Equity");
43 additionalData_["isdaBaseProduct"] = string("Forward");
44 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
45 // skip the transaction level mapping for now
46 additionalData_["isdaTransaction"] = string("");
47
48 additionalData_["strikeCurrency"] = strikeCurrency_;
49 additionalData_["quantity"] = quantity_;
50
51 Currency ccy = parseCurrencyWithMinors(currency_);
52
53 // convert strike to the major currency if needed
54 Real strike;
55 if (!strikeCurrency_.empty()) {
56 strike = convertMinorToMajorCurrency(strikeCurrency_, strike_);
57 // ensure strike currency matches equity currency
58 } else {
59 WLOG("No Strike Currency provide for trade " << id() << ", assuming trade currency " << ccy);
61 }
62 additionalData_["strike"] = strike;
63
64 QuantLib::Position::Type longShort = parsePositionType(longShort_);
66
67 string name = eqName();
68 additionalData_["underlyingSecurityId"] = name;
69
70 QuantLib::ext::shared_ptr<Instrument> inst =
71 QuantLib::ext::make_shared<QuantExt::EquityForward>(name, ccy, longShort, quantity_, maturity, strike);
72
73 // set up other Trade details
74 instrument_ = QuantLib::ext::shared_ptr<InstrumentWrapper>(new VanillaInstrument(inst));
75 npvCurrency_ = ccy.code();
77 // Notional - we really need todays spot to get the correct notional.
78 // But rather than having it move around we use strike * quantity
80 notionalCurrency_ = ccy.code();
81
82 // We check the ccys here at the end of the build to ensure that the rest of the build above
83 // (which does not require the market) runs first
84
85 // get the equity currency from the market
86 Currency equityCcy = engineFactory->market()->equityCurve(eqName())->currency();
87
88 // ensure forward currency matches the equity currency
89 QL_REQUIRE(!equityCcy.empty(), "No equity currency in equityCurve for equity " << eqName());
90 QL_REQUIRE(ccy == equityCcy, "EquityForward currency " << ccy << " does not match equity currency " << equityCcy << " for trade " << id());
91
92 if (!strikeCurrency_.empty()) {
93 Currency strikeCcy = parseCurrencyWithMinors(strikeCurrency_);
94 QL_REQUIRE(strikeCcy == equityCcy, "Strike currency " << ccy << " does not match equity currency " << equityCcy << " for trade " << id());
95 }
96
97 // Pricing engine
98 QuantLib::ext::shared_ptr<EngineBuilder> builder = engineFactory->builder(tradeType_);
99 QL_REQUIRE(builder, "No builder found for " << tradeType_);
100 QuantLib::ext::shared_ptr<EquityForwardEngineBuilder> eqFwdBuilder =
101 QuantLib::ext::dynamic_pointer_cast<EquityForwardEngineBuilder>(builder);
102 inst->setPricingEngine(eqFwdBuilder->engine(name, ccy));
103 setSensitivityTemplate(*eqFwdBuilder);
104}
const std::string & name() const
const string & eqName() const
string npvCurrency_
Definition: trade.hpp:201
QuantLib::Real notional_
Definition: trade.hpp:202
void setSensitivityTemplate(const EngineBuilder &builder)
Definition: trade.cpp:295
QuantLib::ext::shared_ptr< InstrumentWrapper > instrument_
Definition: trade.hpp:197
string notionalCurrency_
Definition: trade.hpp:203
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
QuantLib::Real convertMinorToMajorCurrency(const std::string &s, QuantLib::Real value)
Convert a value from a minor ccy to major.
Definition: parsers.cpp:324
Position::Type parsePositionType(const std::string &s)
Convert text to QuantLib::Position::Type.
Definition: parsers.cpp:404
#define WLOG(text)
Logging Macro (Level = Warning)
Definition: log.hpp:550
Time maturity
Definition: utilities.cpp:66
+ Here is the call 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 Equity names.

Reimplemented from Trade.

Definition at line 139 of file equityforward.cpp.

139 {
140 return {{AssetClass::EQ, std::set<std::string>({eqName()})}};
141}

◆ longShort()

string longShort ( )

Definition at line 52 of file equityforward.hpp.

52{ return longShort_; }

◆ eqName()

const string & eqName ( ) const

Definition at line 53 of file equityforward.hpp.

53{ return equityUnderlying_.name(); }
const std::string & name() const override
Definition: underlying.hpp:109
+ Here is the call graph for this function:

◆ currency()

string currency ( )

Definition at line 54 of file equityforward.hpp.

54{ return currency_; }

◆ quantity()

double quantity ( )

Definition at line 55 of file equityforward.hpp.

55{ return quantity_; }

◆ maturityDate()

string maturityDate ( )

Definition at line 56 of file equityforward.hpp.

56{ return maturityDate_; }

◆ strike()

double strike ( )

Definition at line 57 of file equityforward.hpp.

57{ return strike_; }

◆ strikeCurrency()

string strikeCurrency ( )

Definition at line 58 of file equityforward.hpp.

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

◆ fromXML()

void fromXML ( XMLNode node)
overridevirtual

Reimplemented from Trade.

Definition at line 106 of file equityforward.cpp.

106 {
107 Trade::fromXML(node);
108 XMLNode* eNode = XMLUtils::getChildNode(node, "EquityForwardData");
109
110 longShort_ = XMLUtils::getChildValue(eNode, "LongShort", true);
111 maturityDate_ = XMLUtils::getChildValue(eNode, "Maturity", true);
112 XMLNode* tmp = XMLUtils::getChildNode(eNode, "Underlying");
113 if (!tmp)
114 tmp = XMLUtils::getChildNode(eNode, "Name");
116 currency_ = XMLUtils::getChildValue(eNode, "Currency", true);
117 strike_ = XMLUtils::getChildValueAsDouble(eNode, "Strike", true);
118 strikeCurrency_ = XMLUtils::getChildValue(eNode, "StrikeCurrency", false);
119 quantity_ = XMLUtils::getChildValueAsDouble(eNode, "Quantity", true);
120}
void fromXML(XMLNode *node) override
Definition: underlying.cpp:81
rapidxml::xml_node< char > XMLNode
Definition: xmlutils.hpp:60

◆ toXML()

XMLNode * toXML ( XMLDocument doc) const
overridevirtual

Reimplemented from Trade.

Definition at line 122 of file equityforward.cpp.

122 {
123 XMLNode* node = Trade::toXML(doc);
124 XMLNode* eNode = doc.allocNode("EquityForwardData");
125 XMLUtils::appendNode(node, eNode);
126
127 XMLUtils::addChild(doc, eNode, "LongShort", longShort_);
128 XMLUtils::addChild(doc, eNode, "Maturity", maturityDate_);
129 XMLUtils::appendNode(eNode, equityUnderlying_.toXML(doc));
130 XMLUtils::addChild(doc, eNode, "Currency", currency_);
131 XMLUtils::addChild(doc, eNode, "Strike", strike_);
132 if (!strikeCurrency_.empty())
133 XMLUtils::addChild(doc, eNode, "StrikeCurrency", strikeCurrency_);
134 XMLUtils::addChild(doc, eNode, "Quantity", quantity_);
135 return node;
136}
XMLNode * toXML(XMLDocument &doc) const override
Definition: underlying.cpp:102
+ Here is the call graph for this function:

Member Data Documentation

◆ longShort_

string longShort_
private

Definition at line 64 of file equityforward.hpp.

◆ equityUnderlying_

EquityUnderlying equityUnderlying_
private

Definition at line 65 of file equityforward.hpp.

◆ currency_

string currency_
private

Definition at line 66 of file equityforward.hpp.

◆ quantity_

QuantLib::Real quantity_
private

Definition at line 67 of file equityforward.hpp.

◆ maturityDate_

string maturityDate_
private

Definition at line 68 of file equityforward.hpp.

◆ strike_

QuantLib::Real strike_
private

Definition at line 69 of file equityforward.hpp.

◆ strikeCurrency_

string strikeCurrency_
private

Definition at line 70 of file equityforward.hpp.