does anyone use java+swig bindings?

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

does anyone use java+swig bindings?

Tito Ingargiola

Hi,

I've been playing with QuantLib for the last month or so and have more
or less fallen in love.  In c++, everything I've tried works pretty
much as expected.

Unfortunately, I have an extensive gui written in java and when I try
to bridge into QuantLib via the SWIG interfaces I've run into endless
difficulties.  Given the lack of traffic on this list for java users
except the odd "I tried but it didn't work..." post, I wonder if
anyone is actually using the SWIG interfaces for java integration?  If
so, could anyone kindly point me to a non trivial example of java
accessing QuantLib functionality?  The sample provided with the swig
extension is laughably simple and doesn't demonstrate any kind of
parameter passing.

I'm frustrated at this point as things which are simple to do in c++
just don't work via the swig interfaces and I'm getting close to
dumping the swig interfaces and writing my own JNI interfaces for the
relatively limited areas of functionality I'm interested in, but I'd
prefer not to do this if a reasonable alternative exists.  

In order to illustrate the kinds of difficulties I'm running into, I
enclose below a simple sample program based on
Quantlib/Examples/EquityOption which uses the SWIG interfaces and
compiles fine but will crash in several different places when run.
Even such a simple thing as Dates don't seem to work.  That is:


       Date goodDate = Date.todaysDate(); // ok
       goodDate.add(17); // ok
// boom when date is referenced
       Date badDate = new Date( 1, Month.October, 2007);

I have similar experiences with simple objects like quotes or
handles... which is why I question that anyone is actually using these
things.

Any insights, pointers or suggestions will be very much appreciated!
Thanks and regards,

    Tito.

--- the java program I mentioned follows ---




package test;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;
import org.quantlib.BaroneAdesiWhaleyEngine;
import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Date;
import org.quantlib.DayCounter;
import org.quantlib.FlatForward;
import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;
import org.quantlib.PlainVanillaPayoff;
import org.quantlib.QuoteHandle;
import org.quantlib.SimpleQuote;
import org.quantlib.StochasticProcess;
import org.quantlib.VanillaOption;
import org.quantlib.YieldTermStructureHandle;

/**
 * Test app - simplified version of QuantLib/Examples/EquityOption to test
 * use of Quantlib through supplied SWIG interface...
 *
 * @author Tito Ingargiola
 */
public class EquityOption {
    static {
        /* You need to run this thing with something like:
         * -Djava.library.path=/usr/local/lib
         */
        System.loadLibrary("QuantLib-0.8.1");
        System.loadLibrary("QuantLibJNI");
    }
    
    public static void main(String[] args) throws Exception {
        System.out.println("starting...");
        //QuantLib ql = new QuantLib();
        //Thread.sleep(500);

        Option.Type type = Option.Type.Put;
        double strike = 14.7;
        double underlying = 14.76;
        double riskFreeRate = 0.055;
        double divYield = riskFreeRate; // for futures
        double volatility = .22;
        System.out.println("creating dates...");
        Date settle = Date.todaysDate();        // Explicitly setting date
        Date expiry = Date.todaysDate().add(13);//  causes crash...on use(?)
        Date expiry2 = new Date( 20, Month.September, 2007 ); // e.g.
        System.out.println(settle+" -> "+expiry);
        
        AmericanExercise exercise = new AmericanExercise(settle, expiry,true);
        // using the below will cause crash
       // AmericanExercise exercise2 = new AmericanExercise(settle, expiry2,true);
        
        // this is fine ... unless you use it...
        DayCounter dayc = new Actual365Fixed();
        // this is fine ... unless you use it...
        SimpleQuote under = new SimpleQuote(underlying);
        // this instead blows up on construction...
        QuoteHandle underh = new QuoteHandle(under);
        
        /// the rest is pie-in-the-sky stuff...
        
        YieldTermStructureHandle  flatTS = new YieldTermStructureHandle
            (new FlatForward(settle,riskFreeRate, dayc));
        
        YieldTermStructureHandle flatDivTS = new YieldTermStructureHandle
            (new FlatForward(settle,divYield, dayc));

        BlackVolTermStructureHandle flatVolTS = new BlackVolTermStructureHandle
            (new BlackConstantVol(settle,volatility,dayc));
        
        
        StochasticProcess stochp = new BlackScholesMertonProcess
            (underh,flatDivTS,flatTS,flatVolTS);
        Payoff payoff = new PlainVanillaPayoff(type, strike) ;

        VanillaOption option = new VanillaOption
            (stochp, payoff,exercise);
        
        option.setPricingEngine(new BaroneAdesiWhaleyEngine());
        
        System.out.println("Option:   \t"+option);
        System.out.println("NPV:      \t"+option.NPV());
        
        System.out.println("\ndone.");
        
    }
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Tito Ingargiola

Hi Richard,

I am hoping to hear that someone is able to use the swig bindings for something non-trivial in java which is clearly more than you or I have (yet!) managed.  I want to see some code that actually works as I'm skeptical that the bindings are functional for java.

Luigi's response to you seems correct for the case where one wants to access functionality which hasn't yet been mapped in the swig bindings.  My issue is instead one where the swig bindings are defined but they just don't seem to work.  I agree that writing my own JNI stuff wouldn't be fun, but I wouldn't try to map the entire api, just specific questions I might want answered, e.g., the price of an option on a future.  This is a much more constrained issue which isn't so difficult much as I'd prefer to avoid it if the swig stuff can be made to work...

All of that said, if you have a concrete idea about how we can work together, I'm glad to hear it.  For now, it seems a starting point is to get something simple, like what I'd provided, to work.  I hope someone will be able to point us in the direction of a working example.  (Pretty please! :-)

Regards,

