Getting a Discount Factor from a QuantLib Yield Curve in Python
Summary
The note gives the Python equivalent of a QuantLib Addin operation that retrieves a discount factor from a yield term structure. The relevant operation is to call the curve’s discount method with the effective date. That factor can then be used to discount a future cash flow or net present value to the curve’s reference date, provided the date conventions and curve setup are appropriate.
The response supplies a direct API mapping rather than a broader explanation or worked valuation example. It does not specify how the curve is constructed, how the effective date relates to the curve’s reference date, or whether the desired valuation date is today. Those details matter when applying the factor, so users should verify the curve’s reference date and intended discounting basis in their own setup.
Key ideas
- QuantLib Python yield term structures expose discount factors through a date-based method.
- The effective date is passed to the curve when retrieving its discount factor.
- A discount factor can be applied to cash flows or an NPV under the chosen curve.
- Correct use depends on the curve reference date and date conventions.
Tags
Full text
# qlYieldTSDiscount in QuantLib Python # qlYieldTSDiscount in QuantLib Python I have been using Quantlib Addin, now I am looking for the equivalent function for QuantLib in Python: ``` =qlYieldTSDiscount(EffectiveDate;DiscountCurve) ``` Or any workaround? I need to discount my NPV to today. ## Answer by Luigi Ballabio (score 3, accepted) https://quant.stackexchange.com/a/36984 That would be ``` discount_curve.discount(effective_date) ``` You'll find examples of various tasks in QuantLib-Python on Goutham Balaraman's blog or on the QuantLib Python Cookbook. Having a look at those might ease your learning curve.
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.