Python: BlackIborCouponPricer; SwapRateHelper solved

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

Python: BlackIborCouponPricer; SwapRateHelper solved

Chuck Swiger-4

Thanks to the example in Python/test I found I had a wrong argument
(using libor6m, instead of libor6m() ).

Made much more progress with Bonds.cpp, now I'm stuck on how to
Pythonize:

        // Coupon pricers
         boost::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer);


It exists in Quantlib-0.9.7/ql/cashflows/couponpricer.cpp, the closest I
can find in quantlib_wrap.cpp is  IborCoupon

Any clue appreciated..


--Chuck



------------------------------------------------------------------------------
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: Python: BlackIborCouponPricer; SwapRateHelper solved

Luigi Ballabio
On Thu, 2009-09-17 at 12:53 -0400, Charles Swiger wrote:
> Made much more progress with Bonds.cpp, now I'm stuck on how to
> Pythonize:
>
> // Coupon pricers
>          boost::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer);
>
>
> It exists in Quantlib-0.9.7/ql/cashflows/couponpricer.cpp, the closest I
> can find in quantlib_wrap.cpp is  IborCoupon

That's not exported. It should be added to the SWIG interface. Do you
want to have a try? You should export
shared_ptr<FloatingRateCouponPricer>. You can look at the way
shared_ptr<CashFlow> is exported to get an example. I'll be here if you
get stuck.

Luigi


--

Olmstead's Law:
After all is said and done, a hell of a lot more is said
than done.



------------------------------------------------------------------------------
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: Python: BlackIborCouponPricer; SwapRateHelper solved

Lluis Pujol Bajador
Hi,

I am also interested on using floating Rate Bonds on Python.
(unfortunatelly I am novice to both Quantlib and SWIG)

I am trying to create the shared_ptr<FloatingRateCouponPricer>
interface, as suggested I followed the shared_ptr<CashFlow>, but I got
lost with the private member and also the registerWith that cointains
IborCouponPricer.

This is the C++ version of IborCouponPricer, any help would be appreciated.

class IborCouponPricer : public FloatingRateCouponPricer {
      public:
        IborCouponPricer(const Handle<OptionletVolatilityStructure>& v =
                                         
Handle<OptionletVolatilityStructure>())
        : capletVol_(v) { registerWith(capletVol_); }

        Handle<OptionletVolatilityStructure> capletVolatility() const{
            return capletVol_;
        }
        void setCapletVolatility(
                            const Handle<OptionletVolatilityStructure>& v =
                                   
Handle<OptionletVolatilityStructure>()) {
            unregisterWith(capletVol_);
            capletVol_ = v;
            registerWith(capletVol_);
            update();
        }
      private:
        Handle<OptionletVolatilityStructure> capletVol_;
    };

Lluís


Luigi Ballabio escribió:

> On Thu, 2009-09-17 at 12:53 -0400, Charles Swiger wrote:
>  
>> Made much more progress with Bonds.cpp, now I'm stuck on how to
>> Pythonize:
>>
>> // Coupon pricers
>>          boost::shared_ptr<IborCouponPricer> pricer(new BlackIborCouponPricer);
>>
>>
>> It exists in Quantlib-0.9.7/ql/cashflows/couponpricer.cpp, the closest I
>> can find in quantlib_wrap.cpp is  IborCoupon
>>    
>
> That's not exported. It should be added to the SWIG interface. Do you
> want to have a try? You should export
> shared_ptr<FloatingRateCouponPricer>. You can look at the way
> shared_ptr<CashFlow> is exported to get an example. I'll be here if you
> get stuck.
>
> Luigi
>
>
>  



__________ Información de ESET NOD32 Antivirus, versión de la base de firmas de virus 4589 (20091109) __________

ESET NOD32 Antivirus ha comprobado este mensaje.

http://www.eset.com



------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Python: BlackIborCouponPricer; SwapRateHelper solved

Luigi Ballabio
On Mon, 2009-11-09 at 21:13 +0100, Lluís Pujol wrote:
> I am trying to create the shared_ptr<FloatingRateCouponPricer>
> interface, as suggested I followed the shared_ptr<CashFlow>, but I got
> lost with the private member and also the registerWith that cointains
> IborCouponPricer.

Sorry for the delay.

I meant something like this for the base class:

%ignore IborCouponPricer;
class IborCouponPricer {
  public:
    // export the public interface here, if needed
};

%template(IborCouponPricer) boost::shared_ptr<IborCouponPricer>;

After that,
1) you'll add the setPricer() method to IborCoupon taking a
boost::shared_ptr<IborCouponPricer>;
2) you'll export the constructors for the concrete pricers such as
BlackIborCouponPricer with something like:

%{
typedef boost::shared_ptr<IborCouponPricer> BlackIborCouponPricerPtr;
%}

%rename(BlackIborCouponPricer) BlackIborCouponPricerPtr;
class BlackIborCouponPricerPtr
: public boost::shared_ptr<IborCouponPricer> {
  public:
    %extend {
        BlackIborCouponPricerPtr(...) {
            return new BlackIborCouponPricerPtr(
                new BlackIborCouponPricer(...));
        }
    }
};


Luigi




--

Discontent is the first necessity of progress.
-- Thomas A. Edison



