2

Starting from a yield curve ycHandle (a YieldTermStructureHandle object), I would like to add a constant spread using the ZeroSpreadedTermStructure method. I did the following (working in Python with QuantLib 1.8):

shift = 0
spread = ql.SimpleQuote(shift)
shiftedCurve = ql.ZeroSpreadedTermStructure(ycHandle,ql.QuoteHandle(spread))

def plotCurve(ycHandle, maxTen=25, lab=''):
    # function taking a yield curve handle and plotting it
    call = ql.TARGET()
    tv = [] # tenor vector
    rv = [] # rate vector
    for _ in range(12*1,12*maxTen):
        dt = call.advance(ql.Date.todaysDate(), 2, ql.Days) + 30*_
        tv.append(dc.yearFraction(today,dt))
        rv.append(ycHandle.zeroRate(dt,dc,ql.Compounded,ql.Annual).rate())
    plt.plot(tv,rv, label=lab)

plt.figure()
plotCurve(ycHandle)
plotCurve(shiftedCurve)

Unfortunately the two curves do not overlap although I have shifted ycHandle by 0. I suspect this might be linked to the compounding, have tried to change all to ql.Annual or ql.Continuous but unfortunately was unsuccessful.

  • 1
    You're passing `zcHandle` to build the shifted curve but plotting `ycHandle`. Just a typo when copying the code, or is there something else going on? – Luigi Ballabio Aug 22 '16 at 09:11
  • Just a typo, thanks for pointing it out, I edited the code. Could you reproduce the issue? – Lorenzo di Bonaventura Aug 22 '16 at 10:36
  • No, I couldn't. May you post a self-contained snippet? The one above relies on a few missing variables (`dc`, for instance, but it's not the only one). – Luigi Ballabio Aug 22 '16 at 12:26
  • By writing a self-contained code snippet the problem went away. The issue seemed to come from the YieldCurve objects that were produced by a NelsonSiegel fitting procedure. Thanks! – Lorenzo di Bonaventura Sep 27 '16 at 21:38

0 Answers0