Re: QuantLib Java

Posted by John Nichol-2 on
URL: http://quantlib.414.s1.nabble.com/QuantLib-Java-tp4013p4017.html

Johan,

Re 2) I tried downloading the latest HEAD from CVS but it wasn't building at the time I tried. I will try again when I have some spare time.
Re 3) I persevered and managed to get the functionallity I wanted exposed through SWIG. All I have had to update is the .i files. If anyone is interested I am happy to contribute them back, frankly I have done nothing other than follow the patterns you introduced. My area of interest at the moment is bond based pricing and so the changes are mainly exposing relevant enumerations and methods to access the bond cashflows to do duration and convexity calculations.

Finally I have never actually managed to get things building as cleanly as I would like with the 0.3.10 version of QuantLib. The C++ and Java generated by SWIG both need minor tweeks to get them working correctly. Its limited to 4 C++ methods (not in areas I have touched) and one Java method. Did you have to make minor Java/C++ generated code tweeks to get the code to compile?

The specific problems were
1) quantlib.cxx - the following generated method will not compile


//JNIEXPORT jlong JNICALL Java_org_quantlib_quantlibJNI_SWIGTimeGridUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
//    jlong baseptr = 0;
//    (void)jenv;
//    (void)jcls;
//    *(std::vector<double > **)(void *)&baseptr = *(TimeGrid **)(void *)&jarg1;
//    return baseptr;
//}

//JNIEXPORT jlong JNICALL Java_org_quantlib_quantlibJNI_SWIGStochasticProcess1DUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
//    jlong baseptr = 0;
//    (void)jenv;
//    (void)jcls;
//    *(boost::shared_ptr<GenericStochasticProcess > **)(void *)&baseptr = *(StochasticProcess1DPtr **)(void *)&jarg1;
//    return baseptr;
//}
//
//JNIEXPORT jlong JNICALL Java_org_quantlib_quantlibJNI_SWIGBlackScholesProcessUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
//    jlong baseptr = 0;
//    (void)jenv;
//    (void)jcls;
//    *(StochasticProcess1DPtr **)(void *)&baseptr = *(BlackScholesProcessPtr **)(void *)&jarg1;
//    return baseptr;
//}
//
//JNIEXPORT jlong JNICALL Java_org_quantlib_quantlibJNI_SWIGMerton76ProcessUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
//    jlong baseptr = 0;
//    (void)jenv;
//    (void)jcls;
//    *(StochasticProcess1DPtr **)(void *)&baseptr = *(Merton76ProcessPtr **)(void *)&jarg1;
//    return baseptr;
//}

2) In TimeGrid.java the size method would not compile until I changed it to
  public long size() {
    return quantlibJNI.TimeGrid_size(swigCPtr);
  }

All of these problems were building 0.3.10 quantlib  *.i files. It may be that these are some of the corrections you have already made!

Regards,

John



[hidden email] wrote:
Hi,

some quick answers to your questions:
1) When is 0.3.11 likely to be released? I don't know, that's up to quantlib.org. I understand this is the first release expected to have the undated Swig interfaces: That is correct.
2) Is there is a CVS tag or version of the Swig files for Java that work
with the 0.3.10 release, basically  a bundle of the changes Jonah made? I don't think so... why not download quantlib from the cvs and download 0.3.11 version of quantlib AND swig interface files?
3) Indeed, simply because no one has needed to expose this functionality yet!

regards,
Johan Witters
  
-----Original Message-----
From: John Nichol [[hidden email]]
Sent: Wednesday, August 31, 2005 02:22 PM
To: [hidden email]
Subject: [Quantlib-users] QuantLib Java

Hi,

QuantLib looks very interesting, great work! I am new to QuantLib and
SWIG so apologies if I am asking stupid or inappropriate questions, have
spent many hours searching and building and googling to get to where I
am now!

I have followed Jonah Witters thread "Quantlib available from Java +
using Eclipse as IDE for building quantlib" and followed though his
tutorial as best I can with the 0.3.10 version of QuantLib + some
downloads from CVS.

I have a few questions that I would appreciate some input on
1) When is 0.3.11 likely to be released? I understand this is the first
release expected to have the undated Swig interfaces.
2) Is there is a CVS tag or version of the Swig files for Java that work
with the 0.3.10 release, basically  a bundle of the changes Jonah made?
3) Looking at the latest files in CVS it seems there is still a
functionality missing from the Swig files. E.g. bond.i does not expose
several important methods like

       const std::vector<boost::shared_ptr<CashFlow> >& cashflows() const;
       const boost::shared_ptr<CashFlow>& redemption() const;
       const Calendar& calendar() const;
       BusinessDayConvention businessDayConvention() const;
       const DayCounter& dayCounter() const;
       Frequency frequency() const;

Is this because SWIG does not support exposing this functionality (I
will ask this on the SWIG list), or simply because no one has needed to
expose this functionality yet?

I had a go at making redemption() available in the bond.i file but
wasn't able to get access to the CashFlow object in a useful way. I
could get a SWIGTYPE_p_CashFlow java object, but I can't see how one
uses that. My C++ is very very rusty so I am probably just being a muppet!

Thanks,

John