Installing QuantLib and QuantLib-Python on Windows
By: Pankaj Sharma
Tags: Python, Windows, Quantlib

I am a full-time trader and I use two machines — a linux server that hosts my algorithms and trading programs and a windows machine which is my ‘sandbox’. Installing/Reinstalling QuantLib on the windows machine has always been an activity that limited my experiments in the windows environment. However, recently, for reasons I will cover in another post, I decided to migrate my core trading library, written in R to Python.

Unfortunately, this required installation of QuantLib-Python and here i was, back at square one, struggling with technology. This is my log of installation steps, which will hopefully help in a future re-install and help any other striken folks out there who need help with QuantLib on windows.

The original steps are very well written at https://www.quantlib.org/install/vc10.shtml, but are a little generic at times. There is a more detailed version at Building QuantLib in VS2017 — From First Principles (benjaminwhiteside.com). Hopefully this writeup provides some extra information.

Step 1: Get all downloads unzip them in your folder

The files needed are

a) boost — take the latest version from https://sourceforge.net/projects/boost/files/boost-binaries/

b) QuantLib — take the latest version from https://github.com/lballabio/QuantLib/releases

c) QuantLib SWIG — take the version corresponding to the QuantLib version from https://github.com/lballabio/QuantLib-SWIG/releases

d) Download Visual Studio 2015 from https://visualstudio.microsoft.com/vs/older-downloads/. The community edition is free and works well.

I use a D: drive for storing my libraries. The folder is called tradingtools.

The first three downloads have been unzipped and await further action in D:

Three folders created

Step 2: I need intra-day accuracy in QuantLib as I use the package primarily for exchange traded options. To enable intra-day accuracy, amend the file in QuantLib-1.21/ql/userconfig.hpp. Uncomment following text

Old Text

New Text

Step 3:

We now need to build the QuantLib library. For this we will open Visual Studio 2015 and select the .sln file in QuantLib-1.21 folder.

Open Project File

Select Property Manager in View > Other Windows

We now need to update location of boost libraries to build QuantLib. This is done in 3 locations. In each of the three locations, we need to update 3 values viz

Include Directories — this needs to be updated to D:\tradingtools\boost_1_75_0 Library Directories — this needs to be updated to D:\tradingtools\boost_1_75_0\lib64-msvc-14.1

Updated location oof VC++ Directories in 1 & 2

Additional Include Directories — this needs to be updated to D:\tradingtools\boost_1_75_0

Updated Location of VC++ directories in Step 3

Location 1:

Select All projects

Location 1 — Update VC++ directories

Right click on the select area, and click on Properties in popup. Update libraries

Location 2

Now select QuantLib in Property Manager, expand the node, select all build types, right click and update properties. The values are the same as in the prior image

Location 2 — Update VC++ Directories

Location 3:

Location 3 : Update VC++ libraries

So we need to update the VC++ directories in three locations. This is missed in current online instructions.

Select Release x64 in the toolbar

Select Release x64

Go to solution explorer, select QuantLib, right click and click Build

After about 20 minutes on a 8th Gen i5, the build completes

The output will be in the build folder of QuantLib-1.21.

Step 4: We now need to build the python library using SWIG

If you are using a virtual environment, please make sure that the python evironment is activated and python.exe is in path.

Any of the following 2 installation options can be attempted.

Option 1:

The following commands are to be executed. You should replace folders names with the ones relevant for you. The source of these instruction is from QuantLib-Python Installation on Windows

cd D:\tradingtools\QuantLib-SWIG-1.21\Python

set QL_DIR=D:\tradingtools\QuantLib-1.21

set INCLUDE=D:\tradingtools\boost_1_75_0

python setup.py build

python setup.py test

python setup.py install

The build process takes about 10 minutes.

Option 2

Execute the following commands

cd D:\tradingtools\QuantLib-SWIG-1.21\Python

python setup.py bdist_wheel

cd dist

pip install QuantLib-1.21-cp37-cp37m-win_amd64.whl

You can go with either Option 1 or Option2 to build a Python package. Option 2 appears quicker, but both work.

At the end you should see the QuantLib library in your site-packages folder.

Hope this writeup helps anyone who is stuck on installing QuantLib-Python on windows. Please let me know if any hurdles in your install.