[ This is an article that I started writing a few years back, when I was experimenting with Puppy Linux, then put on hold. Much of it is still useful, so the post merits to go public. ]
Having written a walk-through on how to set up a Linux system ready for compiling software (see here), in this post I give a walk-through of how to set up and use the open-source quant library QuantLib.
Since QuantLib is built using the Boost libraries, we start by installing the Boost C++ libraries.
The QuantLib website states that Boost 1.34.1 is the minimal version needed. As of writing this post, Boost is at version 1.52.0. I downloaded version 1.52.0 from here.
In the top banner there is a link to the getting started section which is where I found the details of how to build and install boost.
Surprising news for me was that a large part of Boost is made up of header files — there is nothing to build for most of it.
The guide explains that
LD_LIBRARY_PATH should be updated.
Then the configure seemed to work.
All fine, and make install filled up the personal space, so I am having to resize and reboot.
Still ran out of space, so I scanned the file usage of /root and deleted a few larger files that were unnecessary.
This stage is not complicated, it just takes a long time.
can be used. Note that we are not yet going to do a
make install; first we will test that all is okay.
Once you have unpacked and make-ed the tarball you will find an
Examples directory which contains a number of folders. These are obviously going to contain examples of such-and-such pricing features, and we will now run through a couple to see check that they work. You can already see that there are a few make-related files in there.
The examples are all set up so that we can build them with make. However, we are going to start to investigate what exactly is happening during the make process, as it will give us an opportunity to get a bit more familiar with the tools that often get used for compiling/linking/distributing source code.
We start by moving into the
Swap directory. Note that you can easily get a command line within a directory you are browsing by using a right-click, as I show here:Once you have the terminal opened, run the program with ./SwapValuation.
That should display some pricings of a swap, based on three different discount curves.
We now see how you can tweak the code and re-build it with make.
Installing QuantLib and experimenting with your own code
The make install will copy the libraries into our usual location:
Let’s create a folder in our
/root space and copy across the whole of the Examples/Swap folder.
We will try to get it working with a simple g++ command. The failures that we hit along the way will serve as a great lesson in the basics of compilation, namely the two-steps of compilation and linking.
The answer that works:
g++ swapvaluation.cpp /root/lib/libQuantLib.a -o foo
Basically the static library just gets listed as part of the package that needs to be linked together. Note that the ordering is important: there is an implicit left-to-tight dependency.
Here are the failures
A few steps which all end in failure, but which are useful to see:
Debugging with gdb
An SO post here explains how gdb finds the source code.
Info here on how the source files are searched.
There is a front end to gdb if you fancy it: install ddd from here.