    Tito.

ps - I've moved this from the dev to the users list as it seems the more appropriate forum

Richard Gomes <[hidden email]> wrote:
Hi Tito,

I have a lot of code in Java as well and I'd like to plug QuantLib in.

It's incredible how you and me are facing the same problems, following
the same path and started translating the same example! :D When I
looked at you Java code it was quite similar to mine (of course... you
also translated the example in C++).

Oh well...

I dont think that writing your own JNI is a good idea.
It's a huge, boring and error prone task. I'd rely on SWIG instead.
It'd be much easier to learn how to hack the intrincacies of SWIG.

It would be great if we were able to convert comments from C++ code to
JavaDOC as well, as Eclipse would be able to show documentation as you type.

Another thing to be considered is performance.
I tried to use Matrix and it does not make sense to initialize every
cell at a time. The performance will be poor. It means that we should
create additional methods intended to be called by another languages due
to poor performance of separated calls.

I've posted one thread quite similiar to yours and Luigi gave me some
directions. In case, I've use Matrix as an example of issues I've found.

I'm planning to work on SWIG this weekend. Maybe we could work together
on this kind of thing.

Kind Regards

-- Richard Gomes


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Guillaume Dru
Hi,

I'm currently working with Java/SWIG/Quantlib, to convert a C++ program into Java (by implementing new interfaces (.*)) files.
I'll be glad to help you, because I had a lot issues at the beginning .
But now, It works great !
So if you want some advices or tips, don't hesitate (sorry for my horrible english ...)
Could you tell me more about your computer ? (OS, IDE, C++ compiler ...)

Regards


2007/9/6, Tito Ingargiola <[hidden email]>:

Hi Richard,

I am hoping to hear that someone is able to use the swig bindings for something non-trivial in java which is clearly more than you or I have (yet!) managed.  I want to see some code that actually works as I'm skeptical that the bindings are functional for java.

Luigi's response to you seems correct for the case where one wants to access functionality which hasn't yet been mapped in the swig bindings.  My issue is instead one where the swig bindings are defined but they just don't seem to work.  I agree that writing my own JNI stuff wouldn't be fun, but I wouldn't try to map the entire api, just specific questions I might want answered, e.g., the price of an option on a future.  This is a much more constrained issue which isn't so difficult much as I'd prefer to avoid it if the swig stuff can be made to work...

All of that said, if you have a concrete idea about how we can work together, I'm glad to hear it.  For now, it seems a starting point is to get something simple, like what I'd provided, to work.  I hope someone will be able to point us in the direction of a working example.  (Pretty please! :-)

Regards,

    Tito.

ps - I've moved this from the dev to the users list as it seems the more appropriate forum

Richard Gomes <[hidden email]> wrote:
Hi Tito,

I have a lot of code in Java as well and I'd like to plug QuantLib in.

It's incredible how you and me are facing the same problems, following
the same path and started translating the same example! :D When I
looked at you Java code it was quite similar to mine (of course... you
also translated the example in C++).

Oh well...

I dont think that writing your own JNI is a good idea.
It's a huge, boring and error prone task. I'd rely on SWIG instead.
It'd be much easier to learn how to hack the intrincacies of SWIG.

It would be great if we were able to convert comments from C++ code to
JavaDOC as well, as Eclipse would be able to show documentation as you type.

Another thing to be considered is performance.
I tried to use Matrix and it does not make sense to initialize every
cell at a time. The performance will be poor. It means that we should
create additional methods intended to be called by another languages due
to poor performance of separated calls.

I've posted one thread quite similiar to yours and Luigi gave me some
directions. In case, I've use Matrix as an example of issues I've found.

I'm planning to work on SWIG this weekend. Maybe we could work together
on this kind of thing.

Kind Regards

-- Richard Gomes


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> <a href="http://get.splunk.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://get.splunk.com/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
<a href="https://lists.sourceforge.net/lists/listinfo/quantlib-dev" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> https://lists.sourceforge.net/lists/listinfo/quantlib-dev


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://get.splunk.com/" target="_blank"> http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/quantlib-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
Guillaume DRU
'' One would normally define a "religion" as a system of
ideas that contain statements that cannot be logically or
observationally demonstrated... Gödel's theorem not only
demonstrates that mathematics is a religion, but shows
that mathematics is the only religion that proves itself
to be one! ''
J. D. Barrow, The World within the world
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Tito Ingargiola

Hi Guillaume,

Thanks for responding - that sounds great. 

Did you see the example I provided in the original mail?  Can you tell me what's wrong with it?  Alternatively, could you provide a sample program in java which actually does something useful with Quantlib?

Environment: I'm running on linux (ubuntu desktop and redhat enterprise); g++ 4.1.2; java 1.6.0_02; IDEs - emacs & eclipse; latest versions of boost, quantlib, and swig. 

Many thanks in advance for any help you might provide!  Regards,

