30 :
Swap(env, leg0, leg1,
"CrossCurrencySwap") {}
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-")) {
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-'")
48 Currency srcCurrency = index->sourceCurrency();
49 Currency tgtCurrency = index->targetCurrency();
51 if (legCcy != srcCurrency && legCcy != tgtCurrency) {
53 "Could not set fixed leg currency to Indexing currency for trade "
54 "validation. Expected the leg currency (" +
56 ") be equal to either of the currencies in the index (" +
57 indexing.
index() +
")")
62 legIndexCcy = legCcy == srcCurrency ? tgtCurrency : srcCurrency;
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")
74 QL_FAIL(
"CrossCurrencySwap leg #" << i + 1 <<
" must be Fixed, Floating or Cashflow");
76 QL_REQUIRE(legDataIdx.size() == 2,
77 "A Cross Currency Swap must have 2 legs that are either Fixed or Floating: " +
id());
79 const LegData& legData0 = legData_[legDataIdx[0]];
80 const LegData& legData1 = legData_[legDataIdx[1]];
88 if (legCcy0 == legCcy1) {
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());
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());
110 QL_REQUIRE(legIndexCcy0 != legIndexCcy1,
"Cross currency swap legs must have different currencies.");
114void CrossCurrencySwap::build(
const QuantLib::ext::shared_ptr<EngineFactory>& engineFactory) {
116 DLOG(
"CrossCurrencySwap::build() called for " <<
id());
118 Swap::build(engineFactory);
120 checkCrossCurrencySwap();
void checkCrossCurrencySwap()
CrossCurrencySwap()
Default constructor.
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding indexing data.
const string & index() const
void log() const
generate Boost log record to pass to corresponding sinks
Serializable object holding leg data.
const string & currency() const
const std::vector< Indexing > & indexing() const
const string & legType() const
QuantLib::ext::shared_ptr< LegAdditionalData > concreteLegData() const
Utility classes for Structured warnings, contains the Trade ID and Type.
Serializable Swap, Single and Cross Currency.
Cross Currency Swap data model and serialization.
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.
Map text representations to QuantLib/QuantExt types.
#define DLOG(text)
Logging Macro (Level = Debug)
Serializable Credit Default Swap.
Classes for structured trade warnings.