0
$\begingroup$

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 &'

$\endgroup$

1 Answer 1

5
$\begingroup$

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()
$\endgroup$
1
  • $\begingroup$ Thank you so much! It helped! :) $\endgroup$
    – user47760
    Commented Jun 24, 2020 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.