Subclassing (the RateHelper) in Python

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

Subclassing (the RateHelper) in Python

ago-2
Hi,

I am trying to subclass the RateHelper using python, so that the
derived class (Inflation Linked Bond) can be used within the
bootstrapper. I am struggling my way through c++, swig and the wrapper
code, and so far I failed miserably with the error:

NotImplementedError: No matching function for overloaded
'new_PiecewiseFlatForward'

This error normally relates to wrong type of constructor arguments,
but in this case it seems more complex and I gave up trying to
understand the wrapper code.

I then tried the "easier" task of subclassing (in python) the
SwapRateHelper, overriding some of the methods for testing purposes.

I have no problem using derived classes in other python code, but when
instances of such classes are consumed within QL, the overridden
methods are not called, the ones of the base class are used instead
:-(

E.g. in the bootstrapper PiecewiseFlatForward::performCalculations(),
the overridden discountGuess() is never called. This is a bit of a
show stopper.

Can this type of subclassing be done in Python or am I wasting my
time? If yes, how? Or should I write c++ code and then use swig? Or
some other python extension technique? What have others done so far?


Reply | Threaded
Open this post in threaded view
|

Re: Subclassing (the RateHelper) in Python

Luigi Ballabio
On 10/14/2005 11:24:10 AM, ago wrote:
> I am trying to subclass the RateHelper using python, so that the
> derived class (Inflation Linked Bond) can be used within the
> bootstrapper. I am struggling my way through c++, swig and the  
> wrapper code, and so far I failed miserably with the error:
>
> NotImplementedError: No matching function for overloaded
> 'new_PiecewiseFlatForward'

I guess the wrappers didn't recognize instances of your class as rate  
helpers. What was the interface you exported? Can you post the relevant  
bit of the .i file?


> I then tried the "easier" task of subclassing (in python) the
> SwapRateHelper, overriding some of the methods for testing purposes.

That won't work. SWIG must be told to generate special code for that  
(see the SWIG documentation for "directors".) However, I'm under the  
impression that it would not work because we're exporting smart  
pointers rather than the actual classes.

Later,
        Luigi


----------------------------------------

To err is human -- to blame it on a computer is even more so.
-- unknown



Reply | Threaded
Open this post in threaded view
|

Re: Subclassing (the RateHelper) in Python

Nabil Layaida

Hi Luigi,

I am porting the cpp testsuite In Java.
I am looking for covering the entire testsuite and the
work is progressing rapidly.
Luigi, Do you think it will have a value in putting this in the
CVS base sometime. A significant part of the test suite
passes already in Java :)

I need a help from a SWIG Interface person
to help me get through. In fact, I don't find the interface for the following
cases :

- the capfloor ImpliedVolatility method in the wrappers.
 Capfloor has been split into its sub-classes, Cap, Floor and Collar
but no Capfloor where ImpliedVolatility id defined.

- In CompoundForward class, there is no methods
  corresponding to the C++ method :
             Rate compoundForward(const Date& d1,
                      Integer f,
                     bool extrapolate = false) const;
               Rate compoundForward(Time t1,
                      Integer f,
                     bool extrapolate = false) const;

- The Class GapPayoff : public StrikedTypePayoff is not interfaced in SWIG

- The Class  CapletConstantVolatility  and its  super class CapletVolatilitystructure
  are not interfaced.

 - The Class InarrearIndexedCoupon and Itssuper class IndexedCoupon are not interfaced.


Nabil



On 10/14/05, Luigi Ballabio <[hidden email]> wrote:

On 10/14/2005 11:24:10 AM, ago wrote:
> I am trying to subclass the RateHelper using python, so that the
> derived class (Inflation Linked Bond) can be used within the
> bootstrapper. I am struggling my way through c++, swig and the
> wrapper code, and so far I failed miserably with the error:
>
> NotImplementedError: No matching function for overloaded
> 'new_PiecewiseFlatForward'

I guess the wrappers didn't recognize instances of your class as rate
helpers. What was the interface you exported? Can you post the relevant
bit of the .i file?


> I then tried the "easier" task of subclassing (in python) the
> SwapRateHelper, overriding some of the methods for testing purposes.

That won't work. SWIG must be told to generate special code for that
(see the SWIG documentation for "directors".) However, I'm under the
impression that it would not work because we're exporting smart
pointers rather than the actual classes.

Later,
        Luigi


----------------------------------------

To err is human -- to blame it on a computer is even more so.
-- unknown



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Quantlib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

Reply | Threaded
Open this post in threaded view
|

ParCoupon and Calendar problem

Siddharth Sharma-3
Hello, all.
I have the following funny situation which I don't
know how to fix. I am building a par curve using a
combination of depos and swaps. For the swaps, I am
using a convention of Unadjusted on both the fixed and
the floating legs. However, this causes a problem when
the swap maturity date is on a weekend. I stepped
through the code and found the following in
parcoupon.cpp in the ParCoupon::amount() method:

Date temp =
index_->calendar().advance(accrualEndDate_,
-fixingDays_, Days);

DiscountFactor endDiscount =          
termStructure->discount(index_->calendar().advance(
temp, index_->settlementDays(), Days));

The problem is that the calendar().advance() takes a
default dayCountConvention of Following. The result is
that my end date (temp) becomes the following Monday.
This causes an exception to be thrown when executing
YieldTermStructure::discount(const Date& d,          
                                           bool
extrapolate) due to the checkRange() method failing.

I'd like to know what's the best way to fix this.

thanks in advance
Sid


               
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


Reply | Threaded
Open this post in threaded view
|

Re: ParCoupon and Calendar problem

Luigi Ballabio
On 10/14/2005 05:38:40 PM, Siddharth Sharma wrote:
> Hello, all.
> I have the following funny situation which I don't
> know how to fix. I am building a par curve using a
> combination of depos and swaps. For the swaps, I am
> using a convention of Unadjusted on both the fixed and
> the floating legs. However, this causes a problem when
> the swap maturity date is on a weekend.
> ...
> I'd like to know what's the best way to fix this.

Siddhart,
        I guess you could modify the ParCoupon so that it takes a  
business-day convention and uses it for adjustment.

Later,
        Luigi

----------------------------------------

There is no opinion so absurd that some philosopher will not
express it.
-- Marcus Tullius Cicero, "Ad familiares"