Integration of Quantlib with Qgraph

QuantLib Introduction

QuantLib is aimed at providing a comprehensive software framework for quantitative finance. QuantLib is a free/open-source library for modeling,trading,and risk management in real-life. The following steps need to be followed to integrate quantlib with QSpace server on Ubuntu platform.

Downloading and Installing Quantlib

Boost Installation

If you don’t require a particular Boost version, the path of least resistance is to install the one packaged for your distribution; for instance, on Ubuntu you would execute:

sudo apt-get install libboost-all-dev

QuantLib Installation

Installation from package repositories

If you don’t need to modify the library, you might want to skip the compilation and install a precompiled binary version; unofficial RPM and DEB packages should be available for your distribution through the usual channels. Note that the default version on Debian and Ubuntu distributions might be lagging behind; to get a recent one, use the “unstable” (a.k.a. “Sid”) distribution on Debian or Dirk Eddelbuettel’s PPA on Ubuntu. If you want to modify the library, instead, you’ll have to compile it yourself as described in the next section.

Installation from a released version

You can download released QuantLib versions from Bintray at QuantLib-1.4.1.tar.gz.

  • Once you have the tarball, extract it by executing:
    tar xzf QuantLib-1.4.1.tar.gz
  • (1.4.1 is the most recent version at the time of this writing; you might have downloaded another one.) This creates a folder QuantLib-1.4.1; enter it and configure QuantLib by executing:
    cd QuantLib-1.4.1 
  • The above step is customizable, run below command to obtain a list of the configuration options
    ./configure --help
    In particular, the –prefix option can be used to install QuantLib in a location other than the default (/usr/local). This is also the step where you might have to tell configure about the location of your Boost installation, if that’s not a standard one. If, for instance, you installed the Boost headers in /home/foo/include and the libraries in /home/foo/lib, execute:
    ./configure --with-boost-include=/home/foo/include --with-boost-lib=/home/foo/lib
  • To setup the build correctly.
    sudo make install
    Finally, builds the library and installs it (if you specified a location with –prefix that doesn’t need admin permissions, you won’t need to use sudo before make install).
  • Depending on your system, you might also need to run below command
    sudo ldconfig
    to notify the dynamic linker that a new shared library is available. (The above works with the default prefix, /usr/local, on most system; if you chose another one, or if your programs still can’t find, you’ll need to add the location of the library to /etc/ before running ldconfig. For a default installation, that would be /usr/local/lib.)
  • Once you’re done, you can try to compile and run an example to check your installation. If you installed everything in the default location, you can simply execute:
    cd Examples/BermudanSwaption 
    g++ BermudanSwaption.cpp -o BermudanSwaption -l QuantLib ./BermudanSwaption
    Otherwise, you’ll have to specify the location of your Boost and QuantLib installations with corresponding -I and -L flags; for instance, the middle step above would be:
    g++ BermudanSwaption.cpp -I/home/foo/include -o;
    BermudanSwaption -L/home/foo/lib -l QuantLib 
    #if you ran ./configure with prefix /home/foo

Installation from a git repository

If you want to compile from a checkout of a git repository (such as the official one at quantlib, or a fork of it that you might have created) you’ll need an additional step at the beginning of the process. Before running the ./configure script, you’ll have to create it by executing ./ To do this, you’ll need automake, autoconf and libtool. Again, they’re packaged for most Linux distributions; on Ubuntu, you would get them by running sudo apt-get install automake autoconf libtool After the  execution of ./, the installation proceeds as in the previous section.

Integration Quantlib with QGraph server

Quantlib is used to compute the price of
  1. Equity option
  2. FX option and
  3. Swap in QSpace
To enable using Quantlib in QSpace it is controlled by environment variable “QS_ENABLE_QUANTLIB” in project’s /script/ file If QS_ENABLE_QUANTLIB environment variable is defined then server uses Quantlib mathematical model for compute the price of Equity Option, FX Option and Swap. Otherwise the server uses its own mathematical model to compute price of Equity Option, FX Option and Swap. Quantlib supports FX Option/ Equity Option models :
  • Black-Scholes
  • Heston semi-analytic
  • Bates semi-analytic
  • Barone-Adesi/Whaley
  • Bjerksund/Stensland
  • Integral
  • Finite differences
  • Binomial Jarrow-Rudd
  • Binomial Cox-Ross-Rubinstein
  • Additive equiprobabilities
  • Binomial Trigeorgis
  • Binomial Tian
  • Binomial Leisen-Reimer
  • Binomial Joshi
  • MC (crude)
  • QMC (Sobol)
  • MC (Longstaff Schwartz) Sample code using Jarrow-Rudd binomial method
#include <ql/qldefines.hpp>
# include <ql/auto_link.hpp>
#include <ql/instruments/vanillaoption.hpp>
#include <ql/pricingengines/vanilla/binomialengine.hpp>
#include <ql/pricingengines/vanilla/analyticeuropeanengine.hpp>
#include <ql/pricingengines/vanilla/analytichestonengine.hpp>
#include <ql/pricingengines/vanilla/baroneadesiwhaleyengine.hpp>
#include <ql/pricingengines/vanilla/bjerksundstenslandengine.hpp>
#include <ql/pricingengines/vanilla/batesengine.hpp>
#include <ql/pricingengines/vanilla/integralengine.hpp>
#include <ql/pricingengines/vanilla/fdeuropeanengine.hpp>
#include <ql/pricingengines/vanilla/fdbermudanengine.hpp>
#include <ql/pricingengines/vanilla/fdamericanengine.hpp>
#include <ql/pricingengines/vanilla/mceuropeanengine.hpp>
#include <ql/pricingengines/vanilla/mcamericanengine.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/utilities/dataformatters.hpp>

#include <boost/timer.hpp>
#include <iostream>
#include <iomanip>

using namespace QuantLib;


// Binomial method: Jarrow-Rudd
	method = "Binomial Jarrow-Rudd";
	new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
	new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
	new BinomialVanillaEngine<JarrowRudd>(bsmProcess,timeSteps)));
	std::cout << std::setw(widths[0]) << std::left << method
	<< std::fixed
	<< std::setw(widths[1]) << std::left << europeanOption.NPV()
	<< std::setw(widths[2]) << std::left << bermudanOption.NPV()
	<< std::setw(widths[3]) << std::left << americanOption.NPV()
	<< std::endl;

Related Posts

Leave a Comment

Comment moderation is enabled. Your comment may take some time to appear.