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

Serializable Cross Currency Swap contract. More...

#include <ored/portfolio/crosscurrencyswap.hpp>

+ Inheritance diagram for CrossCurrencySwap:
+ Collaboration diagram for CrossCurrencySwap:

Public Member Functions

 CrossCurrencySwap ()
 Default constructor. More...
 
 CrossCurrencySwap (const Envelope &env, const vector< LegData > &legData)
 Constructor with vector of LegData. More...
 
 CrossCurrencySwap (const Envelope &env, const LegData &leg0, const LegData &leg1)
 Constructor with two legs. More...
 
void checkCrossCurrencySwap ()
 
virtual void build (const QuantLib::ext::shared_ptr< EngineFactory > &) override
 Trade interface. More...
 
- 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...
 

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 Cross Currency Swap contract.

Definition at line 37 of file crosscurrencyswap.hpp.

Constructor & Destructor Documentation

◆ CrossCurrencySwap() [1/3]

Default constructor.

Definition at line 40 of file crosscurrencyswap.hpp.

40: Swap("CrossCurrencySwap") {}

◆ CrossCurrencySwap() [2/3]

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

Constructor with vector of LegData.

Definition at line 27 of file crosscurrencyswap.cpp.

27: Swap(env, legData, "CrossCurrencySwap") {}

◆ CrossCurrencySwap() [3/3]

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

Constructor with two legs.

Definition at line 29 of file crosscurrencyswap.cpp.

30 : Swap(env, leg0, leg1, "CrossCurrencySwap") {}

Member Function Documentation

◆ checkCrossCurrencySwap()

void checkCrossCurrencySwap ( )

Definition at line 32 of file crosscurrencyswap.cpp.

32 {
33 // This function will attempt to set legIndexCcy to the other ccy from the first Indexing index.
34 auto getIndexingCurrency = [this](const LegData& legData, const Currency& legCcy, Currency& legIndexCcy) {
35 vector<Indexing> indexings = legData.indexing();
36 if (!indexings.empty() && indexings.front().hasData()) {
37 Indexing indexing = indexings.front();
38 if (!boost::starts_with(indexing.index(), "FX-")) {
39 StructuredTradeWarningMessage(
40 tradeType(), id(), "Trade validation (checkCrossCurrencySwap)",
41 "Could not set fixed leg currency to Indexing currency for trade validation. Index (" +
42 indexing.index() + ") should start with 'FX-'")
43 .log();
44 return;
45 }
46
47 auto index = parseFxIndex(indexing.index());
48 Currency srcCurrency = index->sourceCurrency();
49 Currency tgtCurrency = index->targetCurrency();
50
51 if (legCcy != srcCurrency && legCcy != tgtCurrency) {
52 StructuredTradeWarningMessage(tradeType(), id(), "Trade validation (checkCrossCurrencySwap)",
53 "Could not set fixed leg currency to Indexing currency for trade "
54 "validation. Expected the leg currency (" +
55 legCcy.code() +
56 ") be equal to either of the currencies in the index (" +
57 indexing.index() + ")")
58 .log();
59 return;
60 }
61
62 legIndexCcy = legCcy == srcCurrency ? tgtCurrency : srcCurrency;
63 }
64 };
65
66 // Cross Currency Swap legs must be either Fixed, Floating or Cashflow and exactly two of Fixed and/or Floating
67 vector<Size> legDataIdx;
68 for (Size i = 0; i < legData_.size(); i++) {
69 if (legData_[i].legType() == "Fixed" || legData_[i].legType() == "Floating")
70 legDataIdx.push_back(i);
71 else if (legData_[i].legType() == "Cashflow")
72 continue;
73 else
74 QL_FAIL("CrossCurrencySwap leg #" << i + 1 << " must be Fixed, Floating or Cashflow");
75 }
76 QL_REQUIRE(legDataIdx.size() == 2,
77 "A Cross Currency Swap must have 2 legs that are either Fixed or Floating: " + id());
78
79 const LegData& legData0 = legData_[legDataIdx[0]];
80 const LegData& legData1 = legData_[legDataIdx[1]];
81
82 // Check leg currencies
83 const Currency legCcy0 = parseCurrencyWithMinors(legData0.currency());
84 const Currency legCcy1 = parseCurrencyWithMinors(legData1.currency());
85
86 // Require leg currencies to be different. If they are the same, we do a further check of the underlying currencies
87 // (Indexings for Fixed leg; Floating leg index for Floating leg) and compare these.
88 if (legCcy0 == legCcy1) {
89
90 // Get relevant index currency for the first leg - defaults to the leg ccy
91 Currency legIndexCcy0 = legCcy0;
92 if (legData0.legType() == "Fixed") {
93 getIndexingCurrency(legData0, legCcy0, legIndexCcy0);
94 } else if (legData0.legType() == "Floating") {
95 auto floatingLeg = QuantLib::ext::dynamic_pointer_cast<FloatingLegData>(legData0.concreteLegData());
96 if (floatingLeg)
97 legIndexCcy0 = parseIborIndex(floatingLeg->index())->currency();
98 }
99
100 // Get relevant index currency for the second leg - defaults to the leg ccy
101 Currency legIndexCcy1 = legCcy1;
102 if (legData1.legType() == "Fixed") {
103 getIndexingCurrency(legData1, legCcy1, legIndexCcy1);
104 } else if (legData1.legType() == "Floating") {
105 auto floatingLeg = QuantLib::ext::dynamic_pointer_cast<FloatingLegData>(legData1.concreteLegData());
106 if (floatingLeg)
107 legIndexCcy1 = parseIborIndex(floatingLeg->index()) ->currency();
108 }
109
110 QL_REQUIRE(legIndexCcy0 != legIndexCcy1, "Cross currency swap legs must have different currencies.");
111 }
112}
const vector< LegData > & legData() const
Definition: swap.hpp:74
vector< LegData > legData_
Definition: swap.hpp:82
const string & tradeType() const
Definition: trade.hpp:133
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
QuantLib::ext::shared_ptr< FxIndex > parseFxIndex(const string &s, const Handle< Quote > &fxSpot, const Handle< YieldTermStructure > &sourceYts, const Handle< YieldTermStructure > &targetYts, const bool useConventions)
Convert std::string to QuantExt::FxIndex.
Currency parseCurrencyWithMinors(const string &s)
Convert text to QuantLib::Currency.
Definition: parsers.cpp:310
+ Here is the call graph for this function:

◆ build()

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

Trade interface.

Reimplemented from Swap.

Definition at line 114 of file crosscurrencyswap.cpp.

114 {
115
116 DLOG("CrossCurrencySwap::build() called for " << id());
117
118 Swap::build(engineFactory);
119
121}
#define DLOG(text)
Logging Macro (Level = Debug)
Definition: log.hpp:554