Chapter 3, part 4 of n: adding z-spread to an interest-rate curve
Hello again.
This post is the fourth in an ongoing series covering chapter 3 of my book and starting here. It’s a short one, to make up for the monster post of last week.
As I already mentioned, IKB, Quaternion and d-fine are organizing a two-days QuantLib workshop in Düsseldorf on November 13th and 14th. The agenda is here; if you’re interested, send an email to the contacts listed in there. Registration is free; there are just 35 places, though.
Follow me on Twitter if you want to be notified of new posts, or add me to your circles, or subscribe via RSS: the buttonss for that are in the footer. Also, make sure to check my Training page.
Term structures
Example: adding z-spread to an interest-rate curve
This example (a lot simpler than the previous one) shows how to build a term-structure based on another one. We’ll take an existing risk-free curve and modify it to include credit risk. The risk is expressed as a z-spread, i.e., a constant spread to be added to the zero-yield rates. For the pattern-savvy, this is an application of the Decorator pattern; we’ll wrap an existing object, adding some behavior and delegating the rest to the original instance.
Listing 3.12: Implementation of the ZeroSpreadedTermStructure
class.
The implementation of the ZeroSpreadedTermStructure
is shown in
listing 3.12. As previously mentioned, it is based on zero-yield
rates; therefore, it inherits from the ZeroYieldStructure
adapter
described here and will have to
implement the required zeroYieldImpl
method. Not surprisingly, its
constructor takes as arguments the risk-free curve to be modified and
the z-spread to be applied; to allow switching data sources, both are
passed as handles. The arguments are stored in the corresponding data
members, and the curve registers with both of them as an observer. The
update
method inherited from the base class will take care of
forwarding any received notifications.
Note that none of the base-class constructors was called
explicitly. As you might remember from this post, this means that
instances of our curve store no data that can be used by the
TermStructure
machinery; therefore, the class must provide its own
implementation of the methods related to reference-date
calculation. In true Decorator fashion, this is done by delegating
behavior to the wrapped object; each of the referenceDate
,
dayCounter
, calendar
, settlementDays
, and maxDate
methods
forwards to the corresponding method in the risk-free curve.
Finally, we can implement our own specific behavior—namely,
adding the z-spread. This is done in the zeroYieldImpl
method; we
ask the risk-free curve for the zero-yield rate at the required time
(continuously compounded, since that’s what our method must return),
add the value of the z-spread, and return the result as the new
zero-yield rate. The machinery of the ZeroYieldStructure
adapter
will take care of the rest, giving us the desired risky curve.