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

Serializable Equity Swap contract. More...

#include <ored/portfolio/equityswap.hpp>

+ Inheritance diagram for EquitySwap:
+ Collaboration diagram for EquitySwap:

Public Member Functions

 EquitySwap ()
 Default constructor. More...
 
 EquitySwap (const Envelope &env, const vector< LegData > &legData)
 Constructor with vector of LegData. More...
 
 EquitySwap (const Envelope &env, const LegData &leg0, const LegData &leg1)
 Constructor with two legs. More...
 
void checkEquitySwap (const vector< LegData > &legData)
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Trade interface. More...
 
void setIsdaTaxonomyFields () 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
 
- Public Member Functions inherited from Swap
 Swap (const string swapType="Swap")
 Default constructor. More...
 
 Swap (const Envelope &env, const string swapType="Swap")
 
 Swap (const Envelope &env, const vector< LegData > &legData, const string swapType="Swap", const std::string settlement="Physical")
 Constructor with vector of LegData. More...
 
 Swap (const Envelope &env, const LegData &leg0, const LegData &leg1, const string swapType="Swap", const std::string settlement="Physical")
 Constructor with two legs. More...
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Build QuantLib/QuantExt instrument, link pricing engine. More...
 
virtual void setIsdaTaxonomyFields ()
 
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
 
std::map< AssetClass, std::set< std::string > > underlyingIndices (const QuantLib::ext::shared_ptr< ReferenceDataManager > &referenceDataManager=nullptr) const override
 Add underlying index names. More...
 
const string & settlement () const
 Settlement Type can be set to "Cash" for NDF. Default value is "Physical". More...
 
virtual void fromXML (XMLNode *node) override
 
virtual XMLNodetoXML (XMLDocument &doc) const override
 
const vector< LegData > & legData () const
 
const std::map< std::string, boost::any > & additionalData () const override
 returns all additional data returned by the trade once built More...
 
- 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...
 
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

Size equityLegIndex_
 
Size irLegIndex_
 

Additional Inherited Members

- Protected Member Functions inherited from Swap
virtual QuantLib::ext::shared_ptr< LegDatacreateLegData () const
 
- 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 Swap
vector< LegDatalegData_
 
string settlement_
 
bool isXCCY_ = false
 
- 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 Swap contract.

Definition at line 37 of file equityswap.hpp.

Constructor & Destructor Documentation

◆ EquitySwap() [1/3]

Default constructor.

Definition at line 40 of file equityswap.hpp.

40: Swap("EquitySwap") {}

◆ EquitySwap() [2/3]

EquitySwap ( const Envelope env,
const vector< LegData > &  legData 
)

Constructor with vector of LegData.

Definition at line 28 of file equityswap.cpp.

28: Swap(env, legData, "EquitySwap") {}
const vector< LegData > & legData() const
Definition: swap.hpp:74

◆ EquitySwap() [3/3]

EquitySwap ( const Envelope env,
const LegData leg0,
const LegData leg1 
)

Constructor with two legs.

Definition at line 30 of file equityswap.cpp.

31 : Swap(env, leg0, leg1, "EquitySwap") {}

Member Function Documentation

◆ checkEquitySwap()

void checkEquitySwap ( const vector< LegData > &  legData)

Definition at line 33 of file equityswap.cpp.

33 {
34 // An Equity Swap must have 2 legs - 1 an Equity Leg and the other an IR Leg either Fixed or Floating
35 equityLegIndex_ = Null<Size>();
36 irLegIndex_ = Null<Size>();
37 for (Size i = 0; i < legData.size(); ++i) {
38 if (legData[i].legType() == "Equity") {
40 } else {
41 irLegIndex_ = i;
42 }
43 }
44 QL_REQUIRE((legData.size() == 2) && equityLegIndex_ != Null<Size>() && irLegIndex_ != Null<Size>(),
45 "An Equity Swap must have 2 legs, an Equity Leg and an IR Leg - Trade: " + id());
46}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ build()

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

Trade interface.

Reimplemented from Swap.

Definition at line 48 of file equityswap.cpp.

