Setting a Fixed Reference Date for QuantLib Curve Bootstrapping
Summary
This exchange explains how to bootstrap an EONIA curve in QuantLib-Python with a reference date that stays fixed when the evaluation date changes. The proposed solution is to use the `PiecewiseLogCubicDiscount` constructor that accepts an explicit reference date, rate helpers, and day-count convention. The asker’s failed attempt used an overload that combines a settlement-day count with a calendar, which does not accept a date in that position.
The answer also points to SWIG’s available constructor signatures as a way to diagnose the `NotImplementedError`. The example confirms that the curve reports the supplied date as its reference date. A second answer suggests using the QuantLib `Date` name from the imported module, but the accepted answer focuses on the constructor overload. This addresses how to set the curve’s date; it does not discuss calibration quality or compare the resulting curve against market data.
Key ideas
- Use the piecewise curve constructor overload that takes a reference date, rate helpers, and day counter.
- An explicit reference date keeps the curve anchored independently of later evaluation-date changes.
- A constructor type error can indicate that the requested overload is not exposed or that the argument sequence does not match an available signature.
- Inspecting the Python binding signatures can help identify valid constructor arguments.
Tags
Full text
# QuantLib-Python: How to set fixed reference dates when bootstrapping the term structure?
# QuantLib-Python: How to set fixed reference dates when bootstrapping the term structure?
I am borrowing from an example in the "Quantlib Python Cookbook" section 7, to ask my question. To make the point as clear as possible I simplify the code a bit. The aim is to strip the EONIA curve from OIS quotes.
The initialization is not to question:
```
%%capture
%pylab inline --no-import-all
import math
import numpy
import utils
import matplotlib.pyplot as plt
from QuantLib import *
today = Date(11, December, 2012)
Settings.instance().evaluationDate = today
```
A list of `OISRateHelper`s is set up from which the term structure shall be stripped. The "2" tells the helper object that the quotes correspond to contracts that start +2 days from now.
```
helpers = [ OISRateHelper(2, Period(*tenor),
QuoteHandle(SimpleQuote(rate/100)), eonia)
for rate, tenor in [(0.002, (15,Months)), (0.008, (18,Months)),
(0.021, (21,Months)), (0.036, (2,Years)),
(0.127, (3,Years)), (0.274, (4,Years)),
(0.456, (5,Years)), (0.647, (6,Years)),
(0.827, (7,Years)), (0.996, (8,Years)),
(1.147, (9,Years)), (1.280, (10,Years)),
(1.404, (11,Years)), (1.516, (12,Years)),
(1.764, (15,Years)), (1.939, (20,Years)),
(2.003, (25,Years)), (2.038, (30,Years))] ]
```
The bootstrapping is then performed by
```
eonia_curve = PiecewiseLogCubicDiscount(0, TARGET(), helpers, Actual365Fixed() )
```
The initial "0" above tells the bootstrapping algorithm that the reference date of the term structure should be on the previously defined `evaluationDate`.
I don't want my term structure object to change its reference date later on when I change the evaluation date. So I tried to call
```
eonia_curve = PiecewiseLogCubicDiscount(today, TARGET(), helpers, Actual365Fixed() )
```
which I found very natural. But it resulted in: NotImplementedError: Wrong number or type of arguments for overloaded function 'new_PiecewiseLogCubicDiscount'.
Question: How could I correct the above code line to bootstrap with a fixed reference date?
Side note: In section 5 of the mentioned book the author discussed the difference of fixed vs unfixed reference dates. However the code they used did't really help me, because the date was not explicitly specified but taken from an earlier stripped term structure.
```
# curve1 is an allready stripped term structure object
dates, rates = zip(*curve1.nodes())
# first date is taken as reference date
curve2 = ForwardCurve(dates, rates, Actual360())
```
However, I don't want to call the bootstripping algorithm twice: once with the evaluation date as reference date and a second time with `today` as reference date.
Thank you very much, Bernd
## Answer by byouness (score 1, accepted)
https://quant.stackexchange.com/a/40268
To construct a `PiecewiseLogCubicDiscount` object with a fixed reference date, please use the following constructor:
```
PiecewiseLogCubicDiscount(reference_date, helpers, day_counter, ...)
```
Taking your example:
```
eonia_curve = PiecewiseLogCubicDiscount(Date(15, December, 2012), helpers, Actual365Fixed())
eonia_curve.referenceDate()
# result: Date(15,12,2012)
```
How you can get to this result yourself:
If you use a constructor that doesn't exist, or that's not SWIGed, then you will get the `NotImplementedError`, which will usually list the available implementations, and in your case, you can see in this list the one you are looking for. For example:
```
PiecewiseLogCubicDiscount()
#NotImplementedError: Wrong number or type of arguments for overloaded function 'new_PiecewiseLogCubicDiscount'.
# Possible C/C++ prototypes are:
# ...
# PiecewiseLogCubicDiscountPtr::PiecewiseLogCubicDiscountPtr(Date const &,std::vector< boost::shared_ptr< RateHelper >,std::allocator< boost::shared_ptr< RateHelper > > > const &,DayCounter const &)
```
You could also check what's available or not in the SWIG interface files:
- Check piecewiseyieldcurve.i file in the QuantLib-SWIG project. Specifically lines 46 and 110. ` 46: %define export_piecewise_curve(Name,Base,Interpolator) 110: export_piecewise_curve(PiecewiseLogCubicDiscount,Discount,MonotonicLogCubic); ` These show that `PiecewiseLogCubicDiscount` is a `PiecewiseYieldCurve` with `Base = Discount` and `Interpolator = MonotonicLogCubic`.
```
46: %define export_piecewise_curve(Name,Base,Interpolator)
110: export_piecewise_curve(PiecewiseLogCubicDiscount,Discount,MonotonicLogCubic);
```
- Have a look at the SWIGed constructors. In lines 56 to 69, you can find the one you are looking for. It takes the following arguments: Reference date: `const Date& referenceDate` Rate helpers : `const std::vector<boost::shared_ptr<RateHelper> >& instruments` Day counter : `const DayCounter& dayCounter` Optional arguments jumps, jumpDates, accuracy and interpolator.
## Answer by Aria (score 0)
https://quant.stackexchange.com/a/41363
Try ql.Date(dd,mm,yyyy) instead of Date(dd,mm,yyyy). It should fix your problem. I use the former "today" and it's fine.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.