pythonquantlib

How does QuantLib forwardRate function work?


I'm looking to find the expected interest rates for some period in the future based on the term structure of government bonds in python.

I'm trying to use this code as a base: http://gouthamanbalaraman.com/blog/quantlib-term-structure-bootstrap-yield-curve.html

I was hoping that this is what the forwardRate() function would do. But if I call:

yieldcurve.forwardRate(d, d+ ql.Period("1Y"), day_count, compounding, freq).rate()

The resulting rate is unreasonably high - above the rates anytime in that one year period.

An I misunderstanding what forwardRate is supposed to do / doing something wrong here / is there another way to get this value easily?


Solution

  • Based on that code it sounds like you're looking to calculate the 1Y forward rate for a particular date d. The forwardRate() method you mentioned should do just that, but check that the daycount and compounding are consistent with your yield curve definition since those can cause forward rates to look odd.

    Otherwise if the yield curve is upward sloping, it shouldn't be surprising that some forward rates are higher than any of the spot or par rates. That's just a consequence of the term structure.