LogCubic interpolator

Bug #1210005 reported by Richard Gomes
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
JQuantLib
Fix Released
Medium
Richard Gomes

Bug Description

An user reported an issue with LogCubicInterpolator.

Please verify if our translation is in accordance with QuantLib 0.9.7.
If it is not (which means we have a bug, probably!), please validate an implement the fix sent by the user.

Additional information below.

Thanks

======================
Additional Information
======================
Richard,

I tried to test LogCubic interpolator (class LogCubic) and it produced incorrect results – in fact, returned interpolated argument vlaues instead of function values.

It turns out, the problem (most likely, typo) was in AbstractInterpolation::LogInterpolationImpl::update() - jquantlib/src/main/java/org/jquantlib/math/interpolations/AbstractInterpolation.java, line 305 (marked red) :

      public void update() {

            for (int i=0; i<logY_.size(); i++) {

                QL.require(vy.get(i)>0.0, "invalid value"); // TODO: message

                logY_.set(i, Math.log(vx.get(i)));

            }

            interpolation_.update();

        }

logY_ is initialized with x-values, and y-values (vy) are never used anywhere else, so argument becomes the value being interpolated.
Besides, intuitively it is evident that logY_ means log of Y, not X, and in the line above you make sure y-value is non-negative, obviously condition to take logarithm. So I figured it must be typo and replaced vx with vy - now, it worked fine.
The corrected version is below :

      public void update() {

            for (int i=0; i<logY_.size(); i++) {

                QL.require(vy.get(i)>0.0, "invalid value"); // TODO: message

                logY_.set(i, Math.log(vy.get(i)));

            }

            interpolation_.update();

        }

Hope it helps.
I wasn’t sure how to report an issue, decided to write you directly.

Kind Regards,

Boris Ashman

Tags: code-review
Revision history for this message
Ruslan Khafizov (kharus) wrote :

I checked original code from QuantLib 0.9.7 and it uses vy so Boris is correct. I applied fix proposed

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.