从收益率曲线ycHandle
(YieldTermStructureHandle
对象)开始,我想使用ZeroSpreadedTermStructure
方法添加常量点差。我做了以下(使用QuantLib 1.8在Python中工作):
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)
不幸的是,两条曲线不重叠虽然我已将ycHandle
移动了0.我怀疑这可能与复合相关联,试图将所有曲线都更改为ql.Annual
或ql.Continuous
但不幸的是没有成功。