PyQL : a new set of Python wrappers for QuantLib

March 23, 2012

Hi folks,

We are happy to announce the release of PyQL [1], a new set of Python wrappers for QuantLib.

The project is available here :

* URL:
* License: BSD license.
* Authors: Didrik Pinte, Enthought and Patrick Henaff, IAE Paris.

Why another set of Python wrappers for QuantLib?

The SWIG wrappers provide a very good coverage of the library but have
a number of pain points:

  • ¬† few Pythonic optimisation in the syntax: the code a user must writeon the Python side looks like the C++ version
  • no docstring or function signature available on the Python side
  • complex debugging and complex customization of the wrappers
  • monolithic build process
  • complete loss of the C++ code organisation with a flat namespace in Python
  • SWIG typemaps development is not that fun

For those reasons and to have the ability to expose some of the
QuantLib internals that could be very useful on the Python side, we
chosed another road. PyQL is build on top of Cython and creates a thin
Pythonic layer on top of QuantLib. It allows a tight control on the
wrapping and provides higher level Python integration.


  1. Integration with standard datatypes (like datetime objects) and numpy arrays
  2. Simplifed API on the Python side (e.g. usage of Handles completely hidden from the user)
  3. Support full docstring and expose detailed function signatures to Python
  4. Code organised in subpackages to provide a decent namespace, very close to the C++ code organisation
  5. Easy extendibility thanks to Cython and shorter build time when adding new functionnalities
  6. Sphinx documentation

It supports QuantLib >= 1.1 and currently builds very nicely on MacOSX
and Linux. The Windows builds will be there soon. Regarding the build
process, make sure you read the build instruction!
(Cython 0.15 needs a simple patch available in the repo)

The library comes with a decent test suite and many examples: from the
very basic option valuation to more complex heston model calibration
within an IPython notebook.

For more details, take a look at the code, contact the authors, or
discuss on the list!

We are looking forward questions, comments, contributions.

[1] The name is still subject to modification as PyQL is already used
by other projects unrelated to QuantLib. Suggestions are welcome!

Building Quantlib Python bindings (32bit) on MacOSX

December 30, 2010

I needed to use Quantlib with Traits on MacOSX. As the Traits backends are not available in 64bit on MacOSX with EPD, I had to build a 32bit version of Quantlib and the related swig bindings to make it work. By default, Quantlib will be built in 64bit mode and you will get the following warning when building the Python swig bindings using a 32bit Python installation (python build):

ld: warning: in /opt/local/lib/libQuantLib.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

and the following error when trying to run the test (python test)

ImportError: dlopen(build/lib.macosx-10.5-i386-2.6/QuantLib/, 2): Symbol not found: __ZN8QuantLib12SmileSection6updateEv
Referenced from: /Users/dpinte/Downloads/QuantLib-SWIG-1.0/Python/build/lib.macosx-10.5-i386-2.6/QuantLib/
Expected in: flat namespace
in /Users/dpinte/Downloads/QuantLib-SWIG-1.0/Python/build/lib.macosx-10.5-i386-2.6/QuantLib/

1. Build Quantlib after making sure you do have Boost installed (you can use MacPorts for that):

export CFLAGS=-m32
export CPPFLAGS=-m32
export CXXFLAGS=-m32
./configure --enable-static --with-boost-include=/opt/local/include/ \
--with-boost-lib=/opt/local/lib/ --prefix=/opt/local/
make install

2. Build the swig bindings:

python build
python test
python install

And it should work fine :

Ran 25 tests in 0.889s


Surface plots using a 4th parameter for colormap in Mayavi

March 30, 2010

Playing with Mayavi, I wanted to find an easy way to use the colormap in an call to display of fourth dimension. It is a very nice way to explore datasets. The image here below shows an option valuation tool that overlays the Black & Scholes call delta value on top of the surface made using the strikes, time to expiry and Black & Scholes call value.

How can you do it ?
Read the rest of this entry »

London Financial Python User Group meets on February 3

January 20, 2010

The 3rd meeting of the LFPUG is to be held on February 3 at 7PM.

Topics :

  • Improving NumPy performance with the Intel MKL – Didrik Pinte
  • Python to Excel bridges :
    • “PyXLL, a user friendly Python-Excel bridge” – Tony Roberts
    • Discussion on connecting Python and Excel (xlrd/xlwt, pyinex, win32com, pyxll, …)
  • Speeding up Python code using Cython – Didrik Pinte

Location: The event will be hosted by KBC Financial Products that kindly proposed a meeting room for us. For security concerns, please do RSVP at to be confirmed on the attendee list. Address of the day : 111 Old Broad Street, EC2N 1FP (just opposite Tower 42)

The details are available  on the wiki page.