Update: The GitHub code.
The complexity of over-the-counter structured products warrants numerical methods to price derivatives. I have priced exotics using Excel VBA, Numerix and Bloomberg’s DLIB (BLAN). While these tools addressed the computational complexities of different degrees that many large derivatives desks can handle, such sophisticated tools were not available to many.
The advent of open-source library QuantLib is now changing that equation. And, as it extends to Python, we now have a very powerful computational tool for pricing complex derivatives.
Structure of QuantLib
Price of any derivative, be it a plain-vanilla option or a structured product, depends on the following inputs and QuantLib has effectively designed classes for such inputs as depicted in the following chart.
Barrier Option Pricing
Among other variants, let me choose to price an up-and-out barrier option and calculate numerical Greeks. A Barrier Option is a derivative whose payoff depends on whether the price of the underlying security crosses a pre specified level (called the ‘barrier’) before the expiration.
For further details on barriers, refer Paul Wilmott on Quantitative Finance Chapter 23 — Barrier Options and Chapter 77 — Finite Difference Methods for One-factor Models.
Numerical Calculation of Greeks
The QuantLib framework of instrument class makes it easier to set the relevant market data to price the options and approximate the Greeks using numerical differentiation. As the market data are stored in Quote instances, we don’t need to explicitly recalculate the option again. All, we need to do is to simply retrieve the updated value.
We can approximate the derivatives by calculating the option value for two slightly different values of the underlying and by taking the slope between the resulting points.
Delta and Gamma can then be approximated using the following formula:
where P(u) is the price of the option for a given value of the underlying u. Similarly , we use the one-sided formula as below for calculation of Rho & Vega.
Python Script
To access the Jupyter Notebook of this code, refer GitHub.
Price Delta Gamma Theta Vega Rho
------------- -------- ---------- -------- ------- ------
22.0568 0.517543 0.00316869 -5.24684 41.7486 7248.6
QuantLib stands out in ease of pricing complex exotic structures in an effective manner and has now became a part of many global institutional derivatives desk.
If you find value in what I am doing, buy me a coffee https://www.buymeacoffee.com/kannansi