    Tito.

Guillaume Dru <[hidden email]> wrote:
Hi,

I'm currently working with Java/SWIG/Quantlib, to convert a C++ program into Java (by implementing new interfaces (.*)) files.
I'll be glad to help you, because I had a lot issues at the beginning .
But now, It works great !
So if you want some advices or tips, don't hesitate (sorry for my horrible english ...)
Could you tell me more about your computer ? (OS, IDE, C++ compiler ...)

Regards


2007/9/6, Tito Ingargiola <[hidden email]>:

Hi Richard,

I am hoping to hear that someone is able to use the swig bindings for something non-trivial in java which is clearly more than you or I have (yet!) managed.  I want to see some code that actually works as I'm skeptical that the bindings are functional for java.

Luigi's response to you seems correct for the case where one wants to access functionality which hasn't yet been mapped in the swig bindings.  My issue is instead one where the swig bindings are defined but they just don't seem to work.  I agree that writing my own JNI stuff wouldn't be fun, but I wouldn't try to map the entire api, just specific questions I might want answered, e.g., the price of an option on a future.  This is a much more constrained issue which isn't so difficult much as I'd prefer to avoid it if the swig stuff can be made to work...

All of that said, if you have a concrete idea about how we can work together, I'm glad to hear it.  For now, it seems a starting point is to get something simple, like what I'd provided, to work.  I hope someone will be able to point us in the direction of a working example.  (Pretty please! :-)

Regards,

