itsfosslinux

How to Install QuantLib on Linux

In this article, we will see how to install QuantLib on Linux. QuantLib is a free, open-source software library for quantitative finance. It is written in C++ and is designed to be a comprehensive software framework for quantitative finance, providing tools for various aspects of financial mathematics. These include pricing engines for various financial instruments, mathematics tools, numerical algorithms, and calendar/time day-count conventions.

QuantLib is widely used in both academic and commercial settings for modeling, trading, and risk management in real-life financial markets. Its versatility and broad applicability make it a valuable tool for quantitative analysts, developers working in finance, and researchers in financial engineering. It is also very easy to install and use. Here we will see the steps to install QuantLib on Linux.

 

Key Features

  • Wide Range of Financial Instruments: It supports pricing and valuation of various financial derivatives, including options, bonds, and more.
  • Date and Time Management: Tools for handling dates, calendars, and day-count conventions, crucial in finance.
  • Mathematical and Numerical Tools: Provides algorithms for numerical integration, solvers, and optimization.
  • Risk Management Tools: Includes modules for calculating Value at Risk, cash flows, and yield curves.
  • Extensibility: Designed to be extendable to accommodate new financial instruments and models.
  • Cross-Platform Compatibility: As a C++ library, it can be used on multiple operating systems.

 

How to Install QuantLib on Linux

How to Install QuantLib on Linux

Also Read: How to Install libboost-all-dev package on Ubuntu or Debian

Step 1: Prerequisites

a) You should have a running Linux Server.

b) You should have sudo or root access to run privileged commands.

c) You should have tar, wget and make utility available in your Server.

d) You should have libboost-all-dev(on Ubuntu/Debian) or boost-devel(on RHEL/Fedora) package installed in your System.

 

Step 2: Update Your Server

It is often required to install the latest patches in the system to deal with security vulnerabilities. Regular updates all protect the system from new threats. It contains latest bugfixes which are very much required for the stability of the system. If you are using Ubuntu or Debian based systems, then you can update your server by using sudo apt update && sudo apt upgrade command as shown below.

sudo apt update && sudo apt upgrade

If you are using RHEL/CentOS based systems then you can use either sudo yum update && sudo yum upgrade command or sudo dnf update && sudo dnf upgrade command as shown below.

sudo yum update && sudo yum upgrade
sudo dnf update && sudo dnf upgrade

 

 

Step 3: Download QuantLib

To install QuantLib, you have to first download the latest version of QuantLib from GitHub website. You can get the GitHub link from QuantLib official website. To download, you can either wget or curl utility. Here we are using wget utility to download the latest version of QuantLib as shown below. This will download the source code tarball in current working directory.

itsfosslinux@ubuntu:~$ wget https://github.com/lballabio/QuantLib/releases/download/v1.32/QuantLib-1.32.tar.gz
--2023-12-23 00:56:05-- https://github.com/lballabio/QuantLib/releases/download/v1.32/QuantLib-1.32.tar.gz
Resolving github.com (github.com)... 20.207.73.82
Connecting to github.com (github.com)|20.207.73.82|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/48185587/e08dac43-4d9d-42b7-99b9-69397f8b5cf4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20231222%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20231222T192605Z&X-Amz-Expires=300&X-Amz-Signature=3069ae43f04e13007c9f1bdc39ae6fe3e2d0ccf04721a82f997f6927f9f74813&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=48185587&response-content-disposition=attachment%3B%20filename%3DQuantLib-1.32.tar.gz&response-content-type=application%2Foctet-stream [following]
--2023-12-23 00:56:05-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/48185587/e08dac43-4d9d-42b7-99b9-69397f8b5cf4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20231222%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20231222T192605Z&X-Amz-Expires=300&X-Amz-Signature=3069ae43f04e13007c9f1bdc39ae6fe3e2d0ccf04721a82f997f6927f9f74813&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=48185587&response-content-disposition=attachment%3B%20filename%3DQuantLib-1.32.tar.gz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9399084 (9.0M) [application/octet-stream]
Saving to: ‘QuantLib-1.32.tar.gz’

QuantLib-1.32.tar.gz 100%[============================================================================>] 8.96M 16.1MB/s in 0.6s

2023-12-23 00:56:07 (16.1 MB/s) - ‘QuantLib-1.32.tar.gz’ saved [9399084/9399084]

 

 

Step 4: Extract Files

To extract files from tarball, use tar xzf QuantLib-1.32.tar.gz command as shown below. This will create a directory called QuantLib-1.32 in current working location and extract all files in it.

itsfosslinux@ubuntu:~$ tar xzf QuantLib-1.32.tar.gz

 

