|
From: Quant <qua...@gm...> - 2023-12-26 20:46:25
|
Hi Peter,
Thanks for the feedback. The workaround you suggested of avoiding the
extrapolation of the curve worked and also removing the "Forward Rate" in
the node_data as the forward rate is not exported in SWIG as you indicated.
I think it will be helpful if the forward rates can be exported in SWIG as
well on the next updates.
I did 2 plots for the PiecewiseLogCubicDiscount and the
PiecewiseConvexMonotoneZero for both zero and forward rates curves (tried
to attach the plots but the email became too large i.e., more than 100KB to
be posted). The PiecewiseConvexMonotoneZero is not smooth (quite weird
curve) and I was wondering if the one implemented in QuantLib is the
"Monotone convex (unameliorated)" described in the Hagan and West Paper as
the best interpolation method? Is it perhaps possible to add the smoothed
version of the interpolation on the upcoming updates? Please note that the
plots below are related to the bootstrapping of government bonds.
On a separate note, I tried using PiecewiseConvexMonotoneZero on deposits +
FRA + Swap Rates bootstrapping and I got the following error;
Traceback (most recent call last):
File "/Users/Library/CloudStorage/OneDrive-Personal/QuantLib
Software/Valuations/Valuation of ZAR IRS/ZAR IRS Valuation 2.py", line 115,
in <module>
zero_rate = curve.zeroRate(date, day_count, ql.Annual).rate()
File "/usr/local/lib/python3.9/site-packages/QuantLib/QuantLib.py", line
8610, in zeroRate
return _QuantLib.YieldTermStructure_zeroRate(self, *args)
RuntimeError: 1st iteration: failed at 13th alive instrument, pillar May
28th, 2020, maturity May 28th, 2020, reference date February 28th, 2019:
root not bracketed: f[-1,1] -> [-1.339261e-01,-1.181714e+01]
What could be the cause of the error on this one?
Thanks and regards,
On Mon, Dec 25, 2023 at 8:17 PM Peter Caspers <pca...@gm...>
wrote:
> Hi, the error is probably generated here
>
>
> https://github.com/lballabio/QuantLib/blob/master/ql/termstructures/yield/zerocurve.hpp#L168
>
> so a workaround would be to avoid extrapolating the curve.
>
> In fact I think the convex monotone interpolation was designed to be
> applied to forward rates rather than zero yields, see
>
> https://downloads.dxfeed.com/specifications/dxLibOptions/HaganWest.pdf
>
> in section 6. But it seems only zero yield is exported as an
> interpolation variable in SWIG at the moment
>
>
> https://github.com/lballabio/QuantLib-SWIG/blob/master/SWIG/piecewiseyieldcurve.i#L168
>
> We should add forward rate here I guess?
>
> Best
> Peter
>
> On Sun, 24 Dec 2023 at 15:18, Quant <qua...@gm...> wrote:
> >
> > Hi QuantLib Users,
> >
> > I am trying to implement the Convex Monotone interpolation as shown
> below;
> >
> > curve = ql.PiecewiseConvexMonotoneZero(today, helpers, day_count)
> > # curve = ql.PiecewiseLogMixedLinearCubicDiscount(today, helpers,
> day_count)
> > # curve = ql.PiecewiseSplineCubicDiscount(today, helpers, day_count)
> >
> > # Enable Extrapolation:
> > # This line enables extrapolation for the yield curve.
> > # Extrapolation allows the curve to provide interest rates or rates
> beyond the observed data points,
> > # which can be useful for pricing or risk management purposes.
> > curve.enableExtrapolation()
> >
> > # Print the Zero Rates, Forward Rates and Discount Factors at node dates
> > # print(pd.DataFrame(curve.nodes()))
> > node_data = {'Date': [],
> > 'Zero Rates': [],
> > 'Forward Rates': [],
> > 'Discount Factors': []}
> >
> > for dt in curve.dates():
> > node_data['Date'].append(dt)
> > node_data['Zero Rates'].append(curve.zeroRate(dt, day_count,
> ql.Compounded, ql.Annual).rate())
> > node_data['Forward Rates'].append(curve.forwardRate(dt, dt +
> ql.Period(1, ql.Years), day_count, ql.Annual).rate())
> > node_data['Discount Factors'].append(curve.discount(dt))
> >
> > node_dataframe = pd.DataFrame(node_data)
> >
> > And I am getting the following error;
> >
> > Traceback (most recent call last):
> > File "/Users/Library/CloudStorage/OneDrive-Personal/QuantLib
> Software/Valuations/IRS using Bond Bootstrapping/IRS using Bond
> Bootstrapping 3.py", line 87, in <module>
> > node_data['Forward Rates'].append(curve.forwardRate(dt, dt +
> ql.Period(1, ql.Years), day_count, ql.Annual).rate())
> > File "/usr/local/lib/python3.9/site-packages/QuantLib/QuantLib.py",
> line 8617, in forwardRate
> > return _QuantLib.YieldTermStructure_forwardRate(self, *args)
> > RuntimeError: Convex-monotone spline derivative not implemented
> >
> > Is this a known issue with PiecewiseConvexMonotoneZero or it's an error
> that can be fixed in my code? If it can be fixed where do I need to fix?
> >
> > Thanks & regards,
> > _______________________________________________
> > QuantLib-users mailing list
> > Qua...@li...
> > https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|