1
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.