Posted by
Tito Ingargiola on
URL: http://quantlib.414.s1.nabble.com/does-anyone-use-java-swig-bindings-tp1326p1331.html
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