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

More functions to support both clean and dirty prices as input parameter #1813

Merged
merged 11 commits into from Mar 6, 2024

Conversation

igitur
Copy link
Contributor

@igitur igitur commented Oct 18, 2023

I noticed some more bond functions that currently accept only a clean price. This PR extends them to accept either dirty or clean price and adds the relevant priceType parameter.

Previous attempt at #939

@igitur
Copy link
Contributor Author

igitur commented Oct 18, 2023

I just need to check whether I must add more unit tests...

@igitur
Copy link
Contributor Author

igitur commented Oct 18, 2023

Ok, I think these tests should cover it.

FYI, the reason I'm so invested in dirty prices is because Quantlib can't calculate South African bond clean prices correctly. We use Actual/Actual (Bond) for the coupon calculations, but the accrued amount uses Actual/365 (Fixed). Until the FixedRateBond class accepts the daycounts for both of these, the clean prices and accrued amounts will be wrong. So for me, it's just easiest to do everything (bootstrap yield curves, etc) based on dirty prices.

@coveralls
Copy link

coveralls commented Oct 18, 2023

Coverage Status

coverage: 72.454% (-0.02%) from 72.474%
when pulling f1ed886 on igitur:more-pricetype-enhancements
into 014d08a on lballabio:master.

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 Dec 18, 2023
@igitur
Copy link
Contributor Author

igitur commented Dec 18, 2023

I think this PR is ready for review.

@lballabio lballabio removed the stale label Dec 18, 2023
@lballabio
Copy link
Owner

Yes, sorry, I'm a bit behind.

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 Feb 17, 2024
@lballabio lballabio removed the stale label Feb 17, 2024
@lballabio
Copy link
Owner

The PR looks good to me — I'm just wondering whether we should keep the signatures with Real price, Bond::Price::Type priceType, or deprecate them and go for Bond::Price price instead. Any opinions?

@lballabio lballabio added this to the Release 1.34 milestone Feb 20, 2024
@igitur
Copy link
Contributor Author

igitur commented Feb 26, 2024

Yes, I agree with you. Let's deprecate the current ones and move to using Bond::Price where possible. I'll update this PR soon. Thanks.

@lballabio
Copy link
Owner

Great, thanks

@igitur igitur force-pushed the more-pricetype-enhancements branch from 231b351 to 95ac5fa Compare March 1, 2024 09:19
@@ -62,7 +62,8 @@ namespace QuantLib {
class Price {
public:
enum Type { Dirty, Clean };
Price() : amount_(Null<Real>()) {}
Price() : amount_(Null<Real>()), type_(Bond::Price::Clean) {}
Price(Real amount) : amount_(amount), type_(Bond::Price::Clean) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lballabio Codacy says the constructor should be marked explicit, but I think it's totally reasonable to pass through an int value here and let the implicit conversion do its job. Please let me know what your preference is and I'll adjust accordingly.

Copy link
Owner

Choose a reason for hiding this comment

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

Frankly I'd avoid taking a number without an explicit type. I'll do it.

derived class.
\relates Bond::Price
*/
bool operator==(const Bond::Price&, const Bond::Price&);
Copy link
Owner

Choose a reason for hiding this comment

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

Is this used only to compare with Null<Price>()?

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, only for that. If there's a better way, please show me.

Copy link
Owner

Choose a reason for hiding this comment

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

We can add something like price.isValid()

@lballabio lballabio enabled auto-merge March 6, 2024 22:02
@lballabio lballabio merged commit 6d5892e into lballabio:master Mar 6, 2024
48 checks passed
@igitur igitur deleted the more-pricetype-enhancements branch March 7, 2024 07:41
@igitur
Copy link
Contributor Author

igitur commented Mar 7, 2024

Thanks for your help on this.

@lballabio
Copy link
Owner

No problem.

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.

None yet

3 participants