SWIG C#

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

SWIG C#

Martin Champness

Hi,

 

Just wondered if anyone has attempted to use swig to create a C# wrapper for quantlib? How robust was the solution? And what were the problems encountered?

 

I am also interested in peoples opinion on how it would compare to writing a hand crafted managed c++ wrapper which could then be called from C#.

Obviously, the manual coding of the C++ would take longer but it may offer benefits in terms of performance as you can design fat interfaces to avoid excessive interop.

 

Thanks,

Martin

 

Martin Champness

TRG Management Singapore PTE LTD

#25-03 Centennial Tower

3 Temasek Avenue

Singapore 039190

 

DID: (65) 6826 1816

 

Reply | Threaded
Open this post in threaded view
|

Re: SWIG C#

Luigi Ballabio
On 10/14/2005 01:13:31 PM, Martin Champness wrote:
> Just wondered if anyone has attempted to use swig to create a C#
> wrapper for quantlib?

Dominic Thuillier contributed one which will be included in next  
release. I'll step back and let him answer further questions...

Luigi



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

For every problem there is one solution which is simple, neat, and  
wrong.
-- H. L. Mencken



Reply | Threaded
Open this post in threaded view
|

RE: SWIG C#

dominic.thuillier
In reply to this post by Martin Champness
Hi,

As Luigi mentioned, I made the changes to the QuantLib Swig interface files
in order to generate C# wrappers.
Hence in the next version of QuantLib, all the APIs exported to
Python/Ruby/... will also be available in C#.

I rewrote the Bermudan swaption example, which will be included in the
release. It seems to run fine. I have not tackled the other examples, since
I was primarily interested in swaption valuation.

Overall it was surprisingly easy to do : only some minor changes in the way
enums are mapped, a renaming of "params" and "Array" since they are C#
keywords, and other minor things. SWIG is really a fantastic tool, and the
QL interface files were clean and simple enough to incorporate C# mapping.

I worked 2 years ago on the mapping of a complex C++ library to .Net. We
tried real hard (with the help of .Net experts) to use Microsoft's IJW ("It
Just Works") functionality to map in a c++ managed manner the library. It
turned out to be very difficult, if not impossible. It was partly due to the
complexity and design of the legacy C++ library, but the bottom line is that
I did not fancy to live the same experience with QuantLib! Now maybe things
have evolved well and matured, and it may have become simpler!

IMHO, the advantages/drawbacks of the 2 solutions are :

SWIG/C# :
Advantage : uses same interfaces file and technology to map from C++ to
multiple languages at the same time.
Drawback : Difficult to extend the library by inheritance.

Managed C++ (Less sure about this...) :
Advantage : probably faster, since less interop
Drawback : a lot of manual work, only to target the .Net platform...


Cheers,
Dominic.
________________________________________
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Martin
Champness
Sent: vendredi 14 octobre 2005 13:14
To: [hidden email]
Subject: [Quantlib-users] SWIG C#

Hi,

Just wondered if anyone has attempted to use swig to create a C# wrapper for
quantlib? How robust was the solution? And what were the problems
encountered?

I am also interested in peoples opinion on how it would compare to writing a
hand crafted managed c++ wrapper which could then be called from C#.
Obviously, the manual coding of the C++ would take longer but it may offer
benefits in terms of performance as you can design fat interfaces to avoid
excessive interop.

Thanks,
Martin

Martin Champness
TRG Management Singapore PTE LTD
#25-03 Centennial Tower
3 Temasek Avenue
Singapore 039190
 
DID: (65) 6826 1816






Reply | Threaded
Open this post in threaded view
|

RE: SWIG C#

Martin Champness
In reply to this post by Martin Champness
Hi Dominic,
        Thanks for the information. I can understand your frustration with creating a managed C++ wrapper, as I have been attempting this recently. My C++ is very rusty though.

        BTW, do you know when the planned release is for the next version of quantlib? The SWIG created wrapper sounds like a promising way to go. Just wondered if you have any comments on the performance or robustness?

Thanks,
Martin


-----Original Message-----
From: dominic.thuillier [mailto:[hidden email]]
Sent: Saturday, October 15, 2005 3:49 AM
To: Martin Champness
Cc: [hidden email]
Subject: RE: [Quantlib-users] SWIG C#

Hi,

As Luigi mentioned, I made the changes to the QuantLib Swig interface files
in order to generate C# wrappers.
Hence in the next version of QuantLib, all the APIs exported to
Python/Ruby/... will also be available in C#.

I rewrote the Bermudan swaption example, which will be included in the
release. It seems to run fine. I have not tackled the other examples, since
I was primarily interested in swaption valuation.

Overall it was surprisingly easy to do : only some minor changes in the way
enums are mapped, a renaming of "params" and "Array" since they are C#
keywords, and other minor things. SWIG is really a fantastic tool, and the
QL interface files were clean and simple enough to incorporate C# mapping.

I worked 2 years ago on the mapping of a complex C++ library to .Net. We
tried real hard (with the help of .Net experts) to use Microsoft's IJW ("It
Just Works") functionality to map in a c++ managed manner the library. It
turned out to be very difficult, if not impossible. It was partly due to the
complexity and design of the legacy C++ library, but the bottom line is that
I did not fancy to live the same experience with QuantLib! Now maybe things
have evolved well and matured, and it may have become simpler!

IMHO, the advantages/drawbacks of the 2 solutions are :

SWIG/C# :
Advantage : uses same interfaces file and technology to map from C++ to
multiple languages at the same time.
Drawback : Difficult to extend the library by inheritance.

Managed C++ (Less sure about this...) :
Advantage : probably faster, since less interop
Drawback : a lot of manual work, only to target the .Net platform...


Cheers,
Dominic.
________________________________________
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Martin
Champness
Sent: vendredi 14 octobre 2005 13:14
To: [hidden email]
Subject: [Quantlib-users] SWIG C#

Hi,

Just wondered if anyone has attempted to use swig to create a C# wrapper for
quantlib? How robust was the solution? And what were the problems
encountered?

I am also interested in peoples opinion on how it would compare to writing a
hand crafted managed c++ wrapper which could then be called from C#.
Obviously, the manual coding of the C++ would take longer but it may offer
benefits in terms of performance as you can design fat interfaces to avoid
excessive interop.

Thanks,
Martin

Martin Champness
TRG Management Singapore PTE LTD
#25-03 Centennial Tower
3 Temasek Avenue
Singapore 039190
 
DID: (65) 6826 1816







Reply | Threaded
Open this post in threaded view
|

Re: SWIG C#

Luigi Ballabio
On 10/17/2005 03:50:53 AM, Martin Champness wrote:
> BTW, do you know when the planned release is for the next
> version of quantlib?

I'm trying to get it out this week.

Luigi


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

Everything can be filed under "miscellaneous".
-- unknown