Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge DatedOISRateHelper with OISRateHelper #2103

Merged
merged 4 commits into from
Oct 25, 2024

Conversation

eltoder
Copy link
Contributor

@eltoder eltoder commented Oct 23, 2024

Add a second constructor overload to OISRateHelper which works like
DatedOISRateHelper. Deprecate DatedOISRateHelper.

This removes a lot of code duplication and also adds support for custom
pillar dates to DatedOISRateHelper's equivalent.

@eltoder eltoder force-pushed the feature/dated-ois-custom-pillar branch from b052a36 to b2654b6 Compare October 23, 2024 00:36
@coveralls
Copy link

coveralls commented Oct 23, 2024

Coverage Status

coverage: 72.786% (+0.002%) from 72.784%
when pulling 458f24b on eltoder:feature/dated-ois-custom-pillar
into 5ee8f89 on lballabio:master.

@lballabio
Copy link
Owner

lballabio commented Oct 23, 2024

Thanks! Is this compatible with #1912, or a subset of it, or alternative?

Also, it seems to me that the duplication (or the additional template base class) are there because we wanted to inherit OISRateHelper and DatedOISRateHelper from RelativeDateRateHelper and RateHelper, respectively, and that's just so that the relative-date helper can inherit 4 or 5 lines of code. What if we folded DatedOISRateHelper into OISRateHelper instead? It could be a single OISRateHelper class with two different constructors. It could inherit from RateHelper and copy a bit of missing behavior from RelativeDateRateHelper. If this works, we could consider doing away with RelativeDateRateHelper altogether. What do you think?

@eltoder
Copy link
Contributor Author

eltoder commented Oct 23, 2024

This is a subset of #1912 with a more self-contained and possibly slightly simpler implementation. The same approach can be used to add DatedSwapRateHelper as an alternative to #1912.

I don't think we need to copy-paste code from RelativeDateRateHelper, but what to do depends on what end state we want to have. If we want "relative" and "dated" helpers as separate classes, we can use the approach in this PR (a common base class template parametrized by its base class) or the approach from #1912 (a common base class which is not a template, but make RelativeDateRateHelper a template so it can be added on top of any base class). I think the latter is a bit better.

If we want "relative" and "dated" helpers to be different constructors in the same class, we can simply add a bool to RelativeDateRateHelper's constructor. I think this will just work, and it avoids the need for the common base class, so the code will be simpler. That said, I think this approach has a few downsides:

  1. OISRateHelper and DatedOISRateHelper have a lot of constructor arguments. In Python we use kwargs to pass only a few of them and have a much more readable syntax. Unfortunately, SWIG does not support kwargs on overloaded methods. Removing kwargs is also a breaking change for the existing code. So we will likely have to keep separate classes at least in SWIG for Python.
  2. We'll also have to keep DatedOISRateHelper in C++ for backwards compatibility at least for some time.
  3. This will make DatedOISRateHelper a bit less efficient (it does not need to store the arguments), but that's probably OK.

@eltoder
Copy link
Contributor Author

eltoder commented Oct 24, 2024

For the two classes solution another option is to use virtual base class and multiple inheritance instead of templates. I'm not sure if this is more easily understood and it has some run-time overhead.

@lballabio
Copy link
Owner

I'd try going for one class; it's the same instrument, having two classes was an accident of the implementation.

Drawback 1 can be addressed in the SWIG layer: instead of exporting the dated constructor directly, we can export it via a createDated static method we can add from SWIG. This way we have both constructors usable with kwargs. For drawback 2 we use the usual deprecation machinery. I wouldn't worry about 3.

@eltoder eltoder force-pushed the feature/dated-ois-custom-pillar branch from b2654b6 to 571caf4 Compare October 24, 2024 16:05
@eltoder eltoder changed the title Support custom pillar dates in DatedOISRateHelper Merge DatedOISRateHelper with OISRateHelper Oct 24, 2024
@eltoder eltoder force-pushed the feature/dated-ois-custom-pillar branch from 571caf4 to 9d9f90c Compare October 24, 2024 16:30
Add a second constructor overload to OISRateHelper which works like
DatedOISRateHelper. Deprecate DatedOISRateHelper.

This removes a lot of code duplication and also adds support for custom
pillar dates to DatedOISRateHelper's equivalent.
@eltoder eltoder force-pushed the feature/dated-ois-custom-pillar branch from 9d9f90c to 912c944 Compare October 24, 2024 16:52
@eltoder
Copy link
Contributor Author

eltoder commented Oct 24, 2024

@lballabio I merged DatedOISRateHelper with OISRateHelper and deprecated the former as discussed. Please take a look.

@lballabio
Copy link
Owner

I've pushed a few very minor changes but it looks good to me, thanks a lot.

@lballabio lballabio merged commit e3e33d4 into lballabio:master Oct 25, 2024
42 checks passed
@lballabio
Copy link
Owner

We can add DatedSwapRateHelper in the same way.

@lballabio lballabio added this to the Release 1.37 milestone Oct 25, 2024
@eltoder eltoder deleted the feature/dated-ois-custom-pillar branch October 25, 2024 13:23
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.

3 participants