Engine icon indicating copy to clipboard operation
Engine copied to clipboard

`CrossCcySwap` members like `inCcyLegNPV_` not initialized in some constructors

Open paolodelia99 opened this issue 6 months ago • 2 comments

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?

paolodelia99 avatar Jun 09 '25 09:06 paolodelia99

Thanks. We will fix this and push it to GitHub in the next days.

mgroncki avatar Jun 12 '25 11:06 mgroncki

This will be fixed in the upcoming 1.8.13.1 release

pcaspers avatar Jun 19 '25 08:06 pcaspers