Set up quantlib

From JQuantLib

Jump to: navigation, search

Contents

Set up Quantlib

This article describes how to set up and debug Quantlib in Eclipse Cdt under a Debian based Linux distribution (UBUNTU 8.10). MS Visual Studio users may have a look at http://longvega.com/QlInstallation.pdf (thanks to Dominik for pointing this out).

Get Eclipse CDT

You can get the latest CDT from here: CDT Download. Extract it to the folder where you usually install your IDE related applications.

Get GCC

To compile and link Quantlib, you need the GNU Compiler Collection (gcc). Install it using the following command line statement

sudo apt-get install gcc build-essential

Get Quantlib

You can get Quantlib form here: Quantlib download

Install Boost

Quantlib requires Boost. You can get it either using the package manager typing

apt-cache search libboost1

and then selecting the version you have available in your distribution, for instance:

apt-get install libboost1.35-dev libboost1.35-doc

Or you can get it from here: Boost download. Unpack it and navigate to the boost folder. Run the configuration script by typing

./configure

then install it

sudo make install

Set up the Quantlib project

  • Start Eclipse
  • Use File --> New --> C++ Project --> Static Library --> Empty Project --> Name the Project, eg. Quantlib --> Click Finish
  • Right Click the created project --> New --> Source folder and create a new source folder for the Quantlib source, eg. ql
  • Right Click the created project --> Import --> File System --> navigate to the downloaded Quantlib sources --> select the ql folder and click Finish
  • Right Click the project again --> Properties ... --> C/C++ General --> Paths and Symbols --> Includes --> C++ --> add the quantlib folder
  • That's it. Click the build button (the hammer symbol) and Quantlib should start compiling (this takes a while)

Set up the example projects

The following section describes how to set up the Equity Option example.

  • Create a new project as described above (eg. QuantlibExample), but this time select Executable --> Empty Project.
  • Create a new source folder, as described above (eg. src)
  • Import the EquityOption sources from the file system (or just copy the EquityOption.cpp file in the src folder)
  • Right click the QuantlibExample Project --> select Properties --> C/C++ General --> Paths and Symbols --> References select the Quantlib project you created before
  • Then select the Includes tab and add the the Quantlib headers again (ie. link to the project you created before)
  • Finally you have to specify path and name of the Quantlib library you built before. Note: you have to specify the name (without the lib prefix) as well as the location of the library (debug folder of the Quantlib project).
  • Now you should be able to compile and run the Example project. The output should look like this

http://www.jquantlib.org/index.php/Special:Upload

Debugging

Debugging should work as you're used to from Java, ie. just set a breakpoint and start the application in the debug mode.

Advanced Stuff

Using Quantlib as Shared Library

  • So far Quantlib was compiled and linked as static libary. Of course you can also use it as dynamic libary. Therefore you have to change the type of the Quantlib project to a 'Dynamic Library' target.
  • In addition to that you have to specify where the shared library can be found at runtime. Therefore you have to set the LD_LIBRARY_PATH to the debug folder of the shared library project.

Once this is done, the example project should build and run as before.

Writing multithreaded tests for Quantlib using libboost_thread

to be done.... explain how to add additional libraries, quantlib flags asf.