Building a QuantLib Discount Curve from Bloomberg Discount Factors
Summary
The document describes using Bloomberg-provided discount factors to construct a QuantLib discount curve for pricing instruments such as swaps. It emphasizes that Bloomberg supplies market prices for curve-building instruments rather than one universal yield curve: the result depends on choices such as instruments, interpolation, curve side, and OIS stripping. To reproduce Bloomberg pricing, a user can request discount factors from a curve ticker and load the returned dates and factors into QuantLib.
The example uses log-linear interpolation and applies the resulting curve through a yield-curve handle and a discounting swap engine to calculate a vanilla swap’s fair rate. The author reports close agreement with Bloomberg’s swap-pricing setup when settings match, but gives no quantified error or broader validation. The example requires Bloomberg Terminal access and leaves curve construction choices, including interpolation, to the user. It also notes that practical multi-curve pricing may require separate discount and forward curves.
Key ideas
- Bloomberg curve results depend on selected instruments and configuration choices.
- Discount factors can be retrieved directly and used to build a QuantLib curve.
- The example prices a vanilla swap using a discounting engine and log-linear interpolation.
- Matching Bloomberg settings is necessary for close pricing agreement.
- Multi-curve applications may require distinct discount and forward curves.
Tags
Full text
# Using Discount Rates and Zero rate curve from Bloomberg in Quantlib
# Using Discount Rates and Zero rate curve from Bloomberg in Quantlib
I'd like to use the Discount Rates and Zero rate curve from Bloomberg instead of deriving the rates from the yield curve. Can someone share a sample code to use these rates directly in VanillaSwap or FloatingRateBond/FixedRateBond classes in python?
## Answer by David Duarte (score 3)
https://quant.stackexchange.com/a/51588
You should be aware that Bloomberg doesn't have a yield curve. Bloomberg has market prices of the instruments to build a yield curve and the result will depend on the particular configuration for your user. Some of these choices would be:
- Instruments (Deposits, Futures, FRAS, Swaps)
- Interpolation Method
- Curve Side (Bid, Ask, Mid)
- OIS DC Stripping
If you don't want to build the yield curve in QuantLib, althought it's fairly easy to replicate your Bloomberg curve if you use the same inputs and same curve parameters, you can get discount factors directly from the curve ticker using the field `SW_CRV_DISCOUNT_FACTORS`
Here is a simple example to get you started that you will obviously have to run on a computer with the Bloomberg Terminal software installed and logged in.
There are many wrappers for the Bloomberg API on github. In this example I'm using `pybbg`
```
import pybbg
bbg = pybbg.Pybbg()
df = bbg.bds('YCSW0045 Index', 'SW_CRV_DISCOUNT_FACTORS')
```
This will give you a DataFrame with two columns (dates and discount factor) that you can input directly to build a curve object in QuantLib. However, you will still need to choose the interpolation method for the discount factors. This example uses log-linear interpolation of discount factors
```
import QuantLib as ql
dates = df.Date.astype(str).apply(lambda x: ql.Date(x, '%Y-%m-%d')).tolist()
discountFactors = df['Discount Factor'].tolist()
curve = ql.DiscountCurve(dates, discountFactors, ql.ActualActual())
yts = ql.YieldTermStructureHandle(curve)
engine = ql.DiscountingSwapEngine(yts)
swap = ql.MakeVanillaSwap(ql.Period('5y'), ql.Euribor6M(yts), 0.01, ql.Period("2D"), pricingEngine=engine)
print(swap.fairRate())
```
The output is very close to what I get in SWPM with the same settings. Also, note I used a single curve and you should extend this example to get a discount curve and a forward 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.