QuantLib Zero Rates: Entering Yield Curve Rates as Decimals
Summary
The document diagnoses unexpectedly high rates returned by QuantLib when converting a yield curve to annual compounding. The example supplies zero-rate inputs that appear to be percentages, then compares continuous and compounded outputs and finds that the latter are far above the expected values.
The explanation is a units error: QuantLib consumes rates as decimal values. An input such as 2.72901 is interpreted as a rate of 2.72901, or 272.901%, rather than 2.72901%. Entering percentage figures without dividing by 100 therefore produces extreme compounded rates. The discussion is narrowly about correctly scaling rate inputs when building or querying a curve; it does not provide a broader treatment of day-count conventions, curve interpolation, or compounding formulas.
Key ideas
- QuantLib rate inputs are decimals rather than percentage-point values.
- A quoted rate of 2.72901 percent should be supplied as 0.0272901.
- Mis-scaled inputs can make compounded zero-rate outputs appear implausibly large.
- Check the units of curve data before comparing continuous and periodic compounding results.
Tags
Full text
# Quantlib Yield curve and rate compounding
# Quantlib Yield curve and rate compounding
I need help in understanding Quantlib's interpretation of yield curve and rates. The rate output retrieved from yield curve differs from expectation for non continuous cases.
Illustration: Let's start by defining the yield curve ..
```
tod = ql.Date(5,5,2022)
ardates = [tod, tod+ql.Period(1,ql.Weeks), tod+ql.Period(1,ql.Months), tod+ql.Period(3,ql.Months),
tod+ql.Period(6,ql.Months),tod+ql.Period(1,ql.Years),tod+ql.Period(2,ql.Years) ]
arzeros = [0.43902, 0.80713,1.0581, 1.19588,1.64246, 2.2557, 2.72901]
```
I can retrive the values from the yield curve as follows .. This is working as expected for ql.Continuous
```
print(arc1.zeroRate(0, ql.Continuous).rate())
print(arc1.zeroRate(1, ql.Continuous).rate())
print(arc1.zeroRate(2, ql.Continuous).rate())
0.4409131371427133
2.2387596685082873
2.714784836065574
```
But if I try to get yield curve using other compounding approaches, I get very different numbers.
```
print(arc1.zeroRate(0, ql.Compounded, ql.Annual).rate())
print(arc1.zeroRate(1, ql.Compounded, ql.Annual).rate())
print(arc1.zeroRate(2, ql.Compounded, ql.Annual).rate())
0.5541257006801319 vs. expectation of ~ 0.4419
8.38168766530322 vs. expectation of ~ 2.2639 (i.e. e^(1*2.2387%) -1 )
14.101360454177165 vs. expectation of ~ 2.7519 (i.e. e^(2*2.7147%)^0.5 -1 )
```
Can you good folks help me understand why the results differ from my expectation. Is my expectation incorrect in the first place ?
Regards, Rohit
## Answer by Rohit Gajare (score 0)
https://quant.stackexchange.com/a/70823
There was an error in the question itsef. The rates are consumed as decimals, so 2.72901 is regarded as 272.9% instead of 2.72901%, hence the difference in actual vs. expected behavior.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.