Posted by
Yan Kuang on
URL: http://quantlib.414.s1.nabble.com/default-constructor-again-tp7615.html
Hi All,
I am trying to use linear interpolator,
I looked an example, it's like this.
Real
k(Time t, const I1&
xBegin, const I1&
xEnd) const {
LinearInterpolation
li(xBegin, xEnd, (coeffs_->k_).begin());
return
li(t);
}
in abcddinterpolation.hpp
So I wrote a class (sorry I am still
using excel date)
class adtZeroCurve
{
public:
adtZeroCurve(std::vector<double>&
vDate, std::vector<double>&
vZeroRate,
double
valDate)
{
m_ValDate=valDate;
//pdtInt = boost::shared_ptr<LinearInterpolation>(new
LinearInterpolation(vDate.begin(), vDate.end(), vZeroRate.end()));
//pdtInt->update();
adtInt =LinearInterpolation(vDate.begin(), vDate.end(),
vZeroRate.end());
}
virtual
~adtZeroCurve();
double
getDF(double aDate)
{
double
zr = adtInt(aDate);
return
pow(1 / (1 + zr/2) ,((aDate - m_ValDate)/365*2));
}
private:
//boost::shared_ptr<LinearInterpolation>
pdtInt;
LinearInterpolation
adtInt;
double
m_ValDate;
};
As I am using getDF very, very often,
for efficiency I just want to call LinearInterpolation constructor (copy)
once. But the above code
won't compile naturally until I add
default constructor to LinearInterpolation: LinearInterpolation(){}
On one hand, this example may demonstrate
the need of a default constructor. On the other hand I would like someone
to point
out an alternative using boost::shared_ptr.
Thanks,
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.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.
http://p.sf.net/sfu/bobj-july_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users