Re: Python: BlackIborCouponPricer

Posted by Lluis Pujol Bajador on
URL: http://quantlib.414.s1.nabble.com/Python-BlackIborCouponPricer-SwapRateHelper-solved-tp5560p5564.html

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