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

Supply MakeVanillaSwap builder to SwapRateHelper #1932

Closed
wants to merge 9 commits into from

Conversation

PaulXiCao
Copy link
Contributor

@PaulXiCao PaulXiCao commented Mar 19, 2024

(Partially) Closes #1393 .

This mr implements the idea from @eltoder to supply builders instead of adding more and more arguments to the constructors.

I will add some inline comments to places where I was contemplating different options myself. This hopefully simplifies the review process to some extent.

@coveralls
Copy link

coveralls commented Apr 17, 2024

Coverage Status

coverage: 72.493% (-0.01%) from 72.505%
when pulling 4fd2c1a on PaulXiCao:iss1393_SwapRateHelper
into 9a9c154 on lballabio:master.

@PaulXiCao PaulXiCao changed the title Supply builders to helpers, e.g. MakeVanillaSwap to SwapRateHelper Supply MakeVanillaSwap builder to SwapRateHelper Apr 18, 2024
@@ -112,6 +112,8 @@ namespace QuantLib {
ext::optional<BusinessDayConvention> paymentConvention_;

ext::shared_ptr<PricingEngine> engine_;

friend class SwapRateHelper;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is added to enable access within SwapRateHelper::SwapRateHelper(const MakeVanillaSwap& swapBuilder) to swapBuilder.forwardStart_.

@@ -347,6 +358,7 @@ namespace QuantLib {
Handle<YieldTermStructure> discountHandle_;
RelinkableHandle<YieldTermStructure> discountRelinkableHandle_;
ext::optional<bool> useIndexedCoupons_;
bool swapBuiltViaGivenBuilder;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this issue "'SwapRateHelper::swapBuiltViaGivenBuilder' is never used" from "Codacy Static Code Analysis" is a false positive. The member is used, e.g. in ratehelpers.cpp:l.681 SwapRateHelper::setTermStructure().

@PaulXiCao PaulXiCao marked this pull request as ready for review April 19, 2024 19:30
@@ -347,6 +358,7 @@ namespace QuantLib {
Handle<YieldTermStructure> discountHandle_;
RelinkableHandle<YieldTermStructure> discountRelinkableHandle_;
ext::optional<bool> useIndexedCoupons_;
bool swapBuiltViaGivenBuilder;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are supporting two different ctor types

  1. one accepting arguments (e.g. Period tenor) to built up the MakeVanillaSwap
  2. another one accepting directly the builder, i.e. MakeVanillaSwap swapBuilder

Thus, different member variables are used. We could represent this in code (e.g. via optional, variant). Here I used a version of this single boolean for minimal code changes.

Comment on lines +317 to +326
SwapRateHelper(const Handle<Quote>& rate,
const MakeVanillaSwap& swapBuilder,
Handle<Quote> spread = {},
Pillar::Choice pillar = Pillar::LastRelevantDate,
Date customPillarDate = Date());
SwapRateHelper(Rate rate,
const MakeVanillaSwap& swapBuilder,
Handle<Quote> spread = {},
Pillar::Choice pillar = Pillar::LastRelevantDate,
Date customPillarDate = Date());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple pairs of ctors which differ only in Rate rate vs const Handle<Quote>& rate. Should we try to find a way to reduce this duplication? I could imagine there might be a way to define a macro which produces both declarations in the header. The implementation in the cpp would stay as is.

Comment on lines 682 to +684
void SwapRateHelper::setTermStructure(YieldTermStructure* t) {
if (swapBuiltViaGivenBuilder)
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see a straight forward way to access the term structure when the MakeVanillaSwap builder was given in the ctor. Any ideas on how we should handle this member function then?

@lballabio
Copy link
Owner

Hi, sorry for taking so long — this looks like a possibility, but we might have to change something. When the evaluation date changes, the helpers rebuild the swap in initializeDates; but this keeps the old swap. Plus, as you said, we need to fix setTermStructure. I hope to be able to give this some time in the future.

Copy link
Contributor

This PR was automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment, or this will be closed in two weeks.

@github-actions github-actions bot added the stale label Aug 20, 2024
Copy link
Contributor

github-actions bot commented Sep 3, 2024

This PR was automatically closed because it has been stalled for two weeks with no further activity.

@github-actions github-actions bot closed this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using IMM-rolls swaps to build curves
3 participants