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

Bad interpolation ql.ZeroCurve #1797

Closed
marekkolman opened this issue Sep 27, 2023 · 6 comments · Fixed by #1798
Closed

Bad interpolation ql.ZeroCurve #1797

marekkolman opened this issue Sep 27, 2023 · 6 comments · Fixed by #1798

Comments

@marekkolman
Copy link

marekkolman commented Sep 27, 2023

There seems to be a wrong interpolation in ql.ZeroCurve, returning zeroRate = 0.0 instead of a correct value.

I define a curve that has two edge points:

crv = ql.ZeroCurve([ql.Date(30, 8, 2023), ql.Date(31, 12, 2199)], 
                                 [0.02, 0.02], 
                                 ql.SimpleDayCounter(), 
                                 ql.TARGET())

If I retrieve rate for 2023-08-31 I get rate = 0.0, which is wrong:

# returns 0.0 instead of 0.02
crv.zeroRate(ql.Date(31, 8, 2023), ql.SimpleDayCounter(), ql.Continuous).rate() 

If I do

# returns correctly 0.02
crv.zeroRate(ql.Date(30, 8, 2023), ql.SimpleDayCounter(), ql.Continuous).rate() 

or

# returns correctly 0.02
crv.zeroRate(ql.Date(1, 9, 2023), ql.SimpleDayCounter(), ql.Continuous).rate()

I get 0.02. Not clear where the singularity at ql.Date(31, 8, 2023) comes from.

@boring-cyborg
Copy link

boring-cyborg bot commented Sep 27, 2023

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

@lballabio
Copy link
Owner

I haven't looked closely into the calculation to see what happens, but after experimenting a bit it looks like the problem is SimpleDayCounter. It was added as a convenience for a few examples, but honestly I wouldn't use it for any real work. It should probably be deprecated.

Using act/365 or act/360 as day-count convention works as expected.

@marekkolman
Copy link
Author

The same issue is e.g. with
ql.Thirty360(ql.Thirty360.BondBasis).
So seems to be more than just the SimpleDayCounter

@lballabio
Copy link
Owner

Ok, found the issue—for a number of reasons (possibly different compounding etc), the zero rate is not returned directly from the interpolation but passes through a few conversions. The calculations don't work correctly for t=0, so there is a special case in the code for that. However, the check to trigger the special case is not for t==0 but for d == referenceDate. In this case, August 31 is not the reference date (August 30) so the code goes into the general case, but unfortunately t ==0 (because we're using 30/360) and this causes the calculations to fail. August 30 works because it goes into the special case, and September 1st works because t != 0.

I'll change the check so that it detects this case.

@lballabio
Copy link
Owner

lballabio commented Sep 28, 2023

Moving the issue to the main repo because the problem is in the underlying C++ code.

@lballabio lballabio transferred this issue from lballabio/QuantLib-SWIG Sep 28, 2023
@lballabio
Copy link
Owner

Fixed by #1798, it will be in version 1.32

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 a pull request may close this issue.

2 participants