0
$\begingroup$

I'm using QuantLib in Python to calculate the z-spread of a bond. I have a RelinkableYieldTermStructureHandle for the yield curve, but I'm getting a TypeError when I try to pass this handle to the ql.BondFunctions.zSpread() function.

Wrong number or type of arguments for overloaded function 'BondFunctions_zSpread'.
  Possible C/C++ prototypes are:
    BondFunctions::zSpread(Bond const &,Real,ext::shared_ptr< YieldTermStructure > const &,DayCounter const &,Compounding,Frequency,Date,Real,Size,Rate)
    BondFunctions::zSpread(Bond const &,Real,ext::shared_ptr< YieldTermStructure > const &,DayCounter const &,Compounding,Frequency,Date,Real,Size)
    BondFunctions::zSpread(Bond const &,Real,ext::shared_ptr< YieldTermStructure > const &,DayCounter const &,Compounding,Frequency,Date,Real)
    BondFunctions::zSpread(Bond const &,Real,ext::shared_ptr< YieldTermStructure > const &,DayCounter const &,Compounding,Frequency,Date)
    BondFunctions::zSpread(Bond const &,Real,ext::shared_ptr< YieldTermStructure > const &,DayCounter const &,Compounding,Frequency)

Here's the relevant part of my code:

z_spread = ql.BondFunctions.zSpread(self.bond,bond_dirty_price, self.yield_curve , ql.SimpleDayCounter(), ql.SimpleThenCompounded, ql.Annual) 

Where :

self.bond  ->  <class 'QuantLib.QuantLib.FixedRateBond'>
bond_dirty_price -> 98.943322
self.yield_curve -> <class 'QuantLib.QuantLib.RelinkableYieldTermStructureHandle'>

This gives me the above TypeError with the message "Wrong number or type of arguments for overloaded function BondFunctions_zSpread."

I expected that the RelinkableYieldTermStructureHandle could be used in place of a YieldTermStructureHandle or ext::shared_ptr< YieldTermStructure >, but it seems that this isn't the case. Can anyone explain what I'm doing wrong and how to correct this?

$\endgroup$

1 Answer 1

2
$\begingroup$

Use self.yield_curve.currentLink() to retrieve the curve from the handle and pass it to zSpread.

$\endgroup$
2
  • $\begingroup$ Wouldn't it be better if the handle did this automatically? $\endgroup$ Jun 9 at 16:46
  • 1
    $\begingroup$ I suppose we can add an overload. I'd be careful with implicit conversions. $\endgroup$ Jun 13 at 13:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.