Why a Zero Curve May Not Return Its Input Rate at Time Zero
Summary
The document explains a QuantLib zero-curve result where querying the rate at the initial date returns a value slightly different from the rate supplied at that node. The implementation derives zero rates through discount factors. At time zero, recovering a zero rate from a discount factor would require an indeterminate calculation, so the library uses a nearby positive time as a proxy instead.
That proxy can differ from the input rate when the curve changes sharply close to the initial date. The response distinguishes this special initial point from later curve nodes, which should reproduce their input zero rates within numerical accuracy. This is an implementation detail rather than a general claim that interpolation fails to preserve nodes. The observed discrepancy depends on the curve’s shape and the software’s handling of the zero-time case; the discussion does not provide a code change or guarantee about future releases.
Key ideas
- The implementation converts discount factors to zero rates, making time zero a special case.
- A zero rate cannot be recovered directly from a discount factor at time zero using the usual formula.
- QuantLib uses a nearby positive time as a proxy for the initial zero rate.
- A steep rate change near the initial date can make that proxy differ from the supplied node value.
- Later curve nodes should reproduce their input rates within numerical accuracy.
Tags
Full text
# Zero Curve Interpolation Does Not recover Node point input rates
# Zero Curve Interpolation Does Not recover Node point input rates
I having an issue with interpolation in QuantLib Python. Please see the code below for a minimum working example
```
myCurve = ql.ZeroCurve([ql.Date(2,3,2024),ql.Date(2,8,2024)],
[0.05,0.09],
ql.Actual365Fixed(),
ql.NullCalendar(),
ql.Linear(),
ql.Continuous)
print(myCurve.zeroRate(ql.Date(2,3,2024), ql.Actual365Fixed(),ql.Continuous).rate())
print(myCurve.zeroRate(0,ql.Continuous).rate())
```
The output in both of those cases is 0.05000954248362214. I am expecting to recover the input value of 0.05?
## Answer by Luigi Ballabio (score 3, accepted)
https://quant.stackexchange.com/a/76409
For historical reasons, the curve implementation goes through discount factors to calculate zero rates, no matter what the underlying representation is; see https://github.com/lballabio/QuantLib/blob/master/ql/termstructures/yieldtermstructure.cpp#L98-L115.
Unfortunately, this makes $t=0$ a special case. Unlike for all other times, we can't retrieve the zero from the discount as the formula becomes indeterminate. Therefore, we use as proxy the zero we can retrieve from a small time $t' > 0$. Of course, though $t'$ is small, that's already different enough from zero to see a difference, since your rates are increasing sharply.
Other nodes don't have this problem; you should be able to retrieve your original zero rate from 2024-08-02 within numerical accuracy.
I might try to sidestep this problem in a future release, but I'll have to be careful to keep the change backward compatible in interface and behavior, so I can't guarantee I'll succeed.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.