    Tito.

ps - I've moved this from the dev to the users list as it seems the more appropriate forum

Richard Gomes <[hidden email]> wrote:
Hi Tito,

I have a lot of code in Java as well and I'd like to plug QuantLib in.

It's incredible how you and me are facing the same problems, following
the same path and started translating the same example! :D When I
looked at you Java code it was quite similar to mine (of course... you
also translated the example in C++).

Oh well...

I dont think that writing your own JNI is a good idea.
It's a huge, boring and error prone task. I'd rely on SWIG instead.
It'd be much easier to learn how to hack the intrincacies of SWIG.

It would be great if we were able to convert comments from C++ code to
JavaDOC as well, as Eclipse would be able to show documentation as you type.

Another thing to be considered is performance.
I tried to use Matrix and it does not make sense to initialize every
cell at a time. The performance will be poor. It means that we should
create additional methods intended to be called by another languages due
to poor performance of separated calls.

I've posted one thread quite similiar to yours and Luigi gave me some
directions. In case, I've use Matrix as an example of issues I've found.

I'm planning to work on SWIG this weekend. Maybe we could work together
on this kind of thing.

Kind Regards

-- Richard Gomes


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> <a href="http://get.splunk.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://get.splunk.com/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
<a href="https://lists.sourceforge.net/lists/listinfo/quantlib-dev" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> https://lists.sourceforge.net/lists/listinfo/quantlib-dev


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://get.splunk.com/" target="_blank"> http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/quantlib-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
Guillaume DRU
'' One would normally define a "religion" as a system of
ideas that contain statements that cannot be logically or
observationally demonstrated... Gödel's theorem not only
demonstrates that mathematics is a religion, but shows
that mathematics is the only religion that proves itself
to be one! ''
J. D. Barrow, The World within the world


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Richard Gomes
In reply to this post by Tito Ingargiola


Tito Ingargiola wrote:

>
> Hi Richard,
>
> I am hoping to hear that someone is able to use the swig bindings for
> something non-trivial in java which is clearly more than you or I have
> (yet!) managed.  I want to see some code that actually works as I'm
> skeptical that the bindings are functional for java.
>
> Luigi's response to you seems correct for the case where one wants to
> access functionality which hasn't yet been mapped in the swig bindings.  
> My issue is instead one where the swig bindings are defined but they
> just don't seem to work.  I agree that writing my own JNI stuff wouldn't
> be fun, but I wouldn't try to map the entire api, just specific
> questions I might want answered, e.g., the price of an option on a
> future.  This is a much more constrained issue which isn't so difficult
> much as I'd prefer to avoid it if the swig stuff can be made to work...
>
> All of that said, if you have a concrete idea about how we can work
> together, I'm glad to hear it.  For now, it seems a starting point is to
> get something simple, like what I'd provided, to work.  I hope someone
> will be able to point us in the direction of a working example.  (Pretty
> please! :-)
>
> Regards,
>
>     Tito.
>
> ps - I've moved this from the dev to the users list as it seems the more
> appropriate forum
>
> */Richard Gomes <[hidden email]>/* wrote:
>
>     Hi Tito,
>
>     I have a lot of code in Java as well and I'd like to plug QuantLib in.
>
>     It's incredible how you and me are facing the same problems, following
>     the same path and started translating the same example! :D When I
>     looked at you Java code it was quite similar to mine (of course... you
>     also translated the example in C++).
>
>     Oh well...
>
>     I dont think that writing your own JNI is a good idea.
>     It's a huge, boring and error prone task. I'd rely on SWIG instead.
>     It'd be much easier to learn how to hack the intrincacies of SWIG.
>
>     It would be great if we were able to convert comments from C++ code to
>     JavaDOC as well, as Eclipse would be able to show documentation as
>     you type.
>
>     Another thing to be considered is performance.
>     I tried to use Matrix and it does not make sense to initialize every
>     cell at a time. The performance will be poor. It means that we should
>     create additional methods intended to be called by another languages
>     due
>     to poor performance of separated calls.
>
>     I've posted one thread quite similiar to yours and Luigi gave me some
>     directions. In case, I've use Matrix as an example of issues I've found.
>
>     I'm planning to work on SWIG this weekend. Maybe we could work together
>     on this kind of thing.
>
>     Kind Regards
>
>     -- Richard Gomes
>
>
>     -------------------------------------------------------------------------
>     This SF.net email is sponsored by: Splunk Inc.
>     Still grepping through log files to find problems? Stop.
>     Now Search log events and configuration files using AJAX and a browser.
>     Download your FREE copy of Splunk now >> http://get.splunk.com/
>     _______________________________________________
>     QuantLib-dev mailing list
>     [hidden email]
>     https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>
>

Tito,

I'm still in the beginning but I managed to calculate valuation of
options using Black-Scholes (from the sample translated into Java).
Unfortunately I couldnt make it work for all engines. I'm still trying
to solve but didnt have enough time to hack why Quantlib (C++ code) is
throwing a certain exception.

My idea is focus on something I need to make Java work fine, not
review/validate/implement everything. This is not my aim.

About working together.
 From your previous email, I'm sure we are both very focused, busy and
independent. I think the best alternative is simply share experiences
and send our patches to Luigi.

Regards

--
Richard Gomes
http://www.linkedin.com/in/rgomes
M: +44(77)9955-6813
H: +44(870)068-8205
W: +44(20)7378-3924


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Richard Gomes
In reply to this post by Tito Ingargiola
Tito Ingargiola wrote:

>
> Hi Guillaume,
>
> Thanks for responding - that sounds great.
>
> Did you see the example I provided in the original mail?  Can you tell
> me what's wrong with it?  Alternatively, could you provide a sample
> program in java which actually does something useful with Quantlib?
>
> Environment: I'm running on linux (ubuntu desktop and redhat
> enterprise); g++ 4.1.2; java 1.6.0_02; IDEs - emacs & eclipse; latest
> versions of boost, quantlib, and swig.
>
> Many thanks in advance for any help you might provide!  Regards,
>
>     Tito.
>
> */Guillaume Dru <[hidden email]>/* wrote:
>
>     Hi,
>
>     I'm currently working with Java/SWIG/Quantlib, to convert a C++
>     program into Java (by implementing new interfaces (.*)) files.
>     I'll be glad to help you, because I had a lot issues at the beginning .
>     But now, It works great !
>     So if you want some advices or tips, don't hesitate (sorry for my
>     horrible english ...)
>     Could you tell me more about your computer ? (OS, IDE, C++ compiler ...)
>
>     Regards
>
>
>     2007/9/6, Tito Ingargiola <[hidden email]
>     <mailto:[hidden email]>>:
>
>
>         Hi Richard,
>
>         I am hoping to hear that someone is able to use the swig
>         bindings for something non-trivial in java which is clearly more
>         than you or I have (yet!) managed.  I want to see some code that
>         actually works as I'm skeptical that the bindings are functional
>         for java.
>
>         Luigi's response to you seems correct for the case where one
>         wants to access functionality which hasn't yet been mapped in
>         the swig bindings.  My issue is instead one where the swig
>         bindings are defined but they just don't seem to work.  I agree
>         that writing my own JNI stuff wouldn't be fun, but I wouldn't
>         try to map the entire api, just specific questions I might want
>         answered, e.g., the price of an option on a future.  This is a
>         much more constrained issue which isn't so difficult much as I'd
>         prefer to avoid it if the swig stuff can be made to work...
>
>         All of that said, if you have a concrete idea about how we can
>         work together, I'm glad to hear it.  For now, it seems a
>         starting point is to get something simple, like what I'd
>         provided, to work.  I hope someone will be able to point us in
>         the direction of a working example.  (Pretty please! :-)
>
>         Regards,
>
>             Tito.
>
>         ps - I've moved this from the dev to the users list as it seems
>         the more appropriate forum
>
>         */Richard Gomes < [hidden email]
>         <mailto:[hidden email]>>/* wrote:
>
>             Hi Tito,
>
>             I have a lot of code in Java as well and I'd like to plug
>             QuantLib in.
>
>             It's incredible how you and me are facing the same problems,
>             following
>             the same path and started translating the same example! :D
>             When I
>             looked at you Java code it was quite similar to mine (of
>             course... you
>             also translated the example in C++).
>
>             Oh well...
>
>             I dont think that writing your own JNI is a good idea.
>             It's a huge, boring and error prone task. I'd rely on SWIG
>             instead.
>             It'd be much easier to learn how to hack the intrincacies of
>             SWIG.
>
>             It would be great if we were able to convert comments from
>             C++ code to
>             JavaDOC as well, as Eclipse would be able to show
>             documentation as you type.
>
>             Another thing to be considered is performance.
>             I tried to use Matrix and it does not make sense to
>             initialize every
>             cell at a time. The performance will be poor. It means that
>             we should
>             create additional methods intended to be called by another
>             languages due
>             to poor performance of separated calls.
>
>             I've posted one thread quite similiar to yours and Luigi
>             gave me some
>             directions. In case, I've use Matrix as an example of issues
>             I've found.
>
>             I'm planning to work on SWIG this weekend. Maybe we could
>             work together
>             on this kind of thing.
>
>             Kind Regards
>
>             -- Richard Gomes
>
>
>             -------------------------------------------------------------------------
>             This SF.net email is sponsored by: Splunk Inc.
>             Still grepping through log files to find problems? Stop.
>             Now Search log events and configuration files using AJAX and
>             a browser.
>             Download your FREE copy of Splunk now >> http://get.splunk.com/
>             _______________________________________________
>             QuantLib-dev mailing list
>             [hidden email]
>             <mailto:[hidden email]>
>             https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>
>
>
>         -------------------------------------------------------------------------
>         This SF.net email is sponsored by: Splunk Inc.
>         Still grepping through log files to find problems?  Stop.
>         Now Search log events and configuration files using AJAX and a
>         browser.
>         Download your FREE copy of Splunk now >>   http://get.splunk.com/
>         _______________________________________________
>         QuantLib-users mailing list
>         [hidden email]
>         <mailto:[hidden email]>
>         https://lists.sourceforge.net/lists/listinfo/quantlib-users
>         <https://lists.sourceforge.net/lists/listinfo/quantlib-users>
>
>
>
>
>     --
>     Guillaume DRU
>     '' One would normally define a "religion" as a system of
>     ideas that contain statements that cannot be logically or
>     observationally demonstrated... Gödel's theorem not only
>     demonstrates that mathematics is a religion, but shows
>     that mathematics is the only religion that proves itself
>     to be one! ''
>     J. D. Barrow, The World within the world
>
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-users


Hi Guillaume,

Thank you for your offer.

My environment is

AMD64
Kubuntu 7.04
GCC 4.1.2
Java 1.5.12 for AMD64
Java 1.6.0_02 for AMD64 (still evaluating)
Eclipse 3.3 with CDT
Boost 1.33
Quantlib 0.8.1
QuantLib-SWIG 0.8.0

In spite it's AMD64, everyting is working fine. :)
What is not working fine, I'm sure it's *my* ignorance about QuantLib.

Thanks

-- Richard Gomes


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: does anyone use java+swig bindings?

Luigi Ballabio
In reply to this post by Guillaume Dru
On Thu, 2007-09-06 at 20:50 +0200, Guillaume Dru wrote:
> I'm currently working with Java/SWIG/Quantlib, to convert a C++
> program into Java (by implementing new interfaces (.*)) files.
> I'll be glad to help you, because I had a lot issues at the
> beginning .
> But now, It works great !
> So if you want some advices or tips, don't hesitate (sorry for my
> horrible english ...)

Guillaume, Tito, Richard,
        needless to say, I'll be glad to incorporate any fixes in the official
repository. Just send them to me.

Thanks,
        Luigi


--

A programming language is low-level when its programs require attention
to the irrelevant.
-- Alan Perlis



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

small progress with java+swig

Tito Ingargiola
In reply to this post by Richard Gomes

Hi Guillaume, Richard & Co.,

I installed jdk1.5.0_12 and rebuilt everything with the same results
as with 1.6.

One thing I have found, however, is that when I build the SWIG
bindings, I get many warnings during compilation of the variety:

quantlib_wrap.cpp:90734: warning: dereferencing type-punned pointer will break strict-aliasing rules

I modified the configure script to add '-fno-strict-aliasing' to the
CXXFLAGS and this got rid of the warnings.  More importantly, this
also fixed the problems I had with the program crashing when using a
date or SimpleQuote - progress!  However, I still fail to get values
out of a pricing engine.

Are you guys not seeing these warnings when you build the
QuantLib-SWIG-0.8.0 project? 

I include the sample program I'm using and the output below in case
anyone has an idea what's happening.  I'm still looking forward to
receiving a working example of Java calling non-trivial QuantLib
functionality in case anyone has some code sitting around.

Thanks and regards,

    Tito.

--- output ---

starting...
September 7th, 2007 -> December 21st, 2007
Option:       org.quantlib.VanillaOption@10385c1

java.lang.RuntimeException: no results returned from pricing engine


done.

--- code ---

package test;

import org.quantlib.Actual365Fixed;
import org.quantlib.AmericanExercise;
import org.quantlib.BaroneAdesiWhaleyEngine;
import org.quantlib.BinomialVanillaEngine;
import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Date;
import org.quantlib.DayCounter;
import org.quantlib.FlatForward;
import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;
import org.quantlib.PlainVanillaPayoff;
import org.quantlib.QuantLib;
import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;
import org.quantlib.StochasticProcess;
import org.quantlib.VanillaOption;
import org.quantlib.YieldTermStructureHandle;

/**
 * Test app - simplified version of QuantLib/Examples/EquityOption to test
 * use of Quantlib through supplied SWIG interface...
 *
 * @author Tito Ingargiola
 */
public class EquityOption {
    static {
        /* You need to run this thing with something like:
         * -Djava.library.path=/usr/local/lib
         */
        System.loadLibrary("QuantLib-0.8.1");
        System.loadLibrary("QuantLibJNI");
    }
   
