`CrossCcySwap` members like `inCcyLegNPV_` not initialized in some constructors
Hi ORE team,
I noticed that the following constructors of CrossCcySwap do not initialize internal members like inCcyLegNPV_, inCcyLegBPS_, and npvDateDiscounts_:
CrossCcySwap(const Leg& firstLeg, const Currency& firstLegCcy,
const Leg& secondLeg, const Currency& secondLegCcy);
CrossCcySwap(const std::vector<Leg>& legs, const std::vector<bool>& payer,
const std::vector<Currency>& currencies);
This causes a runtime error when calling NPV() after assigning a pricing engine, for example:
Rate spotFx = 1.22;
Leg usdLeg, chfLeg;
// ... build usdLeg ...
// ... build chfLeg ...
auto xccy = ext::make_shared<CrossCcySwap>(usdLeg, USDCurrency(), chfLeg, CHFCurrency());
auto fxSpotQuote = Handle<Quote>(ext::make_shared<SimpleQuote>(1.0 / spotFx));
auto engine = ext::make_shared<CrossCcySwapEngine>(
USDCurrency(), usdDiscountCurve(),
CHFCurrency(), chfDiscountCurve(),
fxSpotQuote
);
xccy->setPricingEngine(engine);
Real npv = xccy->NPV(); // Throws: Wrong number of in-currency leg NPVs returned by engine
This happens (when fetchResults is executed) because the CrossCcySwapEngine returns a vector of leg NPVs, but internally the swap has no pre-initialized storage for inCcyLegNPV_, causing a mismatch in expected vs. actual size.
Is this lack of initialization intentional or was it an oversight? Should those members be initialized similarly to the constructor that takes Size legs as input?
Thanks. We will fix this and push it to GitHub in the next days.
This will be fixed in the upcoming 1.8.13.1 release