------------------------------------------------------------------------------
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
Reply | Threaded
Open this post in threaded view
|

Re: Python: BlackIborCouponPricer

Lluis Pujol Bajador
Hi,

After a long time without being able to play with it I've tried again to
implement the SWIG interfaces needed to use FRN in Python.

As suggested by Luigi I exported the IborCouponPricer and
BlackIborCouponPricer with no compiling errors but I have not been able
to test it as I am getting stuck now with the following sentence  (from
C++ bond Examples)

   setCouponPricer(floatingRateBond.cashflows(),pricer);

I exported setCouponPricer as:

void setCouponPricer(const std::vector<boost::shared_ptr<CashFlow> >&  ,
const boost::shared_ptr<IborCouponPricer>& );

I get the following error when I try to use it on Python.

Traceback (most recent call last):

     setCouponPricer(frn.cashflows,pricer)
TypeError: in method 'setCouponPricer', argument 1 of type 'std::vector<
boost::shared_ptr< CashFlow >,std::allocator< boost::shared_ptr<
CashFlow > > > const &'

I attach the couponpricer interface. (please don't complain as I am
really newby to SWIG and C++).

Any help is appreciated.

Lluís

Luigi Ballabio escribió:

> On Mon, 2009-11-09 at 21:13 +0100, Lluís Pujol wrote:
>  
>> I am trying to create the shared_ptr<FloatingRateCouponPricer>
>> interface, as suggested I followed the shared_ptr<CashFlow>, but I got
>> lost with the private member and also the registerWith that cointains
>> IborCouponPricer.
>>    
>
> Sorry for the delay.
>
> I meant something like this for the base class:
>
> %ignore IborCouponPricer;
> class IborCouponPricer {
>   public:
>     // export the public interface here, if needed
> };
>
> %template(IborCouponPricer) boost::shared_ptr<IborCouponPricer>;
>
> After that,
> 1) you'll add the setPricer() method to IborCoupon taking a
> boost::shared_ptr<IborCouponPricer>;
> 2) you'll export the constructors for the concrete pricers such as
> BlackIborCouponPricer with something like:
>
> %{
> typedef boost::shared_ptr<IborCouponPricer> BlackIborCouponPricerPtr;
> %}
>
> %rename(BlackIborCouponPricer) BlackIborCouponPricerPtr;
> class BlackIborCouponPricerPtr
> : public boost::shared_ptr<IborCouponPricer> {
>   public:
>     %extend {
>         BlackIborCouponPricerPtr(...) {
>             return new BlackIborCouponPricerPtr(
>                 new BlackIborCouponPricer(...));
>         }
>     }
> };
>
>
> Luigi
>
>
>
>
>  




%{
using QuantLib::IborCouponPricer;
%}

%ignore IborCouponPricer;
class IborCouponPricer {
  public:
    IborCouponPricer(const Handle<OptionletVolatilityStructure>& v =
                                          Handle<OptionletVolatilityStructure>())
        : capletVol_(v) { registerWith(capletVol_); }

        Handle<OptionletVolatilityStructure> capletVolatility() const{
            return capletVol_;}

        void setCapletVolatility(
                            const Handle<OptionletVolatilityStructure>& v =
                                    Handle<OptionletVolatilityStructure>()) {
            unregisterWith(capletVol_);
            capletVol_ = v;
            registerWith(capletVol_);
            update();
        }
};

%template(IborCouponPricer) boost::shared_ptr<IborCouponPricer>;

// implementations
%{
using QuantLib::BlackIborCouponPricer;
%}
%{

typedef boost::shared_ptr<IborCouponPricer> BlackIborCouponPricerPtr;

%}

%rename(BlackIborCouponPricer) BlackIborCouponPricerPtr;
class BlackIborCouponPricerPtr : public boost::shared_ptr<IborCouponPricer> {
    public:
        %extend {
        BlackIborCouponPricerPtr(const Handle<OptionletVolatilityStructure>& v =
                                          Handle<OptionletVolatilityStructure>()) {
            return new BlackIborCouponPricerPtr(
                new BlackIborCouponPricer(v));}
       
                }
   
};

void setCouponPricer(const std::vector<boost::shared_ptr<CashFlow> >&  , const boost::shared_ptr<IborCouponPricer>& );




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

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Python: BlackIborCouponPricer

Luigi Ballabio
On Sat, 2010-04-24 at 01:26 +0200, Lluis Pujol wrote:

> As suggested by Luigi I exported the IborCouponPricer and
> BlackIborCouponPricer with no compiling errors [...] I get the
> following error when I try to use it on Python.
>
> Traceback (most recent call last):
>
>      setCouponPricer(frn.cashflows,pricer)
> TypeError: in method 'setCouponPricer', argument 1 of type 'std::vector<
> boost::shared_ptr< CashFlow >,std::allocator< boost::shared_ptr<
> CashFlow > > > const &'

I think you mean
        setCouponPricer(frn.cashflows(),pricer)
(note the () after cashflows.)
If that still doesn't work, it might be that the declaration is not
picking up the typemap for cash-flow vectors. Try adding

%include cashflows.i

at the beginning of couponpricer.i.

Luigi


--

This gubblick contains many nonsklarkish English flutzpahs, but the
overall pluggandisp can be glorked from context.
-- David Moser



------------------------------------------------------------------------------
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users