Re: small progress with java+swig

Posted by Guillaume Dru on
URL: http://quantlib.414.s1.nabble.com/does-anyone-use-java-swig-bindings-tp1326p1332.html

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