@@ -42,6 +42,9 @@ using std::make_pair;
4242namespace ore {
4343namespace data {
4444
45+
46+
47+
4548void Swap::build (const boost::shared_ptr<EngineFactory>& engineFactory) {
4649 DLOG (" Swap::build() called for trade " << id ());
4750
@@ -55,6 +58,7 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
5558 Size numLegs = legData_.size ();
5659 legPayers_ = vector<bool >(numLegs);
5760 std::vector<QuantLib::Currency> currencies (numLegs);
61+ std::vector<QuantLib::Currency> underlyingCurrencies (numLegs);
5862 legs_.resize (numLegs);
5963
6064 isXCCY_ = false ;
@@ -67,11 +71,31 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
6771 currencies[i] = parseCurrencyWithMinors (legData_[i].currency ());
6872 else
6973 currencies[i] = parseCurrency (legData_[i].currency ());
74+
7075 if (currencies[i] != currency)
7176 isXCCY_ = true ;
7277 isResetting_ = isResetting_ || (!legData_[i].isNotResetXCCY ());
7378 }
7479
80+
81+ // Check if there is indexing is used for NDF, needed for AMC
82+ for (Size i = 0 ; i < numLegs; ++i) {
83+ underlyingCurrencies[i] = currencies[i];
84+ if (tradeType_ == " CrossCurrencySwap" && !isXCCY_) {
85+ vector<Indexing> indexings = legData_[i].indexing ();
86+ if (!indexings.empty () && indexings.front ().hasData ()) {
87+ Indexing indexing = indexings.front ();
88+ if (boost::starts_with (indexing.index (), " FX-" )) {
89+ auto index = parseFxIndex (indexing.index ());
90+ Currency srcCurrency = index->sourceCurrency ();
91+ Currency tgtCurrency = index->targetCurrency ();
92+ underlyingCurrencies[i] = currency == srcCurrency ? tgtCurrency : srcCurrency;
93+ isXCCY_ = true ;
94+ }
95+ }
96+ }
97+ }
98+
7599 static std::set<std::string> eligibleForXbs = {" Fixed" , " Floating" };
76100 bool useXbsCurves = true ;
77101 for (Size i=0 ;i<numLegs;++i) {
@@ -151,7 +175,7 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
151175 boost::shared_ptr<CrossCurrencySwapEngineBuilderBase> swapBuilder =
152176 boost::dynamic_pointer_cast<CrossCurrencySwapEngineBuilderBase>(builder);
153177 QL_REQUIRE (swapBuilder, " No Builder found for CrossCurrencySwap " << id ());
154- swap->setPricingEngine (swapBuilder->engine (currencies , npvCcy));
178+ swap->setPricingEngine (swapBuilder->engine (underlyingCurrencies , npvCcy));
155179 // take the first legs currency as the npv currency (arbitrary choice)
156180 instrument_.reset (new VanillaInstrument (swap));
157181 } else {
0 commit comments