Skip to content

Simplify SwaptionVolatilityCube::atmStrike() using SwapIndex::clone(tenor) - #2849

Open
Nityahapani wants to merge 1 commit into
lballabio:masterfrom
Nityahapani:refactor/swaptionvolcube-use-clone-for-atmstrike
Open

Nityahapani wants to merge 1 commit into
lballabio:masterfrom
Nityahapani:refactor/swaptionvolcube-use-clone-for-atmstrike

Conversation

@Nityahapani

Copy link
Copy Markdown

atmStrike() built temporary SwapIndex objects by spelling out every constructor argument (familyName, fixingDays, currency, calendar, fixedLegTenor, convention, dayCounter, iborIndex) manually, with a separate branch for the exogenousDiscount case, totalling ~50 lines and a FIXME comment:

// FIXME use a familyName-based index factory

SwapIndex already provides exactly this: clone(const Period& tenor) returns a copy of the index with a different tenor while preserving all other attributes — including the discount curve when exogenousDiscount is true. The virtual dispatch also means subclasses of SwapIndex (e.g. EuriborSwapIsdaFixA, OvernightIndexedSwapIndex) correctly clone themselves rather than being silently downcast to a plain SwapIndex.

Replace the four constructor branches with:

const SwapIndex* base = (swapTenor > shortSwapIndexBase_->tenor())
                            ? swapIndexBase_.get()
                            : shortSwapIndexBase_.get();
return base->clone(swapTenor)->fixing(optionD);

No behaviour change for standard SwapIndex; correctness improvement for any SwapIndex subclass stored in swapIndexBase_ or shortSwapIndexBase_.

…enor)

atmStrike() built temporary SwapIndex objects by spelling out every
constructor argument (familyName, fixingDays, currency, calendar,
fixedLegTenor, convention, dayCounter, iborIndex) manually, with a
separate branch for the exogenousDiscount case, totalling ~50 lines and
a FIXME comment:

    // FIXME use a familyName-based index factory

SwapIndex already provides exactly this: clone(const Period& tenor)
returns a copy of the index with a different tenor while preserving all
other attributes — including the discount curve when exogenousDiscount
is true. The virtual dispatch also means subclasses of SwapIndex (e.g.
EuriborSwapIsdaFixA, OvernightIndexedSwapIndex) correctly clone
themselves rather than being silently downcast to a plain SwapIndex.

Replace the four constructor branches with:

    const SwapIndex* base = (swapTenor > shortSwapIndexBase_->tenor())
                                ? swapIndexBase_.get()
                                : shortSwapIndexBase_.get();
    return base->clone(swapTenor)->fixing(optionD);

No behaviour change for standard SwapIndex; correctness improvement for
any SwapIndex subclass stored in swapIndexBase_ or shortSwapIndexBase_.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant