Skip to content
All library documents

Choosing a Moving Reference Date for QuantLib Yield Curves

Article Quant Q&A · Author: Fitz_Hoo

Summary

This discussion explains why changing QuantLib’s evaluation date does not necessarily move the reference date of a discount curve built directly from a fixed set of dates and rates. It outlines two ways to construct a curve when a different reference date is needed.

One approach builds a piecewise curve from rate helpers and uses the curve configuration to set the reference date relative to the evaluation date. The other directly constructs a zero curve but shifts its input dates when moving the reference date. The examples concern QuantLib’s Python interface and a specific curve setup; the brief answers do not compare interpolation choices, conventions, or pricing consequences. The original question points readers to further material for the distinction between curves that do and do not follow the evaluation date.

Key ideas

  • A directly constructed zero curve can retain its reference date when the evaluation date changes.
  • Rate helpers and a piecewise curve provide a way to define the curve reference date relative to the evaluation date.
  • With a directly supplied date-and-rate curve, shifting the input dates can shift the resulting reference date.
  • Curve construction choices depend on the intended date conventions and behavior.

Tags

Full text
# How to change the YieldTermStructureHandle's referenceDate in QuantLib


# How to change the YieldTermStructureHandle's referenceDate in QuantLib












Suppose we have already known the dates and rates of a spot rate curve, and I passed the data to the ZeroCurve class to construct a discount curve for bond pricing. What I wanna find is how to change the referenceDate of the discount curve without changing the original dates and rates data. I have tried like below:

```
Settings.instance().evaluationDate = Date(11, 12, 2017)

fake_dates = [Date(8, 5, 2017+i) for i in range(5)]
fake_rates = [(1+i)/100 for i in range(5)]

day_counter = ActualActual()

spot_curve = ZeroCurve(fake_dates, fake_rates, day_counter, China(), Linear(), Compounded, Semiannual)     

discount_curve = YieldTermStructureHandle(spot_curve)

print(discount_curve.referenceDate())

# Reset the evaluation date

Settings.instance().evaluationDate = Date(12, 12, 2017)
print(discount_curve.referenceDate())
```

But, this doesn't work! It returns the same result of Date(11, 12, 2017)

I am a newbie to QuantLib-Python, it would be appreciated if anyone could do me a favor. Many thanks!

## Answer by Bernd (score 0, accepted)

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

I suggest that you read the following chapter in the QuantLib Python Cookbook:

"5. Term structures and their reference dates"

Alternatively, see this video:

https://www.youtube.com/watch?v=pc1yOmxU2GQ

The author strips a term structure in a way that its reference date moves with the evaluation date and one method that it doesn't.

## Answer by Fitz_Hoo (score 0)

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

I meant to add a comment to answer my own question according to @Bernd's link(thx @Bernd), but the comment editor is really not friendly to use for me. Back to the question, there are two alternative ways to choose.

- Use the tenors and rates to construct a helper. `helper_= DepositRateHelper(QuoteHandle(SimpleQuote(rate/100)),Period(*tenor),0,China(),Following,False,ActualActual()) for tenor, rate in [((1, Years), 1),((2, Years), 2),((3, Years), 3),((4, Years), 4), ((5, Years), 5)]] discount_curve = PiecewiseFlatForward(2, TARGET(), helper_, ActualActual()) discount_curve.referenceDate() `

```
helper_= DepositRateHelper(QuoteHandle(SimpleQuote(rate/100)),Period(*tenor),0,China(),Following,False,ActualActual()) for tenor, rate in [((1, Years), 1),((2, Years), 2),((3, Years), 3),((4, Years), 4), ((5, Years), 5)]]

discount_curve = PiecewiseFlatForward(2, TARGET(), helper_, ActualActual())
discount_curve.referenceDate()
```

Now, we can change the first argument of PiecewiseFlatForward to get our required referenceDate.

- Use the dates and rates to directly construct a curve. But now we have to change the dates if we want to change the referenceDate. `fake_dates_shift = [date + Period(2, Days) for date in fake_dates] spot_curve_shift = ZeroCurve(fake_dates_shift, fake_rates, day_counter, China(), Linear(), Compounded, Semiannual) discount_curve_shift = YieldTermStructureHandle(spot_curve_shift) discount_curve_shift.referenceDate() `

```
fake_dates_shift = [date + Period(2, Days) for date in fake_dates]   
spot_curve_shift = ZeroCurve(fake_dates_shift, fake_rates, day_counter, China(), Linear(), Compounded, Semiannual)     
discount_curve_shift = YieldTermStructureHandle(spot_curve_shift)
discount_curve_shift.referenceDate()
```

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.