Hi All
This is my first post, and hopefully not my last, I've been working with quantlib for a while now, and want to use it from Java in a project. The problem is that I have now spent 2 solid days trying to change the termstructures.i interface to work for interpolatedzerocurve. The problem is an intermediate class ZeroYieldStructure. I can't seem to get swig to generate this class because of it's virtual methods. I was hoping that someone with a bit more experience with swig and quantlib could give me some pointers. Here is what I have at the moment (I have tried man different iterations of this..) but it complains when trying to compile the cpp wrappers: //%feature("notabstract") ZeroYieldStructure; %{ using QuantLib::ZeroYieldStructure; typedef boost::shared_ptr<ZeroYieldStructure> ZeroYieldStructurePtr; %} %rename(ZeroYieldStructure) ZeroYieldStructurePtr; class ZeroYieldStructurePtr : public boost::shared_ptr<YieldTermStructure> { public: // ZeroYieldStructure(); // ZeroYieldStructure(const Date& referenceDate); // ZeroYieldStructure(Integer settlementDays, const Calendar&); // Rate zeroYieldImpl(Time) const = 0; // Date maxDate() const; // DayCounter dayCounter() const = 0; }; // flat forward curve %feature("notabstract") InterpolatedZeroCurve; %{ using QuantLib::InterpolatedZeroCurve; using QuantLib::Linear; %} template <class Interpolator> class InterpolatedZeroCurve : public ZeroYieldStructure { public: InterpolatedZeroCurve(const std::vector<Date>& dates, const std::vector<Rate>& yields, const DayCounter& dayCounter, const Interpolator& interpolator = Interpolator()); DayCounter dayCounter() const; Date maxDate() const; Time maxTime() const; const std::vector<Time>& times() const; const std::vector<Date>& dates() const; }; %template(LinearInterpolatedZeroCurve) InterpolatedZeroCurve<Linear>; The erros is as follows: ../quantlib.cxx: In function `jlong Java_org_quantlib_quantlibJNI_SWIGZeroYieldStructureUpcast(JNIEnv*, _jclass*, long long int)': ../quantlib.cxx:70529: cannot convert `ZeroYieldStructurePtr*' to `boost::shared_ptr<QuantLib::YieldTermStructure>*' in assignment Any help would be appreciated, and hopefully I could get the swing of this soon to start contributing back. Regards Tinus |
Ok, so here I have an answer to my own question. Don't think it's the best
answer but at least it is working. First of all I realised it was of no use trying to wrap the abstract class ZeroYieldStructure. Secondly I could not get the template to work so I created 2 instances of the class, if anyone know of a better way please let me know. %{ using QuantLib::InterpolatedZeroCurve; using QuantLib::Linear; typedef boost::shared_ptr<YieldTermStructure> LinearInterpolatedZeroCurvePtr; %} %rename(LinearInterpolatedZeroCurve) LinearInterpolatedZeroCurvePtr; class LinearInterpolatedZeroCurvePtr : public boost::shared_ptr<YieldTermStructure> { public: %extend { LinearInterpolatedZeroCurvePtr(const std::vector<Date>& dates, const std::vector<Rate>& yields, const DayCounter& dayCounter){ return new LinearInterpolatedZeroCurvePtr( new InterpolatedZeroCurve<Linear>(dates,yields,dayCounter)); } } }; %{ using QuantLib::Cubic; typedef boost::shared_ptr<YieldTermStructure> CubicInterpolatedZeroCurvePtr; %} %rename(CubicInterpolatedZeroCurve) CubicInterpolatedZeroCurvePtr; class CubicInterpolatedZeroCurvePtr : public boost::shared_ptr<YieldTermStructure> { public: %extend { CubicInterpolatedZeroCurvePtr(const std::vector<Date>& dates, const std::vector<Rate>& yields, const DayCounter& dayCounter, const Cubic& cubic = Cubic()){ return new CubicInterpolatedZeroCurvePtr( new InterpolatedZeroCurve<Cubic>(dates,yields,dayCounter,cubic)); } } }; -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Tinus Rautenbach Sent: 10 December 2005 16:51 To: [hidden email] Subject: [Quantlib-dev] swig interface extension problem Hi All This is my first post, and hopefully not my last, I've been working with quantlib for a while now, and want to use it from Java in a project. The problem is that I have now spent 2 solid days trying to change the termstructures.i interface to work for interpolatedzerocurve. The problem is an intermediate class ZeroYieldStructure. I can't seem to get swig to generate this class because of it's virtual methods. I was hoping that someone with a bit more experience with swig and quantlib could give me some pointers. Here is what I have at the moment (I have tried man different iterations of this..) but it complains when trying to compile the cpp wrappers: //%feature("notabstract") ZeroYieldStructure; %{ using QuantLib::ZeroYieldStructure; typedef boost::shared_ptr<ZeroYieldStructure> ZeroYieldStructurePtr; %} %rename(ZeroYieldStructure) ZeroYieldStructurePtr; class ZeroYieldStructurePtr : public boost::shared_ptr<YieldTermStructure> { public: // ZeroYieldStructure(); // ZeroYieldStructure(const Date& referenceDate); // ZeroYieldStructure(Integer settlementDays, const Calendar&); // Rate zeroYieldImpl(Time) const = 0; // Date maxDate() const; // DayCounter dayCounter() const = 0; }; // flat forward curve %feature("notabstract") InterpolatedZeroCurve; %{ using QuantLib::InterpolatedZeroCurve; using QuantLib::Linear; %} template <class Interpolator> class InterpolatedZeroCurve : public ZeroYieldStructure { public: InterpolatedZeroCurve(const std::vector<Date>& dates, const std::vector<Rate>& yields, const DayCounter& dayCounter, const Interpolator& interpolator = Interpolator()); DayCounter dayCounter() const; Date maxDate() const; Time maxTime() const; const std::vector<Time>& times() const; const std::vector<Date>& dates() const; }; %template(LinearInterpolatedZeroCurve) InterpolatedZeroCurve<Linear>; The erros is as follows: ../quantlib.cxx: In function `jlong Java_org_quantlib_quantlibJNI_SWIGZeroYieldStructureUpcast(JNIEnv*, _jclass*, long long int)': ../quantlib.cxx:70529: cannot convert `ZeroYieldStructurePtr*' to `boost::shared_ptr<QuantLib::YieldTermStructure>*' in assignment Any help would be appreciated, and hopefully I could get the swing of this soon to start contributing back. Regards Tinus ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Quantlib-dev mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-dev |
Free forum by Nabble | Edit this page |