lballabio / QuantLib

The QuantLib C++ library
http://quantlib.org
Other
5.24k stars 1.78k forks source link

zero spreaded rate curves / bond z-spread analytics ignore day counter #697

Open pcaspers opened 4 years ago

pcaspers commented 4 years ago

ZeroSpreadedTermStructure and InterpolatedPiecewiseZeroSpreadedTermStructureas well BondFunctions::zSpread() (which uses the former class internally) suggest that the spread can be given w.r.t. a day count convention specified by a DayCounter argument. However looking at the implementation this argument is ignored and the day count convention of the benchmark rate curve is alway used.

I am not sure if there is a valid use case for having different day counters for the benchmark curve and the spreads, but I think we should either add a clear documentation or (better) remove the argument or (a bit ugly) throw if the day counter in the argument is not consistent with the curve day counter or (at best?) fix the issue.

A fix does not seem to be trivial though. At the moment I'd think we need to add date based virtual discountImpl(const Date&) and zeroYieldImpl(const Date&) methods to the YieldTermStructure resp. ZeroYieldStructure interfaces and possibly throw (?) in the time based method implementations in the spreaded term structure classes mentioned above.

Any opinions how to move forward?

By the way I noticed that ZeroSpreadedTermStructure::forwardImpl(Time t) seems to return a forward rate with wrong conventions, but luckily the method is protected and does not seem to implement any interface :-) ... so that can probably just removed.

lballabio commented 4 years ago

You're right, both about the problem and about the fact that a fix is not trivial...

For the time being, I'd add overloads that don't take the day counter and deprecate the old versions.

lballabio commented 4 years ago

And yes, let's remove (or deprecate) ZeroSpreadedTermStructure::forwardImpl(Time t).

pcaspers commented 4 years ago

Yeah I guess whether it's worth providing the day counter depends on what the standard practice is to calculate the z-spread (which I am not sure about yet). If it's required we can still introduce a special solution for the z-spread calculation without solving the general case of the spreaded term structure.