Login  Register

Re: swig some class are not wrapped

Posted by archlight on Jul 14, 2011; 1:47am
URL: http://quantlib.414.s1.nabble.com/swig-some-class-are-not-wrapped-tp6058p6071.html

Thank you so much, Lluis. I was frustrated for a while and moved to other experimenting other products. with your help, I can come back and look at it again.

Regards
Ren Wei

On Wed, Jul 13, 2011 at 6:24 AM, Lluis Pujol <[hidden email]> wrote:
Hi Ren,

Probably you have already sort it out, but just in case.....

I am trying to do the same you did (try to port the cms to Python), and I had similar difficulties. But I am able to create a SwaptionVolCube2 with the approach 1 that you pointed out below.
I tried to execute your python but with my interfaces and get the same Boost assertion error (altough I don't understand why). I've look at it and I replaced your atmVol declaration for the following one and the error dissapears.

atmVol = SwaptionVolatilityStructureHandle(SwaptionVolatilityMatrix(calendar,
                                 Following,
                                 atmOptionTenors,
                                 atmSwapTenors,
                                 Matrix(m),
                                 Actual365Fixed()));


To do so you will need to include the following overload depending if you input a matrix or a vector of vectors.
SwaptionVolatilityMatrixPtr(const Calendar& calendar,
                                BusinessDayConvention bdc,
                                    const std::vector<Period>& optionTenors,
                                    const std::vector<Period>& swapTenors,
                                    const std::vector<std::vector<Handle<Quote> > >& vols,
                                    const DayCounter& dayCounter){
            return new SwaptionVolatilityMatrixPtr(
                new SwaptionVolatilityMatrix(calendar,bdc,optionTenors,swapTenors,vols,dayCounter));
      
         } 

    SwaptionVolatilityMatrixPtr(
                    const Calendar& calendar,
                    BusinessDayConvention bdc,
                    const std::vector<Period>& optionTenors,
                    const std::vector<Period>& swapTenors,
                    const Matrix& vols,
                    const DayCounter& dayCounter){
            return new SwaptionVolatilityMatrixPtr(
                new SwaptionVolatilityMatrix(calendar,bdc,optionTenors,swapTenors,vols,dayCounter));
         } 
    }

I additionally solved the initial vector of vector problems with the following as suggested by Francis in a recent thread.

In marketelements.i
namespace std {
    %template(QuoteVector) vector<boost::shared_ptr<Quote> >;
    %template(QuoteHandleVector) vector<Handle<Quote> >;
    %template(RelinkableQuoteHandleVector) vector<RelinkableHandle<Quote> >;
    
    // Additional lines required:
    // -----------------------------------
    %template(QuoteVVector) vector<vector<boost::shared_ptr<Quote> > >;
    %template(QuoteHandleVVector) vector<vector<Handle<Quote> > >;
    %template(RelinkableQuoteHandleVVector) vector<vector<RelinkableHandle<Quote> > >;
}

I hope it helps.

If I ever finnish the cms test for python i will post it (together with the required interfaces). I am currently stuck with some casting issues in SwaptionVolCube1 and MakeCms that I cannot figure it out.

Lluís


El 07/03/2011 15:43, ren wei escribió:
Hi 

   I have been stuck on this for quite some time. I managed to get it compiled. but I get error RuntimeError: Boost assertion failed: px != 0

   basically i took two approaches. 

   1) pass boost::shared_ptr<Index> in SwaptionVolCube2 constructor and dynamically cast to boost::shared_ptr<SwapIndex>. the reason is EuriborSwapIsdaFixA is casted as boost::shared_ptr<Index> but  SwaptionVolCube2  accepts only SwapIndex

   2) change export_swap_instance macro and cast EuriborSwapIsdaFixA as boost::shared_ptr<SwapIndex> so it can pass in constuctor

   attached are two version interface file and testing python, please take a look when you have a time

Regards

On Thu, Mar 3, 2011 at 11:10 PM, ren wei <[hidden email]> wrote:
I am using swig 2.0.1 and quantlib compiled by VC 2008 as required by python 2.7

What version do you use to generate quantlib_wrapper? maybe I should back date to that version

Regards


On Thu, Mar 3, 2011 at 9:39 PM, Luigi Ballabio <[hidden email]> wrote:
On Thu, 2011-03-03 at 18:08 +0800, ren wei wrote:
> Hi Luigi,
>
>    Thanks for your reply. it is working with quantlib_wrapper in the
> download package. if I use swig to generate myself, it has such
> problem even though I don't touch any interface files.
>
>    is it swig version issue?

Possibly.  What SWIG version and QuantLib version are you using?

Luigi


--

Prediction is very difficult, especially if it's about the future.
-- Niels Bohr




------------------------------------------------------------------------------ What You Don't Know About Data Connectivity CAN Hurt You This paper provides an overview of data connectivity, details its effect on application quality, and explores various alternative solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users



------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users