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

Fix calendar advance for unadjusted convention #1917

Merged
merged 4 commits into from
Feb 28, 2024

Conversation

DeimosXing
Copy link
Contributor

This PR resolves #1910

In Calendar::advance(), the return date will be moved to end of business day if endOfMonth && isEndOfMonth(d) is True. However, isEndOfMonth(d) is True when d is on or after the end of business day, which introduces a discrepancy between d and the return date.

This PR fixes this behavior by returning the end of calendar date when convention is Unadjusted.

I added a unit test to ensure this behaves correctly for a US treasury bond. The ref start date should be end of calendar date and the cashflow should match the real-world cashflow.

Copy link

boring-cyborg bot commented Feb 21, 2024

Thanks for opening this pull request! It might take a while before we look at it, so don't worry if there seems to be no feedback. We'll get to it.

@DeimosXing DeimosXing marked this pull request as draft February 21, 2024 19:19
@CLAassistant
Copy link

CLAassistant commented Feb 21, 2024

CLA assistant check
All committers have signed the CLA.

@DeimosXing DeimosXing marked this pull request as ready for review February 21, 2024 22:25
if (endOfMonth && isEndOfMonth(d))
return Calendar::endOfMonth(d1);

if (endOfMonth && isEndOfMonth(d)){
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use Date::isEndOfMonth() when the convention is Unadjusted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is better, fixed

@@ -82,7 +82,7 @@ BOOST_AUTO_TEST_CASE(testConventions) {
//Unadjusted
SingleCase(SouthAfrica(), Unadjusted, Date(3,February,2015), Period(1,Months), false, Date(3,March,2015)),
SingleCase(SouthAfrica(), Unadjusted, Date(3,February,2015), Period(4,Days), false, Date(9,February,2015)),
SingleCase(SouthAfrica(), Unadjusted, Date(31,January,2015), Period(1,Months), true, Date(27,February,2015)),
SingleCase(SouthAfrica(), Unadjusted, Date(31,January,2015), Period(1,Months), true, Date(28,February,2015)),
Copy link
Owner

Choose a reason for hiding this comment

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

@igitur it's been a long time, but git tells me you wrote this test — do you think it makes sense to change the result?

Copy link
Contributor

Choose a reason for hiding this comment

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

@lballabio Hi, yes, the fix looks correct. I probably used QuantlibXL to generate test data for the existing business day conventions, thereby including the bug in the test data. Sorry.

@coveralls
Copy link

Coverage Status

coverage: 72.478% (+0.001%) from 72.477%
when pulling 4ed9da4 on VoleonGroup:fix-calendar-unadjusted
into 012754d on lballabio:master.

@lballabio lballabio added this to the Release 1.34 milestone Feb 28, 2024
@lballabio lballabio merged commit bd7242c into lballabio:master Feb 28, 2024
48 checks passed
Copy link

boring-cyborg bot commented Feb 28, 2024

Congratulations on your first merged pull request!

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.

Long existing bug causing error in first period interest/cashflow calculation for FixedRateBond
6 participants