    public static void main(String[] args) throws Exception {
        System.out.println("starting...");
       
        double strike = 14.7;
        double underlying = 14.76;
        double riskFreeRate = 0.055;
        double divYield = riskFreeRate; // for futures
        double volatility = .22;
        Date settle = Date.todaysDate();
        Date expiry = new Date( 21, Month.December, 2007 ); 
        System.out.println(settle+" -> "+expiry);
        Settings.instance().setEvaluationDate(settle);
       
        // we no longer blow up in the following block!
        AmericanExercise exercise = new AmericanExercise(settle, expiry, false);
        DayCounter dayc = new Actual365Fixed();
        SimpleQuote under = new SimpleQuote(underlying);
        QuoteHandle underh = new QuoteHandle(under);
       
        YieldTermStructureHandle  flatTS = new YieldTermStructureHandle
            (new FlatForward(settle,riskFreeRate, dayc));
       
        YieldTermStructureHandle flatDivTS = new YieldTermStructureHandle
            (new FlatForward(settle,divYield, dayc));

        BlackVolTermStructureHandle flatVolTS = new BlackVolTermStructureHandle
            (new BlackConstantVol(settle,volatility,dayc));
       
        StochasticProcess stochp = new BlackScholesMertonProcess
            (underh,flatDivTS,flatTS,flatVolTS);
        Payoff payoff = new PlainVanillaPayoff(Option.Type.Put, strike) ;

        VanillaOption option = new VanillaOption(stochp, payoff,exercise);
 
        // None of these engines produce a result, but in the c++ they do :-/
       
        option.setPricingEngine(new BaroneAdesiWhaleyEngine());
        //option.setPricingEngine(new BinomialVanillaEngine("leisenreimer", 801));
        //option.setPricingEngine(new BinomialVanillaEngine("crr", 801));
        Thread.sleep(1000);
        System.out.println("Option:   \t"+option);
        try {
            System.out.println("NPV:      \t"+option.NPV());
        } catch(Exception e) {
            System.err.println(e);
        }
        System.out.println("\ndone.");  
    }
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: small progress with java+swig

Guillaume Dru
Hi,
I've not this kind of warnings when I compile quantlib_wrap.cpp ...
I send u the command line I use with Cygwin on windows, It may help u :
To compile the .o file :
g++ -I"C:\Program Files\Java\jdk1.5.0_12\include\win32" -I"C:\Program Files\Java\jdk1.5.0_12\include" -I"C:\workspace\QuantLib" -I"C:\Documents and Settings\Administrateur\Mes documents\Developpement\boost_1_33_1"  -O0 -g3 -c -fmessage-length=0 -MMD -MP -MF" cppwrapper.d" -MT"cppwrapper.d" -o"cppwrapper.o" "C:\workspace\QuantLib CPP Wraper\cppwrapper.cpp"

To compile the library (dll for me, so or .a for u)
g++ -L"C:\workspace\QuantLib\Debug" -shared -o" QuantLibCPPWraper.dll" -O0 -g3  -fmessage-length=0 -MMD -MP ./cppwrapper.o   -lQuantLib

Note the library size is approximatively 80MegaBytes.
Good luck !

2007/9/7, Tito Ingargiola < [hidden email]>:

Hi Guillaume, Richard & Co.,

I installed jdk1.5.0_12 and rebuilt everything with the same results
as with 1.6.

One thing I have found, however, is that when I build the SWIG
bindings, I get many warnings during compilation of the variety:

quantlib_wrap.cpp:90734: warning: dereferencing type-punned pointer will break strict-aliasing rules

I modified the configure script to add '-fno-strict-aliasing' to the
CXXFLAGS and this got rid of the warnings.  More importantly, this
also fixed the problems I had with the program crashing when using a
date or SimpleQuote - progress!  However, I still fail to get values
out of a pricing engine.

Are you guys not seeing these warnings when you build the
QuantLib-SWIG-0.8.0 project? 

I include the sample program I'm using and the output below in case
anyone has an idea what's happening.  I'm still looking forward to
receiving a working example of Java calling non-trivial QuantLib
functionality in case anyone has some code sitting around.

Thanks and regards,

