Skip to content
All library documents

QuantLib Python Bindings May Not Expose CompoundOption

Article Quant Q&A · Author: Ruan

Summary

The document addresses whether Python users can price compound options through QuantLib's CompoundOption class. The accepted answer reports that the class is not exposed in the Python module: attempting to access it through the QuantLib namespace raises an attribute error. This gives a concrete compatibility limitation for users who find the class in the library's annotated C++ source and assume the same interface exists in Python.

The evidence is a brief import-and-access check, rather than a pricing example or a survey of alternative methods. The document does not explain whether later versions or other bindings expose the class, nor does it provide a workaround, implementation, or valuation model. Its practical value is therefore narrow: it warns that the existence of a C++ class does not guarantee Python availability, and that users should verify the bindings in their installed environment before designing code around that interface.

Key ideas

  • A class visible in QuantLib's C++ source may not be available through its Python bindings.
  • The answer reports that accessing CompoundOption from the Python module raises an attribute error.
  • The document gives a binding availability check but does not show how to price compound options another way.

Tags

Full text
# Pricing Compound Options using QuantLib


# Pricing Compound Options using QuantLib












I am trying to price Compound Options using `QuantLib` on Python. I've looked around but am unable to find any sample code. I believe that the CompoundOption Class should be used?

https://rkapl123.github.io/QLAnnotatedSource/dc/dae/class_quant_lib_1_1_compound_option.html

If you know of any sample code or if you know how to use `QuantLib` to price compound options, could you please assist. Any help will be appreciated.

## Answer by David Duarte (score 1, accepted)

https://quant.stackexchange.com/a/52901

I don't think the `CompoundOption` class has been exported to the python module

If you try:

```
import QuantLib as ql
ql.CompoundOption()
```

You will get an error:

`AttributeError: module 'QuantLib' has no attribute 'CompoundOption'`

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.