unsafe upcasting (not via pointer or reference) in SwaptionVolatilityMatrix

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

unsafe upcasting (not via pointer or reference) in SwaptionVolatilityMatrix

Yan Kuang

Hi All,

Upcasting is safe via pointer or reference, however, I have found in swaptionvolmatrix.hpp/ cpp:

In hpp, declared:

Interpolation2D interpolation_;

In cpp:

interpolation_ =
            BilinearInterpolation(swapLengths_.begin(), swapLengths_.end(),
                                  optionTimes_.begin(), optionTimes_.end(),
                                  volatilities_);

I think this is not safe, should change to:

In hpp, declaration:
boost::shared_ptr<Interpolation2D> interpolation_;

In cpp:
interpolation_ = shared_ptr<Interpolation2D> (new BilinearInterpolation(swapLengths_.begin(), swapLengths_.end(),
                                  optionTimes_.begin(), optionTimes_.end(),
                                  volatilities_));


Please convince me if my concern is not a problem.

Cheers,
Yan
Please consider our environment before printing this email.

WARNING - This email and any attachments may be confidential. If received in error, please delete and inform us by return email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Westpac cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email by Westpac, please contact us immediately.

It is also important to check for viruses and defects before opening or using attachments. Westpac's liability is limited to resupplying any affected attachments.

This email and its attachments are not intended to constitute any form of financial advice or recommendation of, or an offer to buy or offer to sell, any security or other financial product. We recommend that you seek your own independent legal or financial advice before proceeding with any investment decision.

Westpac Institutional Bank is a division of Westpac Banking Corporation, a company registered in New South Wales in Australia under the Corporations Act 2001 (Cth). Westpac is authorised and regulated in the United Kingdom by the Financial Services Authority and is registered at Cardiff in the United Kingdom as Branch No. BR 106. Westpac operates in the United States of America as a federally chartered branch, regulated by the Office of the Comptroller of the Currency.

Westpac Banking Corporation ABN 33 007 457 141.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; 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&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: unsafe upcasting (not via pointer or reference) in SwaptionVolatilityMatrix

Luigi Ballabio
On Mon, 2009-09-21 at 15:21 +1000, Yan Kuang wrote:

> Upcasting is safe via pointer or reference, however, I have found in
> swaptionvolmatrix.hpp/ cpp:
>
> In hpp, declared:
>
> Interpolation2D interpolation_;
>
> In cpp:
>
> interpolation_ =
>     BilinearInterpolation(swapLengths_.begin(), swapLengths_.end(),
>                           optionTimes_.begin(), optionTimes_.end(),
>                           volatilities_);
>
> I think this is not safe.

It's true that during the copy, the object is sliced.  However, that is
not a problem. The Interpolation2D object is not polymorphic.  What
provides the polymorphic behavior is the contained Impl class, which is
safely stored in a shared_ptr.  The result of the copy is an
interpolation object that has lost memory of its original type, but
still works correctly by delegating behavior to its contained Impl.

Luigi


--

If you can't convince them, confuse them.
-- Harry S. Truman



------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; 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&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users