Problems with QL 0.9.7 and Cubic interpolation for curves

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with QL 0.9.7 and Cubic interpolation for curves

Dirk Eddelbuettel

While working on RQuantLib [1], Khanh and I discovered a number of numerical
issues with Cubic interpolation on yield curves.  The RQuantLib side of the
code that triggers it is actually pretty old and used to run so I am confused
as to when this changed.  

A relatively simple way to trigger the same issue is to modify the
swapvaluation.cpp example as follows:

edd@ron:~/svn/quantlib/Examples/Swap$ diff -u swapvaluation.cpp.orig swapvaluation.cpp
--- swapvaluation.cpp.orig      2008-08-01 03:55:43.000000000 -0500
+++ swapvaluation.cpp   2009-10-17 10:08:42.000000000 -0500
@@ -316,7 +316,7 @@
         depoSwapInstruments.push_back(s10y);
         depoSwapInstruments.push_back(s15y);
         boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
-            new PiecewiseYieldCurve<Discount,LogLinear>(
+            new PiecewiseYieldCurve<Discount,Cubic>(
                                           settlementDate, depoSwapInstruments,
                                           termStructureDayCounter,
                                           std::vector<Handle<Quote> >(),

and you get to trigger the bug as easily as

edd@ron:~/svn/quantlib/Examples/Swap$ g++ -o newswap swapvaluation.cpp -lQuantLib -lm && ./newswap

Today: Monday, September 20th, 2004
Settlement date: Wednesday, September 22nd, 2004
====================================================================
5-year market swap-rate = 4.43 %
====================================================================
        5-years swap paying 4.00 %
term structure | net present value | fair spread | fair fixed rate |
--------------------------------------------------------------------
1st iteration: could not bootstrap the 1st instrument, maturity September 29th, 2004: root not bracketed: f[2.22045e-16,1] -> [1.116106e+18,3.820000e-02]
edd@ron:~/svn/quantlib/Examples/Swap$


We used to do this quite regularly and combine Discount with Linear,
LogLinear and Cubic with no issues.  Now it seems to throw errors. Should we
stop using Cubic interpolation here?

In other words, did something change that we need to accomodate?  Or should
we simply not combine the Piecewise interpolation with the Cubic argument ?
I also noticed the messages on Cubic interpolation in the list archives but
from I gathered this is for new code rather than this curve-building
functionality.

Many thanks for any pointers, Dirk

[1] http://dirk.eddelbuettel.com/code/rquantlib.html

--
Three out of two people have difficulties with fractions.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problems with QL 0.9.7 and Cubic interpolation for curves

Luigi Ballabio
On Sat, 2009-10-17 at 10:35 -0500, Dirk Eddelbuettel wrote:

> While working on RQuantLib [1], Khanh and I discovered a number of numerical
> issues with Cubic interpolation on yield curves.  The RQuantLib side of the
> code that triggers it is actually pretty old and used to run so I am confused
> as to when this changed.  
>
> A relatively simple way to trigger the same issue is to modify the
> swapvaluation.cpp example as follows:
>
> edd@ron:~/svn/quantlib/Examples/Swap$ diff -u swapvaluation.cpp.orig swapvaluation.cpp
> --- swapvaluation.cpp.orig      2008-08-01 03:55:43.000000000 -0500
> +++ swapvaluation.cpp   2009-10-17 10:08:42.000000000 -0500
> @@ -316,7 +316,7 @@
>          depoSwapInstruments.push_back(s10y);
>          depoSwapInstruments.push_back(s15y);
>          boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
> -            new PiecewiseYieldCurve<Discount,LogLinear>(
> +            new PiecewiseYieldCurve<Discount,Cubic>(
>                                            settlementDate, depoSwapInstruments,
>                                            termStructureDayCounter,
>                                            std::vector<Handle<Quote> >(),
>
> and you get to trigger the bug as easily as
>
> edd@ron:~/svn/quantlib/Examples/Swap$ g++ -o newswap swapvaluation.cpp -lQuantLib -lm && ./newswap

Dirk,
        as of today, I couldn't reproduce the error on the 0.9.9 release branch
(branches/R000909-branch in Subversion.)  The swap example runs
successfully after the change.  Does it work for you? Of course it's not
picking up some other library version you installed earlier, is it?

Later,
        Luigi


--

It is better to know some of the questions than all of the answers.
-- James Thurber



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problems with QL 0.9.7 and Cubic interpolation for curves

Dirk Eddelbuettel

On 29 October 2009 at 15:25, Luigi Ballabio wrote:
| On Sat, 2009-10-17 at 10:35 -0500, Dirk Eddelbuettel wrote:
| > While working on RQuantLib [1], Khanh and I discovered a number of numerical
| > issues with Cubic interpolation on yield curves.  The RQuantLib side of the
| > code that triggers it is actually pretty old and used to run so I am confused
| > as to when this changed.  
| >
| > A relatively simple way to trigger the same issue is to modify the
| > swapvaluation.cpp example as follows:
| >
| > edd@ron:~/svn/quantlib/Examples/Swap$ diff -u swapvaluation.cpp.orig swapvaluation.cpp
| > --- swapvaluation.cpp.orig      2008-08-01 03:55:43.000000000 -0500
| > +++ swapvaluation.cpp   2009-10-17 10:08:42.000000000 -0500
| > @@ -316,7 +316,7 @@
| >          depoSwapInstruments.push_back(s10y);
| >          depoSwapInstruments.push_back(s15y);
| >          boost::shared_ptr<YieldTermStructure> depoSwapTermStructure(
| > -            new PiecewiseYieldCurve<Discount,LogLinear>(
| > +            new PiecewiseYieldCurve<Discount,Cubic>(
| >                                            settlementDate, depoSwapInstruments,
| >                                            termStructureDayCounter,
| >                                            std::vector<Handle<Quote> >(),
| >
| > and you get to trigger the bug as easily as
| >
| > edd@ron:~/svn/quantlib/Examples/Swap$ g++ -o newswap swapvaluation.cpp -lQuantLib -lm && ./newswap
|
| Dirk,
| as of today, I couldn't reproduce the error on the 0.9.9 release branch
| (branches/R000909-branch in Subversion.)  The swap example runs
| successfully after the change.  Does it work for you? Of course it's not
| picking up some other library version you installed earlier, is it?

Confirmed!  I (finally) got a chance to build QL 0.9.9 (using 20091023
tarballs) and things work now.  Very good news.  

I only needed a few touchups to get RQuantLib to build with it too.

So I put 0.9.9~20091023 into Debian -- and may follow up with the Nov 2
variant you released today.  The full build and regression test takes well
over an hour but seemingly passed each and every test.  

Looking forward to QL 1.0!!

Dirk

--
Three out of two people have difficulties with fractions.

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problems with QL 0.9.7 and Cubic interpolation for curves

Luigi Ballabio
On Mon, 2009-11-02 at 16:04 -0600, Dirk Eddelbuettel wrote:
> Confirmed!  I (finally) got a chance to build QL 0.9.9 (using 20091023
> tarballs) and things work now.  Very good news.

Glad to hear that.

Cheers,
        Luigi


--

Of course, if people could just act consistently, they could keep
their desks clean, avoid cavities, lose weight, give up smoking,
play a musical instrument, and possibly even produce software on
a regular and timely basis.
-- Alistair Cockburn



------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev