Skip to content

Commit

Permalink
Merge pull request #101 from auto-differentiation/feature/update-quan…
Browse files Browse the repository at this point in the history
…tlib-risks-naming

Updated naming of QuantLib-Risks
  • Loading branch information
auto-differentiation-dev authored Mar 29, 2024
2 parents 8461e93 + 334742e commit 08c1fa3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions docs/quantlib/python.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
---
description: >-
quantlib-risks enables high performance risk evaluations with QuantLib Python bindings
QuantLib-Risks enables high performance risk evaluations with QuantLib Python bindings
using XAD automatic differentiation.
---

# Python QuantLib Integration: quantlib-risks
# Python QuantLib Integration: QuantLib-Risks

The Python package [quantlib-risks](https://pypi.org/project/quantlib-risks), a fork of the QuantLib Python bindings, is now available on PyPI. This version integrates automatic differentiation capabilities through its dependency on [XAD's Python bindings](../python.md). This integration significantly boosts the efficiency of performing high-performance risk assessments within QuantLib from Python.
The Python package [QuantLib-Risks](https://pypi.org/project/QuantLib-Risks), a fork of the QuantLib Python bindings, is now available on PyPI. This version integrates automatic differentiation capabilities through its dependency on [XAD's Python bindings](../python.md). This integration significantly boosts the efficiency of performing high-performance risk assessments within QuantLib from Python.

The key advantage brought by quantlib-risks is its ability to expediently ascertain how the pricing of derivatives is influenced by various input variables, notably market quotes.
The key advantage brought by QuantLib-Risks is its ability to expediently ascertain how the pricing of derivatives is influenced by various input variables, notably market quotes.

The user interface mimics the official [QuantLib Python package](https://pypi.org/project/QuantLib), with the addition of replacing it's `Real` type with `xad-autodiff.adj_1st.Real`, which can be tracked on an adjoint automatic differentiation tape and derivatives
can be calculated [xad-autodiff](../python.md).


## Performance

To gauge the performance impact of calculating sensitivities, we leverage the [multi-curve bootstrapping example](https://github.com/auto-differentiation/quantlib-risks/blob/v1.33/Python/examples/multicurve-bootstrapping.py). This setup incorporates a wide array of quotes to construct a term structure for swap pricing. It prices a forward-starting 5-year swap, set to commence 15 months into the future, with a calculation of 69 sensitivities covering all market quotes used in curve construction and select swap parameters like nominal, fixed rate, and spread.
To gauge the performance impact of calculating sensitivities, we leverage the [multi-curve bootstrapping example](https://github.com/auto-differentiation/QuantLib-Risks/blob/main/Python/examples/multicurve-bootstrapping.py). This setup incorporates a wide array of quotes to construct a term structure for swap pricing. It prices a forward-starting 5-year swap, set to commence 15 months into the future, with a calculation of 69 sensitivities covering all market quotes used in curve construction and select swap parameters like nominal, fixed rate, and spread.

Performance metrics are drawn from averaging execution times over 20 runs for stability. Initial benchmarks using the standard QuantLib package clock in at 198ms for pricing alone. Switching to `quantlib-risks` for simultaneous pricing and sensitivity analysis results in an execution time of 370ms, demonstrating that *all sensitivities can be obtained within approximately 1.87x of the original pricing time*.
Performance metrics are drawn from averaging execution times over 20 runs for stability. Initial benchmarks using the standard QuantLib package clock in at 198ms for pricing alone. Switching to `QuantLib-Risks` for simultaneous pricing and sensitivity analysis results in an execution time of 370ms, demonstrating that *all sensitivities can be obtained within approximately 1.87x of the original pricing time*.

Comparatively, a traditional bump-and-reval approach for sensitivities would necessitate 70 pricer code executions (one for valuation and one for each variable bump), translating to 70x the pure pricing time. *Thus, `quantlib-risks` achieves a 37.4x speed advantage over bump and reval*.
Comparatively, a traditional bump-and-reval approach for sensitivities would necessitate 70 pricer code executions (one for valuation and one for each variable bump), translating to 70x the pure pricing time. *Thus, `QuantLib-Risks` achieves a 37.4x speed advantage over bump and reval*.

Summary of performance benchmarks:

| Sensitivities | Valuation (QuantLib) | AAD (quantlib-risks) | Bumping (estimate) | AAD vs Valuation | Bumping vs AAD |
| Sensitivities | Valuation (QuantLib) | AAD (QuantLib-Risks) | Bumping (estimate) | AAD vs Valuation | Bumping vs AAD |
|---:|---:|---:|---:|---:|---:|
| 69 | 198ms | 370ms | 13,860ms | 1.87x | 37.4x |

Benchmark configuration details include:
- `QuantLib` and `quantlib-risks` version: 1.33
- `xad-autodiff` version: 1.5.0
- `QuantLib` version: 1.33
- `QuantLib-Risks` version: 1.33.2
- `xad-autodiff` version: 1.5.1
- Operating on Ubuntu 22.04 with GCC 11.4.0
- Hardware specs include 128GB RAM and an Intel(R) Xeon(R) W-2295 CPU @ 3.00GHz.


## Installation

```
pip install quantlib-risks
pip install QuantLib-Risks
```

## Usage Illustration

```python
import quantlib_risks as ql
import QuantLib_Risks as ql
from xad_autodiff.adj_1st import Tape

with Tape() as t:
Expand Down

0 comments on commit 08c1fa3

Please sign in to comment.