Archive

Archive for June, 2008

using Quantlib from Java

June 14th, 2008

A free/open-source library for quantitative finance

One of these days I’m going to give an overview of all the excellent open-source software I use on a daily basis. Until that day comes, I’ll observe that finance remains one of the big areas where open-source software has made relatively limited inroads.Java

Two production-quality packages fight that unhappy state: QuantLib – a comprehensive framework for quantitative finance – and QuickFix – a full-featured FIX engine. Both are C++ libraries and both provide very nice interfaces to facilitate integration with other languages, including Java. QuantLib is a big and complicated library and integrating it with Java is not totally obvious. Below, I’ll describe how to build and use QuantLib from Java.

These instructions are based on a unix installation. I’m not really a windows developer and don’t have all the shiny tools that windows developers use, so it’s not an area of focus for me. That said, I have managed to build QuantLib under windows by using MinGW+MSYS but it wasn’t terribly easy and I don’t currently have a working installation, so I won’t cover that here. If this is your aim, don’t be dismayed as it is possible and it had all the functionality I enjoy under linux.

Using QuantLib from Java (on linux)

  • Build QuantLib
    • Requires a working version of Boost. This may prove to be the hardest step of all and you’ll need to use the ample documentation provided by the Boost team.
    • Once you have a working copy of Boost, building QuantLib should require little more than
    • sh autogen.sh
      ./configure

      make
      sudo make install

  • Build QuantLib-SWIG
    • Requires a working copy of SWIG. Again, look to the SWIG instructions, but it should be easy.
    • Once SWIG is available, building the QuantLib/SWIG interfaces should only require:
    • sh autogen.sh
      ./configure \

      –with-jdk-include=${JAVA_HOME}/include \
      –with-jdk-system-include=${JAVA_HOME}/include/linux
      make -C Java
      sudo make install

  • Now you’ll have a Jar file with all of the SWIG/JNI stubs in it available in /usr/local/lib/QuantLib.jar. Add this to your classpath.
  • Programs which call QuantLib functionality will need to have the LD_LIBRARY_PATH set. This can be done by invoking the vm with something like:
  • -Djava.library.path=/usr/local/lib

  • Programs which call QuantLib functionality will also need to explicitly load the QuantLib libraries. This can be done with something like the following static block appearing before your main method:
  • static { // Load QuantLib
    try { System.loadLibrary("QuantLibJNI"); }
    catch (RuntimeException e) { e.printStackTrace(); }
    }

  • That’s it. Now test your configuration by running the examples in Quantlib-SWIG/Java/examples.

It’s worth understanding how Quantlib is being used from java. SWIG is creating a JNI interface into those methods within Quantlib which have been exposed through their declaration in the swig *.i files. These files are found in Quantlib-SWIG/SWIG and they determine what functionality from Quantlib will be available to you. You’ll likely need to get familiar with a subset of those files that you care about. If you find that some functionality you care about isn’t exposed in those files, you may need to expose it yourself.

There’s a learning curve, but it’s worth traversing so you can get at all the rich functionality so many smart people have put together.

FIX Protocol, monte-carlo methods, open-source software, options pricing, technology

unsung virtues of a dynamic hedge

June 4th, 2008

unsung virtues of a dynamic hedge

I’ve recently been working-on and trading an equity strategy that has some great characteristics and some interesting challenges. The great characteristics revolve around its profitability, volatility and simplicity. The challenges start with the fact that the strategy generates alpha on the short side – thus, you are intrinsically swimming against the tide and can conceivably be ruined in a hurry. Your broker might also be unable to find inventory to short. Other challenges include the native capacity of the strategy – it’s not fundamentally scalable as a strategy and only a relatively small amount of money could be put against it without incurring increasingly onerous costs and risks. In any case, it’s been a fun strategy to develop as it’s an interesting puzzle and it makes money.

Discussing the strategy recently with a potential client, they observed that such a strategy wouldn’t be acceptable within their environment (apart the capacity issues) as their risk management practices required all strategies to maintain dollar neutrality – for any dollar of x that they used to buy something, they needed to sell a dollar of y. This led to an interesting experiment for me, the results of which I share with you below.

Read more…

performance analysis, portfolio management, strategy development