Hi guys,
I'm a little confused about the QuantLib curve classes ForwardCurve, DiscountCurve and ZeroCurve.
In the three class definitions we have the member variable
mutable Interpolation interpolation_;
but in constructing a curve (using the PiecewiseYieldCurve) we use a factory class function (interpolator_.interpolate) to allocate an Interpolation object to the interpolation_ member variable. However, often the object allocated is an object of a derived class e.g. CubicSpline. Now, I know pointers and references can be polymorphic. But in this case a derived class is being allocated to a base class instance... I know most information required for interpolation is contained within the Interpolation::impl_ object but I'm wondering whether: a) my C++ knowledge is lacking and the base class instance (e.g. ForwardCurve::interpolation_) can be polymorphic somehow. Or... b) why a pointer to the derived Interpolation object isn't returned by the factory class (e.g. Cubic::interpolate) - to obviate the need for a polymorphic Interpolation::impl_ member variable? Thanks in advance for enlightening me. Simon ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Hi Simon,
On Fri, 2008-02-15 at 09:57 +0000, Simon Ibbotson wrote: > I'm a little confused about the QuantLib curve classes ForwardCurve, > DiscountCurve and ZeroCurve. > > In the three class definitions we have the member variable > mutable Interpolation interpolation_; > > [...] often the object allocated is an object of a derived class e.g. > CubicSpline. > > Now, I know pointers and references can be polymorphic. But in this > case a derived class is being allocated to a base class instance... > > I know most information required for interpolation is contained within > the Interpolation::impl_ object but I'm wondering whether: > > a) my C++ knowledge is lacking and the base class instance (e.g. > ForwardCurve::interpolation_) can be polymorphic somehow. Or... No, you're right---it's not polymorphic. As you surmised, the polymorphic behavior is delegated to the inner Interpolation::impl_ object, which is copied by pointer and continues to have the correct type even when the containing Interpolation object is sliced. > b) why a pointer to the derived Interpolation object isn't returned by > the factory class (e.g. Cubic::interpolate) - to obviate the need for > a polymorphic Interpolation::impl_ member variable? I confess that it's a while since we coded it, so I might be wrong. But I think it's the same reason why we coded, say, the Calendar and DayCounter classes in the same way---to avoid writing the shared_ptr part. See <http://quantlib.org/quep/quep001.html> for the full rationale (the code samples are outdated, but the reasoning still holds.) Luigi -- Olmstead's Law: After all is said and done, a hell of a lot more is said than done. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Hi Luigi,
Thanks for the reply: I did eventually find the document mentioned below but found no way of replying to my own message on Sourceforge (so that I could say that I'd found the answer). On a separate note, do you know who is currently working on the curve interface? I'd like to contribute a different Bootstrap to the library (for localized approximations of global interpolations) but want to check the current state of development: what interface(s) the Bootstrap class needs to implement. All the best, Simon -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Luigi Ballabio Sent: 25 February 2008 16:44 To: Simon Ibbotson Cc: [hidden email] Subject: Re: [Quantlib-dev] Curve interpolation Hi Simon, On Fri, 2008-02-15 at 09:57 +0000, Simon Ibbotson wrote: > I'm a little confused about the QuantLib curve classes ForwardCurve, > DiscountCurve and ZeroCurve. > > In the three class definitions we have the member variable > mutable Interpolation interpolation_; > > [...] often the object allocated is an object of a derived class e.g. > CubicSpline. > > Now, I know pointers and references can be polymorphic. But in this > case a derived class is being allocated to a base class instance... > > I know most information required for interpolation is contained within > the Interpolation::impl_ object but I'm wondering whether: > > a) my C++ knowledge is lacking and the base class instance (e.g. > ForwardCurve::interpolation_) can be polymorphic somehow. Or... No, you're right---it's not polymorphic. As you surmised, the polymorphic behavior is delegated to the inner Interpolation::impl_ object, which is copied by pointer and continues to have the correct type even when the containing Interpolation object is sliced. > b) why a pointer to the derived Interpolation object isn't returned by > the factory class (e.g. Cubic::interpolate) - to obviate the need for > a polymorphic Interpolation::impl_ member variable? I confess that it's a while since we coded it, so I might be wrong. But I think it's the same reason why we coded, say, the Calendar and DayCounter classes in the same way---to avoid writing the shared_ptr part. See <http://quantlib.org/quep/quep001.html> for the full rationale (the code samples are outdated, but the reasoning still holds.) Luigi -- Olmstead's Law: After all is said and done, a hell of a lot more is said than done. ------------------------------------------------------------------------ - This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Hi Simon,
On Mon, 2008-02-25 at 16:51 +0000, Simon Ibbotson wrote: > On a separate note, do you know who is currently working on the curve > interface? I'd like to contribute a different Bootstrap to the library > (for localized approximations of global interpolations) but want to > check the current state of development: what interface(s) the Bootstrap > class needs to implement. Nando has been working on it for the last few days (Nando, is it done?) Then I'll want to make a few minor changes myself. I'll send you a line when I'm done. Later, Luigi -- Innovation is hard to schedule. -- Dan Fylstra ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ QuantLib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |