|
From: Peter C. <pca...@gm...> - 2023-12-25 18:17:57
|
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 |