Skip to content
All library documents

Passing Volatility as a Quote When Pricing CDS Options in QuantLib

Article Quant Q&A · Author: user47760

Summary

The document addresses a Python QuantLib error encountered while pricing a European credit default swap option with a Black-style option engine. The reported constructor error indicates that the engine expects its volatility input as a quote handle rather than as a plain numeric value. The accepted answer recommends wrapping the volatility in a simple quote and then in a quote handle.

It also clarifies the pricing call pattern: attach the pricing engine to the CDS option object, then request that option’s net present value. The answer supplies a corrected usage example, but the source does not report a resulting price or broader validation. It is a narrow implementation note rather than a discussion of CDS option theory; it assumes the underlying CDS, hazard curve, recovery assumption, rates, and exercise setup are otherwise configured appropriately.

Key ideas

  • The Black CDS option engine expects volatility through a quote handle.
  • A numeric volatility input can be wrapped as a simple quote and then passed through a quote handle.
  • The pricing engine is attached directly to the CDS option object.
  • The option’s net present value is requested after the engine is set.

Tags

Full text
# CDS Option pricing in quantlib python


# CDS Option pricing in quantlib python












I am newbie in Python and I am trying to price a CDS Option in quantlib Python. I have the below code:

```
expiry= ql.Date(15,ql.May,2012)
cds_vol=0.5
exercise = ql.EuropeanExercise(expiry)
cds_option=ql.CdsOption(cds, exercise, True)
risk_free_rate = ql.YieldTermStructureHandle(ql.FlatForward(todaysDate, 0.01, ql.Actual365Fixed()))
probability = ql.DefaultProbabilityTermStructureHandle(hazard_curve)
cds = ql.CreditDefaultSwap(ql.Protection.Seller, nominal, s, schedule, ql.Following, ql.Actual365Fixed())
engine = ql.MidPointCdsEngine(probability, recovery_rate, risk_free_rate)
cds.setPricingEngine(engine)
cds_option_price=cds_option.setPricingEngine((ql.BlackCdsOptionEngine(probability, recovery_rate, risk_free_rate,cds_vol)))
cds_option_price.NPV()
```

This gives me an error:TypeError: in method 'new_BlackCdsOptionEngine', argument 4 of type 'Handle< Quote > const &'

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

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

First, the error is because you should input the cds_vol as a quote.

So instead of `cds_col` use `ql.QuoteHandle(ql.SimpleQuote(cds_vol))`

Apart from that the `.setPricingEngine()` method will affect the cds_option object directly, so you should use it as:

```
cds_option.setPricingEngine((ql.BlackCdsOptionEngine(probability, recovery_rate, risk_free_rate, ql.QuoteHandle(ql.SimpleQuote(cds_vol)))))
cds_option.NPV()
```

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.