@@ -58,7 +58,7 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
5858 Size numLegs = legData_.size ();
5959 legPayers_ = vector<bool >(numLegs);
6060 std::vector<QuantLib::Currency> currencies (numLegs);
61- std::vector<QuantLib::Currency> underlyingCurrencies (numLegs) ;
61+ std::vector<QuantLib::Currency> currenciesForMcSimulation ;
6262 legs_.resize (numLegs);
6363
6464 isXCCY_ = false ;
@@ -78,24 +78,29 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
7878 }
7979
8080
81- // Check if there is indexing is used for NDF, needed for AMC
81+ // Check if there is indexing is used, need to collect all underlying currrencies
82+ // for AMC simulations, such a trade needs to be treated a x-ccy swap with both leg paying
83+ // one currency.
84+ auto addUnique = [](vector<Currency>& currencies, Currency ccy) {
85+ if (std::find (currencies.begin (), currencies.end (), ccy) ==
86+ currencies.end ()) {
87+ currencies.push_back (ccy);
88+ }
89+ };
90+
8291 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- }
92+ addUnique (currenciesForMcSimulation, currencies[i]);
93+ vector<Indexing> indexings = legData_[i].indexing ();
94+ if (!indexings.empty () && indexings.front ().hasData ()) {
95+ Indexing indexing = indexings.front ();
96+ if (boost::starts_with (indexing.index (), " FX-" )) {
97+ auto index = parseFxIndex (indexing.index ());
98+ addUnique (currenciesForMcSimulation, index->targetCurrency ());
99+ addUnique (currenciesForMcSimulation, index->sourceCurrency ());
95100 }
96101 }
97102 }
98-
103+ isXCCY_ = isXCCY_ || currenciesForMcSimulation. size () > 1 ;
99104 static std::set<std::string> eligibleForXbs = {" Fixed" , " Floating" };
100105 bool useXbsCurves = true ;
101106 for (Size i=0 ;i<numLegs;++i) {
@@ -175,7 +180,7 @@ void Swap::build(const boost::shared_ptr<EngineFactory>& engineFactory) {
175180 boost::shared_ptr<CrossCurrencySwapEngineBuilderBase> swapBuilder =
176181 boost::dynamic_pointer_cast<CrossCurrencySwapEngineBuilderBase>(builder);
177182 QL_REQUIRE (swapBuilder, " No Builder found for CrossCurrencySwap " << id ());
178- swap->setPricingEngine (swapBuilder->engine (underlyingCurrencies , npvCcy));
183+ swap->setPricingEngine (swapBuilder->engine (currenciesForMcSimulation , npvCcy));
179184 // take the first legs currency as the npv currency (arbitrary choice)
180185 instrument_.reset (new VanillaInstrument (swap));
181186 } else {
0 commit comments