Tiphaine Bonniot
HPC Innovation Engineer
Engineer at Qarnot, specialized in HPC, environmental footprint and operations research

QuantLib on Qarnot Cloud

April 27, 2022 - Finance, Documentation

Introduction

QuantLib is a free and open-source library for quantitative finance. QuantLib offers tools that are useful both for practical implementation and for advanced modeling, with features such as market conventions, yield curve models, solvers, PDEs, Monte Carlo (low-discrepancy included), exotic options, VAR, and so on.

Versions

Versions available on Qarnot's cloud platform.

Release yearVersion
20221.25
20211.24

If you are interested in another version, please send us an email at qlab@qarnot.com.

Prerequisites

Before launching the case, please ensure that the following prerequisites have been met.

Test cases

We use Python examples provided by the QuantLib-SWIG repository:

  • Pricing of an American option using different methods (analytical approximations, finite-difference and binomial trees),
  • Pricing of basket options (European and American) with two correlated underlyings and varying types of payoffs,
  • Pricing of exotic swap options (ITM, ATM and OTM) with different models (analytical and numerical),
  • Pricing of simple bonds (zero-coupon, fixed-rate, floating-rate) with appropriate term structures,
  • Computation of swaps cash-flows with fixed and floating rates,
  • Pricing of credit default swaps (CDS),
  • Pricing of an European option using different methods,
  • Valuation of interest rate derivatives using Gaussian Short Rate (GSR) and Markov models,
  • Computation of zero-coupon interest rates with the bootstrap method,
  • Implementation of an ISDA process to deal with default in CDS,
  • Computation and display of Heston Stochastic Local Volatility (SLV) model leverage function,
  • Pricing of interest-rate swaps,
  • Pricing of a swing option with two models (Black-Scholes or Kluge).

You can download scripts to run these examples here. You need to unzip this folder to be able to use it on Qarnot Cloud.

Launching a case

Copy the following code in a Python script and save it next to the quantlib-examples folder you unzipped before. Be sure you have copied your authentication token in the script (instead of <<<MY_SECRET_TOKEN>>>) to be able to launch the task on Qarnot. quantlib.py By default, the script quantlib.py launches the pricing of an American option example. To launch another example, change the use_case at line 3:

use_case = "american-option"

Replace american-option by the script name of your choice in the quantlib-examples folder. Make sure that all input files are in the same folder named quantlib-examples. Your working directory should look like this :

  • quantlib-examples/ : examples from QuantLib-SWIG described above
    • american-option.py
    • basket-option.py
    • bermudan-swaption.py
    • bonds.py
    • cashflows.py
    • cds.py
    • european-option.py
    • gaussian1d-models.py
    • global-bootstrap.py
    • isda-engine.py
    • slv.py
    • swap.py
    • swing.py
  • quantlib.py : python script to run the computations on Qarnot Cloud using QuantLib.

To launch this script, open a terminal in your working directory and execute python3 quantlib.py &. It will launch the execution of american-option.py on Qarnot and wait in the background until the execution is over to download the results.

Results

At any given time, you can monitor the status of your task on Tasq. You should now have an output folder in your working directory on your computer and a QuantLib-out bucket on Tasq containing all output files. For instance, here is the output file of the pricing of an American option example:


Pricing of an American Put Option
Evaluation date: April 15th, 2022
Expiration date: April 15th, 2023
Strike: 40.0
Spot: 36.0
Volatility ?: 0.20
Risk free rate: 6%
Pricing using different methods:
                  Method  Option value
0    Barone-Adesi-Whaley      4.459628
1    Bjerksund-Stensland      4.453064
2     finite differences      4.486113
3          Binomial (JR)      4.486552
4         Binomial (CRR)      4.486415
5         Binomial (EQP)      4.480097
6  Binomial (Trigeorgis)      4.486461
7        Binomial (Tian)      4.486413
8          Binomial (LR)      4.486076
9      Binomial (Joshi4)      4.486076

Wrapping up

That’s it! If you have any questions, please contact qlab@qarnot.com and we will help you with pleasure! You can visit the Qarnot Blog to read more articles on other computational use-cases.

Share on networks