    Tito.

--- output ---

starting...
September 7th, 2007 -> December 21st, 2007
Option:       org.quantlib.VanillaOption@10385c1

java.lang.RuntimeException: no results returned from pricing engine


done.

--- code ---

package test;

import org.quantlib.Actual365Fixed ;
import org.quantlib.AmericanExercise;
import org.quantlib.BaroneAdesiWhaleyEngine;
import org.quantlib.BinomialVanillaEngine;
import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess ;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Date;
import org.quantlib.DayCounter;
import org.quantlib.FlatForward;
import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;
import org.quantlib.PlainVanillaPayoff;
import org.quantlib.QuantLib;
import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;
import org.quantlib.StochasticProcess;
import org.quantlib.VanillaOption;
import org.quantlib.YieldTermStructureHandle;

/**
 * Test app - simplified version of QuantLib/Examples/EquityOption to test
 * use of Quantlib through supplied SWIG interface...
 *
 * @author Tito Ingargiola
 */
public class EquityOption {
    static {
        /* You need to run this thing with something like:
         * -Djava.library.path=/usr/local/lib
         */
        System.loadLibrary("QuantLib-0.8.1");
        System.loadLibrary("QuantLibJNI");
    }
   
    public static void main(String[] args) throws Exception {
        System.out.println("starting...");
       
        double strike = 14.7;
        double underlying = 14.76;
        double riskFreeRate = 0.055;
        double divYield = riskFreeRate; // for futures
        double volatility = .22;
        Date settle = Date.todaysDate();
        Date expiry = new Date( 21, Month.December, 2007 ); 
        System.out.println(settle+" -> "+expiry);
        Settings.instance().setEvaluationDate(settle);
       
        // we no longer blow up in the following block!
        AmericanExercise exercise = new AmericanExercise(settle, expiry, false);
        DayCounter dayc = new Actual365Fixed();
        SimpleQuote under = new SimpleQuote(underlying);
        QuoteHandle underh = new QuoteHandle(under);
       
        YieldTermStructureHandle  flatTS = new YieldTermStructureHandle
            (new FlatForward(settle,riskFreeRate, dayc));
       
        YieldTermStructureHandle flatDivTS = new YieldTermStructureHandle
            (new FlatForward(settle,divYield, dayc));

        BlackVolTermStructureHandle flatVolTS = new BlackVolTermStructureHandle
            (new BlackConstantVol(settle,volatility,dayc));
       
        StochasticProcess stochp = new BlackScholesMertonProcess
            (underh,flatDivTS,flatTS,flatVolTS);
        Payoff payoff = new PlainVanillaPayoff(Option.Type.Put, strike) ;

        VanillaOption option = new VanillaOption(stochp, payoff,exercise);
 
        // None of these engines produce a result, but in the c++ they do :-/
       
        option.setPricingEngine(new BaroneAdesiWhaleyEngine());
        //option.setPricingEngine(new BinomialVanillaEngine("leisenreimer", 801));
        //option.setPricingEngine(new BinomialVanillaEngine("crr", 801));
        Thread.sleep(1000);
        System.out.println("Option:   \t"+option);
        try {
            System.out.println("NPV:      \t"+option.NPV());
        } catch(Exception e) {
            System.err.println(e);
        }
        System.out.println("\ndone.");  
    }
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://get.splunk.com/" target="_blank"> http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/quantlib-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
Guillaume DRU
'' One would normally define a "religion" as a system of
ideas that contain statements that cannot be logically or
observationally demonstrated... Gödel's theorem not only
demonstrates that mathematics is a religion, but shows
that mathematics is the only religion that proves itself
to be one! ''
J. D. Barrow, The World within the world
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: small progress with java+swig

Tito Ingargiola
Thank you, Guillaume.  Could you kindly verify that the example program I provided runs in your environment and send me the output?  Many thanks for your help!


Guillaume Dru <[hidden email]> wrote:
Hi,
I've not this kind of warnings when I compile quantlib_wrap.cpp ...
I send u the command line I use with Cygwin on windows, It may help u :
To compile the .o file :
g++ -I"C:\Program Files\Java\jdk1.5.0_12\include\win32" -I"C:\Program Files\Java\jdk1.5.0_12\include" -I"C:\workspace\QuantLib" -I"C:\Documents and Settings\Administrateur\Mes documents\Developpement\boost_1_33_1"  -O0 -g3 -c -fmessage-length=0 -MMD -MP -MF" cppwrapper.d" -MT"cppwrapper.d" -o"cppwrapper.o" "C:\workspace\QuantLib CPP Wraper\cppwrapper.cpp"

To compile the library (dll for me, so or .a for u)
g++ -L"C:\workspace\QuantLib\Debug" -shared -o" QuantLibCPPWraper.dll" -O0 -g3  -fmessage-length=0 -MMD -MP ./cppwrapper.o   -lQuantLib

Note the library size is approximatively 80MegaBytes.
Good luck !

2007/9/7, Tito Ingargiola < [hidden email]>:

Hi Guillaume, Richard & Co.,

I installed jdk1.5.0_12 and rebuilt everything with the same results
as with 1.6.

One thing I have found, however, is that when I build the SWIG
bindings, I get many warnings during compilation of the variety:

quantlib_wrap.cpp:90734: warning: dereferencing type-punned pointer will break strict-aliasing rules

I modified the configure script to add '-fno-strict-aliasing' to the
CXXFLAGS and this got rid of the warnings.  More importantly, this
also fixed the problems I had with the program crashing when using a
date or SimpleQuote - progress!  However, I still fail to get values
out of a pricing engine.

Are you guys not seeing these warnings when you build the
QuantLib-SWIG-0.8.0 project? 

I include the sample program I'm using and the output below in case
anyone has an idea what's happening.  I'm still looking forward to
receiving a working example of Java calling non-trivial QuantLib
functionality in case anyone has some code sitting around.

Thanks and regards,

