SwapRateHelper Question - SWIG Python

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

SwapRateHelper Question - SWIG Python

Ioan F.
Hello,

I am trying to expose a new type of the SwapRateHelper constructor (already existent in QuantLib) to Python.
In the ratehelpers.i interface file, I added the following code:

//ADDED

SwapRateHelperPtr(
              const Handle<Quote>& rate,
        const Period &tenor,
        const Calendar &calendar,
        Frequency fixedFrequency,
        BusinessDayConvention fixedConvention,
        const DayCounter &fixedDayCount,
        const boost::shared_ptr<IborIndex> &index,
        const Handle<Quote> &spread=Handle<Quote>(),
        const Period &fwdStart=0 *Days,
        const Handle<YieldTermStructure> &discountingCurve=Handle<YieldTermStructure>()) {
                boost::shared_ptr<IborIndex> libor =
                        boost::dynamic_pointer_cast<IborIndex>(index);
                           return new SwapRateHelperPtr(
                           new SwapRateHelper(rate, tenor, calendar,
                                   fixedFrequency, fixedConvention,
                                   fixedDayCount, libor,
                                   spread, fwdStart,
                        discountingCurve));


//END ADDED

I was able to wrap, build and install the QuantLib library (via SWIG) into Python, but when I try to use the SwapRateHelper in Python, I get the following error:

 NotImplementedError: Wrong number or type of arguments for overloaded function 'new_SwapRateHelper'.
  Possible C/C++ prototypes are:....


The following code works:

qqq=SwapRateHelper(QuoteHandle(eurLiborSwaps[(2, Years)]),
                            Period(2, Years),
                            euroCalendar,
                            fixedLegFrequency,
                            fixedLegAdjustment,
                            fixedLegDayCounter,
                            EURLibor3M(),
                            QuoteHandle(),
                            Period(0,0))


while this one causes the problem:

qqq=SwapRateHelper(QuoteHandle(eurLiborSwaps[(2, Years)]),
                            Period(2, Years),
                            euroCalendar,
                            fixedLegFrequency,
                            fixedLegAdjustment,
                            fixedLegDayCounter,
                            EURLibor3M(),
                            QuoteHandle(),
                            Period(0,0),
                            eoniaHandle)


Furthermore, please note that Python reports the type of the eoniaHandle variable as:

QuantLib.QuantLib.YieldTermStructureHandle

Any help or suggestions are highly appreciated.
Since this is my first time posting, please excuse any breaking of the "mailing list etiquette."

Thank you,
Ioan
Reply | Threaded
Open this post in threaded view
|

Re: SwapRateHelper Question - SWIG Python

Luigi Ballabio
The constructor is exported in the latest version of the code (see
<https://github.com/lballabio/quantlib/blob/master/QuantLib-SWIG/SWIG/ratehelpers.i>)
and it seems to work. Are you sure you're not picking up an old
installed version of the module? In the "Possible C/C++ prototypes
are:....* error message, is the one with the additional parameter
listed? If so, can you provide a small script that initializes the
parameters you're passing and reproduces the problem?

Luigi


On Wed, May 21, 2014 at 6:27 PM, Ioan F. <[hidden email]> wrote:

> Hello,
>
> I am trying to expose a new type of the SwapRateHelper constructor (already
> existent in QuantLib) to Python.
> In the ratehelpers.i interface file, I added the following code:
>
> //ADDED
>
> *SwapRateHelperPtr(
>               const Handle& rate,
>         const Period &tenor,
>         const Calendar &calendar,
>         Frequency fixedFrequency,
>         BusinessDayConvention fixedConvention,
>         const DayCounter &fixedDayCount,
>         const boost::shared_ptr<IborIndex> &index,
>         const Handle &spread=Handle(),
>         const Period &fwdStart=0 *Days,
>         const Handle<YieldTermStructure>
> &discountingCurve=Handle<YieldTermStructure>()) {
>                 boost::shared_ptr<IborIndex> libor =
>                         boost::dynamic_pointer_cast<IborIndex>(index);
>                            return new SwapRateHelperPtr(
>                            new SwapRateHelper(rate, tenor, calendar,
>                                    fixedFrequency, fixedConvention,
>                                    fixedDayCount, libor,
>                                    spread, fwdStart,
>                         discountingCurve));*
>
> //END ADDED
>
> I was able to wrap, build and install the QuantLib library (via SWIG) into
> Python, but when I try to use the SwapRateHelper in Python, I get the
> following error:
>
>  *NotImplementedError: Wrong number or type of arguments for overloaded
> function 'new_SwapRateHelper'.
>   Possible C/C++ prototypes are:....*
>
> The following code works:
>
> *qqq=SwapRateHelper(QuoteHandle(eurLiborSwaps[(2, Years)]),
>                             Period(2, Years),
>                             euroCalendar,
>                             fixedLegFrequency,
>                             fixedLegAdjustment,
>                             fixedLegDayCounter,
>                             EURLibor3M(),
>                             QuoteHandle(),
>                             Period(0,0))*
>
> while this one causes the problem:
>
> *qqq=SwapRateHelper(QuoteHandle(eurLiborSwaps[(2, Years)]),
>                             Period(2, Years),
>                             euroCalendar,
>                             fixedLegFrequency,
>                             fixedLegAdjustment,
>                             fixedLegDayCounter,
>                             EURLibor3M(),
>                             QuoteHandle(),
>                             Period(0,0),
>                             eoniaHandle)*
>
> Furthermore, please note that Python reports the type of the eoniaHandle
> variable as:
>
> *QuantLib.QuantLib.YieldTermStructureHandle*
>
> Any help or suggestions are highly appreciated.
> Since this is my first time posting, please excuse any breaking of the
> "mailing list etiquette."
>
> Thank you,
> Ioan
>
>
>
> --
> View this message in context: http://quantlib.10058.n7.nabble.com/SwapRateHelper-Question-SWIG-Python-tp15297.html
> Sent from the quantlib-dev mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev



--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>

------------------------------------------------------------------------------
The best possible search technologies are now affordable for all companies.
Download your FREE open source Enterprise Search Engine today!
Our experts will assist you in its installation for $59/mo, no commitment.
Test it for FREE on our Cloud platform anytime!
http://pubads.g.doubleclick.net/gampad/clk?id=145328191&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: SwapRateHelper Question - SWIG Python

Ioan F.
Thank you Luigi.

Using the latest ratehelpers.i interface file worked.

If I may ask, how come your version of the SWIG interface files are not part of the latest "official" version? I got the latest QuantLib SWIG version available not too long ago from

http://sourceforge.net/projects/quantlib/files/QuantLib/1.4/other%20languages/
Reply | Threaded
Open this post in threaded view
|

Re: SwapRateHelper Question - SWIG Python

Luigi Ballabio
On Tue, May 27, 2014 at 9:26 PM, Ioan F. <[hidden email]> wrote:
> Using the latest ratehelpers.i interface file worked.

Glad to hear it. Strange, though: your change looked the same to me. Oh well.

> If I may ask, how come your version of the SWIG interface files are not part
> of the latest "official" version?

The additional constructor was exported after the 1.4 version was released.

Cheers,
    Luigi


--
<https://implementingquantlib.blogspot.com>
<https://twitter.com/lballabio>

------------------------------------------------------------------------------
The best possible search technologies are now affordable for all companies.
Download your FREE open source Enterprise Search Engine today!
Our experts will assist you in its installation for $59/mo, no commitment.
Test it for FREE on our Cloud platform anytime!
http://pubads.g.doubleclick.net/gampad/clk?id=145328191&iu=/4140/ostg.clktrk
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev