Skip to content
All library documents

Using Zero Curves to Obtain Discount Factors in QuantLib

Article Quant Q&A · Author: Bogaso

Summary

The document explains how to obtain discount factors from a zero-rate curve in QuantLib. The key point is that a zero curve can already serve as a discount curve: calling its discount method for a date or year fraction performs the conversion. The accepted answer illustrates querying the curve at its nodes to collect corresponding discount factors.

For dates between nodes, the resulting values depend on the curve’s interpolation setup. The discussion names alternative zero-curve and piecewise curve classes that use different interpolation approaches. It does not provide a general comparison of interpolation behavior or explain curve construction and calibration in depth. The example is limited to a supplied curve and demonstrates access to discount factors rather than building a separate discount curve object.

Key ideas

  • A constructed zero curve can return discount factors directly through its discount method.
  • Discount factors can be queried at the curve’s nodes or at other dates.
  • Interpolation choices determine values between curve nodes.
  • The example demonstrates retrieval of discount factors, not curve calibration.

Tags

Full text
# How to convert a Zero curve to a Discount Curve


# How to convert a Zero curve to a Discount Curve












I have created a `Zero-Curve` as below -

```
from QuantLib import *
spot_dates = [Date(1, 1, 2015), Date(1, 6, 2015), Date(1, 12, 2015), Date(1, 4, 2016), Date(1, 8, 2016)]
spot_rates = [0, 0.02, 0.04, 0.06, 0.08]
us_calendar = UnitedStates()
zero_curve = ZeroCurve(spot_dates, spot_rates, Actual365Fixed(), us_calendar, Linear(), Compounded, Annual)
```

Now I wish to transform this `zero_curve` to a `discount-curve`.

Does `QuantLib` offer any direct function to achieve the same.

Thanks for your help

## Answer by David Duarte (score 1, accepted)

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

Although you can build the curve in different ways (from spot rates, from discount factors, by bootstrapping instruments and by fitting instruments), once the curve instance is successfully built, as Luigi said, the discount method will give you the discount factors for dates or year fractions.

Example using you code:

```
dfs = [zero_curve.discount(dt) for dt, rate in zero_curve.nodes()]
print(dfs)
```

[1.0, 0.9918411458168641, 0.9647467581357048, 0.9297902787888683, 0.8852611853613657]

To specify the interpolation method you want for points that are not curve nodes, you can use different alternatives of ZeroCurve and Piecewise classes (LogLinearZeroCurve, CubicZeroCurve, PiecewiseLogLinearDiscount, PiecewiseLogCubicDiscount, PiecewiseLinearZero, etc)

## Answer by Luigi Ballabio (score 4)

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

Your curve can already be used as a discount curve. Its `discount` method will do the conversion internally.

## Answer by Dom (score 2)

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

This is not a direct answer to your question as it is not Quantlib-related. I would just like to mention that I have just released a pure python finance library that does this called FinancePy. You can find it at https://github.com/domokane/FinancePy. It covers this functionality and gives you the ability to drop down into the underlying code.

You can install it using pip.

A set of example notebooks are provided at https://github.com/domokane/FinancePy-Examples.

Documentation can be found here.

https://github.com/domokane/FinancePy-Examples/blob/master/FinancePyManualV_0.180.pdf

It's a beta version so not guaranteed to be bug-free but I would be happy to get comments and feedback.

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.