    Tito.

--- output ---

starting...
September 7th, 2007 -> December 21st, 2007
Option:       org.quantlib.VanillaOption@10385c1

java.lang.RuntimeException: no results returned from pricing engine


done.

--- code ---

package test;

import org.quantlib.Actual365Fixed ;
import org.quantlib.AmericanExercise;
import org.quantlib.BaroneAdesiWhaleyEngine;
import org.quantlib.BinomialVanillaEngine;
import org.quantlib.BlackConstantVol;
import org.quantlib.BlackScholesMertonProcess ;
import org.quantlib.BlackVolTermStructureHandle;
import org.quantlib.Date;
import org.quantlib.DayCounter;
import org.quantlib.FlatForward;
import org.quantlib.Month;
import org.quantlib.Option;
import org.quantlib.Payoff;
import org.quantlib.PlainVanillaPayoff;
import org.quantlib.QuantLib;
import org.quantlib.QuoteHandle;
import org.quantlib.Settings;
import org.quantlib.SimpleQuote;
import org.quantlib.StochasticProcess;
import org.quantlib.VanillaOption;
import org.quantlib.YieldTermStructureHandle;

/**
 * Test app - simplified version of QuantLib/Examples/EquityOption to test
 * use of Quantlib through supplied SWIG interface...
 *
 * @author Tito Ingargiola
 */
public class EquityOption {
    static {
        /* You need to run this thing with something like:
         * -Djava.library.path=/usr/local/lib
         */
        System.loadLibrary("QuantLib-0.8.1");
        System.loadLibrary("QuantLibJNI");
    }
   
