Skip to content
All library documents

Set QuantLib's Evaluation Date to Reproduce Yield Curve Examples

Article Quant Q&A · Author: imrichardcole

Summary

The document investigates why a QuantLib piecewise yield-curve example produces zero rates different from those shown in its teaching slides. The reported output from the copied code is substantially lower than the slide values, despite using the same example source. The accepted answer traces the mismatch to the library's evaluation date: the example defines a historical date but does not set it as QuantLib's evaluation date.

QuantLib therefore performs the calculation using its default evaluation date, which has advanced from the date assumed by the original example. Setting the evaluation date to the example's defined date makes the results match the slides. This is a focused debugging lesson about date-dependent financial calculations, not a general explanation of curve construction; the document offers one specific diagnosis and does not examine other possible sources of discrepancies.

Key ideas

  • QuantLib calculations can depend on the global evaluation date.
  • Defining a date variable does not necessarily make it the library's evaluation date.
  • An unset evaluation date can cause historical yield-curve examples to use the current date.
  • Set the evaluation date explicitly to reproduce date-sensitive reference results.

Tags

Full text
# Unable to match quantlib examples


# Unable to match quantlib examples












I'm currently learning Quantlib using C++ and am following the very good instructions here:

https://www.quantlib.org/slides/dima-ql-intro-2.pdf

Specifically on building piecewise yieldcurves (slide 102) the example code gives the following output:

```
Settlement Date:September 15th, 2009
Zero 3M: 0.299690 % Actual/360 simple compounding
Zero 6M: 0.682500 % Actual/360 simple compounding
Zero 9M: 0.997500 % Actual/360 simple compounding
```

Yet copying the code verbatim using the header `YieldCurve6.h`, I consistently get the following:

```
Settlement Date:September 15th, 2009
Zero 3M: 0.240698 % Actual/360 simple compounding
Zero 6M: 0.240770 % Actual/360 simple compounding
Zero 9M: 0.240844 % Actual/360 simple compounding
```

Is anyone else able to run the example code within the slides and get matching results?

Update 1

As per the comment below, I've put the code here which comes from the code used in the slides:

https://gist.github.com/imrichardcole/2859eccb2240e4c663b64fecf77ed407

## Answer by Luigi Ballabio (score 2)

https://quant.stackexchange.com/a/76709

The code in the slide is not setting the evaluation date, therefore the calculation is done as of 2023, which of course throws it off. You need to add

```
Settings::instance().evaluationDate() = today;
```

after you define `today` in the code. This will give you the results in the slide.

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.