48 {
49
50 DLOG("EquitySwap::build() called for " << id());
51
53
54 QL_REQUIRE(equityLegIndex_ < legData_.size(), "equityLegIndex (" << equityLegIndex_
55 << ") out of range, legData has size "
56 << legData_.size() << ", this is unexpected");
57 QL_REQUIRE(irLegIndex_ < legData_.size(), "equityLegIndex (" << irLegIndex_ << ") out of range, legData has size "
58 << legData_.size() << ", this is unexpected");
59
60 // 1 add indexing data from the equity leg, if this is desired
61
62 auto eqLegData = QuantLib::ext::dynamic_pointer_cast<EquityLegData>(legData_[equityLegIndex_].concreteLegData());
63 QL_REQUIRE(eqLegData, "could not cast to EquityLegData for equity leg in equity swap, this is unexpected");
64
65 if (legData_[irLegIndex_].indexingFromAssetLeg() && eqLegData->notionalReset()) {
66 DLOG("adding indexing information from equity leg to funding leg");
67
68 // build valuation schedule
69 std::vector<string> valuationDates;
70 auto legBuilder = engineFactory->legBuilder(legData_[equityLegIndex_].legType());
71 RequiredFixings dummy;
72 Leg tmpEqLeg = legBuilder->buildLeg(legData_[equityLegIndex_], engineFactory, dummy,
73 engineFactory->configuration(MarketContext::pricing));
74 for (Size i = 0; i < tmpEqLeg.size(); ++i) {
75 auto eqCpn = QuantLib::ext::dynamic_pointer_cast<QuantExt::EquityCoupon>(tmpEqLeg[i]);
76 QL_REQUIRE(eqCpn, "EquitySwap::build(): expected EquityCoupon on equity leg, this is unexpected");
77 valuationDates.push_back(ore::data::to_string(eqCpn->fixingStartDate()));
78 if (i == tmpEqLeg.size() - 1)
79 valuationDates.push_back(ore::data::to_string(eqCpn->fixingEndDate()));
80 }
81 ScheduleData valuationSchedule(ScheduleDates("", "", "", valuationDates, ""));
82
83 // add equity indexing
84 QL_REQUIRE(eqLegData->quantity() != Null<Real>(),
85 "indexing can only be added to funding leg, if quantity is given on equity leg");
86 Indexing eqIndexing("EQ-" + eqLegData->eqName(), "", false, false, false, eqLegData->quantity(),
87 eqLegData->initialPrice(), Null<Real>(), valuationSchedule, 0, "", "U", false);
88 legData_[irLegIndex_].indexing().push_back(eqIndexing);
89
90 // add fx indexing, if applicable
91 if (!eqLegData->fxIndex().empty()) {
92 Real initialFxFixing = Null<Real>();
93 // if the eq leg has an initial price and this is in the eq leg currency, we do not want an FX conversion
94 // for this price
95 if (!eqLegData->initialPriceCurrency().empty() &&
96 eqLegData->initialPriceCurrency() == legData_[equityLegIndex_].currency() &&
97 eqLegData->initialPrice() != Null<Real>())
98 initialFxFixing = 1.0;
99 Indexing fxIndexing(eqLegData->fxIndex(), "", false, false, false, 1.0, initialFxFixing, Null<Real>(),
100 valuationSchedule, 0, "", "U", false);
101 legData_[irLegIndex_].indexing().push_back(fxIndexing);
102 }
103
104 // set notional node to 1.0
105 legData_[irLegIndex_].notionals() = std::vector<Real>(1, 1.0);
106 legData_[irLegIndex_].notionalDates() = std::vector<std::string>();
107
108 // reset flag that told us to pull the indexing information from the equity leg
109 legData_[irLegIndex_].indexingFromAssetLeg() = false;
110 }
111
112 // just underlying security; notionals and currencies are covered by the Swap class already
113 additionalData_["underlyingSecurityId"] = eqLegData->eqName();
114
115 // 2 now build the swap using the updated leg data
116
117 Swap::build(engineFactory);
118}
void checkEquitySwap(const vector< LegData > &legData)
Definition: equityswap.cpp:33
vector< LegData > legData_
Definition: swap.hpp:82
virtual void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Definition: swap.cpp:45
std::map< std::string, boost::any > additionalData_
Definition: trade.hpp:224
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554
std::string to_string(const LocationInfo &l)
Definition: ast.cpp:28
+ Here is the call graph for this function:

◆ setIsdaTaxonomyFields()

void setIsdaTaxonomyFields ( )
overridevirtual

Reimplemented from Swap.

Definition at line 120 of file equityswap.cpp.

120 {
122
123 // ISDA taxonomy
124 additionalData_["isdaAssetClass"] = string("Equity");
125 additionalData_["isdaBaseProduct"] = string("Swap");
126 additionalData_["isdaSubProduct"] = string("Price Return Basic Performance");
127 // skip the transaction level mapping for now
128 additionalData_["isdaTransaction"] = string("");
129}
virtual void setIsdaTaxonomyFields()
Definition: swap.cpp:220
+ 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 131 of file equityswap.cpp.

131 {
132 Date asof = Settings::instance().evaluationDate();
133 for (auto const& c : legs_[equityLegIndex_]) {
134 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<QuantExt::EquityCoupon>(c)) {
135 if (c->date() > asof)
136 return cpn->nominal();
137 }
138 }
139 ALOG("Error retrieving current notional for equity swap " << id() << " as of " << io::iso_date(asof));
140 return Null<Real>();
141}
std::vector< QuantLib::Leg > legs_
Definition: trade.hpp:198
#define ALOG(text)
Logging Macro (Level = Alert)
Definition: log.hpp:544

◆ notionalCurrency()

std::string notionalCurrency ( ) const
overridevirtual

Reimplemented from Trade.

Definition at line 143 of file equityswap.cpp.

143 {
144 // try to get the notional ccy from the additional results of the instrument
145 if (legCurrencies_.size() > equityLegIndex_)
147 else
148 return Swap::notionalCurrency();
149}
std::string notionalCurrency() const override
Definition: swap.cpp:286
std::vector< string > legCurrencies_
Definition: trade.hpp:199
+ Here is the call graph for this function:

Member Data Documentation

◆ equityLegIndex_

Size equityLegIndex_
private

Definition at line 57 of file equityswap.hpp.

◆ irLegIndex_

Size irLegIndex_
private

Definition at line 57 of file equityswap.hpp.