    public static void main(String[] args) throws Exception {
        System.out.println("starting...");
       
        double strike = 14.7;
        double underlying = 14.76;
        double riskFreeRate = 0.055;
        double divYield = riskFreeRate; // for futures
        double volatility = .22;
        Date settle = Date.todaysDate();
        Date expiry = new Date( 21, Month.December, 2007 ); 
        System.out.println(settle+" -> "+expiry);
        Settings.instance().setEvaluationDate(settle);
       
        // we no longer blow up in the following block!
        AmericanExercise exercise = new AmericanExercise(settle, expiry, false);
        DayCounter dayc = new Actual365Fixed();
        SimpleQuote under = new SimpleQuote(underlying);
        QuoteHandle underh = new QuoteHandle(under);
       
        YieldTermStructureHandle  flatTS = new YieldTermStructureHandle
            (new FlatForward(settle,riskFreeRate, dayc));
       
        YieldTermStructureHandle flatDivTS = new YieldTermStructureHandle
            (new FlatForward(settle,divYield, dayc));

        BlackVolTermStructureHandle flatVolTS = new BlackVolTermStructureHandle
            (new BlackConstantVol(settle,volatility,dayc));
       
        StochasticProcess stochp = new BlackScholesMertonProcess
            (underh,flatDivTS,flatTS,flatVolTS);
        Payoff payoff = new PlainVanillaPayoff(Option.Type.Put, strike) ;

        VanillaOption option = new VanillaOption(stochp, payoff,exercise);
 
        // None of these engines produce a result, but in the c++ they do :-/
       
        option.setPricingEngine(new BaroneAdesiWhaleyEngine());
        //option.setPricingEngine(new BinomialVanillaEngine("leisenreimer", 801));
        //option.setPricingEngine(new BinomialVanillaEngine("crr", 801));
        Thread.sleep(1000);
        System.out.println("Option:   \t"+option);
        try {
            System.out.println("NPV:      \t"+option.NPV());
        } catch(Exception e) {
            System.err.println(e);
        }
        System.out.println("\ndone.");  
    }
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://get.splunk.com/" target="_blank"> http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/quantlib-users" target="_blank">https://lists.sourceforge.net/lists/listinfo/quantlib-users




--
Guillaume DRU
'' One would normally define a "religion" as a system of
ideas that contain statements that cannot be logically or
observationally demonstrated... Gödel's theorem not only
demonstrates that mathematics is a religion, but shows
that mathematics is the only religion that proves itself
to be one! ''
J. D. Barrow, The World within the world


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users