Step 5: Configure Source Code

Switch to directory using cd QuantLib-1.32 command and then configure the source code by running ./configure script as shown below. This step will check if your system has all the necessary software and tools to build the package. It also customizes the software package according to your local systems configuration to get the optimal performance.

itsfosslinux@ubuntu:~$ cd QuantLib-1.32
itsfosslinux@ubuntu:~/QuantLib-1.32$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether UID '1001' is supported by ustar format... yes
checking whether GID '1001' is supported by ustar format... yes
checking how to create a ustar tar archive... gnutar
checking for gawk... (cached) mawk
checking for gcc... gcc
checking whether the C compiler works...
.........................................

 

Step 6: Build Source Code

After completing the configuration, you can build the source code by running make command as shown below. It will read set of directives in Makefile to determine how to compile and link the program.

NOTE:

Please note that this step might take few mins to few hours to complete, depending on your system configuration. It has lot of source code files to build.
itsfosslinux@ubuntu:~/QuantLib-1.32$ make
Making all in ql
make[1]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql'
make all-recursive
make[2]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql'
Making all in cashflows
make[3]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/cashflows'
depbase=`echo averagebmacoupon.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/bash ../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I../.. -I../.. -g -O2 -MT averagebmacoupon.lo -MD -MP -MF $depbase.Tpo -c -o averagebmacoupon.lo averagebmacoupon.cpp &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: g++ -DHAVE_CONFIG_H -I../.. -I../.. -g -O2 -MT averagebmacoupon.lo -MD -MP -MF .deps/averagebmacoupon.Tpo -c averagebmacoupon.cpp -fPIC -DPIC -o .libs/averagebmacoupon.o
.........................................

 

Step 7: Install QuantLib

After successful build, you can install all the generated binaries by using sudo make install command as shown below. This step should be quick and does not take much time to complete. So cheers !!

itsfosslinux@ubuntu:~/QuantLib-1.32$ sudo make install
[sudo] password for itsfosslinux:
Making install in ql
make[1]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql'
Making install in cashflows
make[2]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/cashflows'
make[3]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/cashflows'
make[3]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/usr/local/include/ql/cashflows'
/usr/bin/install -c -m 644 all.hpp averagebmacoupon.hpp capflooredcoupon.hpp capflooredinflationcoupon.hpp cashflows.hpp cashflowvectors.hpp cmscoupon.hpp conundrumpricer.hpp coupon.hpp couponpricer.hpp cpicoupon.hpp cpicouponpricer.hpp digitalcmscoupon.hpp digitalcoupon.hpp digitaliborcoupon.hpp dividend.hpp duration.hpp equitycashflow.hpp fixedratecoupon.hpp floatingratecoupon.hpp iborcoupon.hpp indexedcashflow.hpp inflationcoupon.hpp inflationcouponpricer.hpp lineartsrpricer.hpp overnightindexedcoupon.hpp rangeaccrual.hpp rateaveraging.hpp replication.hpp simplecashflow.hpp subperiodcoupon.hpp timebasket.hpp yoyinflationcoupon.hpp zeroinflationcashflow.hpp '/usr/local/include/ql/cashflows'
make[3]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/cashflows'
make[2]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/cashflows'
Making install in currencies
make[2]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/currencies'
make[3]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/currencies'
make[3]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/usr/local/include/ql/currencies'
/usr/bin/install -c -m 644 all.hpp africa.hpp america.hpp asia.hpp crypto.hpp europe.hpp exchangeratemanager.hpp oceania.hpp '/usr/local/include/ql/currencies'
make[3]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/currencies'
make[2]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/currencies'
Making install in experimental
make[2]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/experimental'
Making install in amortizingbonds
make[3]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/experimental/amortizingbonds'
make[4]: Entering directory '/home/itsfosslinux/QuantLib-1.32/ql/experimental/amortizingbonds'
make[4]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/usr/local/include/ql/experimental/amortizingbonds'
/usr/bin/install -c -m 644 all.hpp amortizingcmsratebond.hpp amortizingfixedratebond.hpp amortizingfloatingratebond.hpp '/usr/local/include/ql/experimental/amortizingbonds'
make[4]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/experimental/amortizingbonds'
make[3]: Leaving directory '/home/itsfosslinux/QuantLib-1.32/ql/experimental/amortizingbonds'
Making install in asian
....................................................................

Additionally, you might also need to run sudo ldconfig command to notify the dynamic linker that a new shared library is available.

itsfosslinux@ubuntu:~/QuantLib-1.32$ sudo ldconfig
[sudo] password for itsfosslinux:

Leave a comment