matthewgilbert / pdblp

pandas wrapper for Bloomberg Open API
MIT License
242 stars 67 forks source link

Pull curve table data using ref_hist #5

Closed ryanshrott closed 7 years ago

ryanshrott commented 7 years ago

Would like to grab curves data like this: df_curve = con.ref_hist("BVIS0587 Index", "CURVE_TENOR_RATES", '20160625', '20160625')

matthewgilbert commented 7 years ago

I don't currently have a connection to Bloomberg so I can't really add functionality. What would this call return, the underlying constituents of the curve?

ryanshrott commented 7 years ago

It should have similar functionality to the excel function.

In excel, you can write: =BDS("YCSW0254Index","CURVE_TENOR_RATES","CURVE_DATE","20161208","cols=6;rows=26")

And this is returned: 1D SFDR1T Curncy -0.75 -0.875 -1 2016-12-08 1W SF0001W Index -0.781 -0.781 -0.781 2016-12-08 1M SF0001M Index -0.808 -0.808 -0.808 2016-12-08 2M SF0002M Index -0.776 -0.776 -0.776 2016-12-08 3M SF0003M Index -0.736 -0.736 -0.736 2016-12-08 6M SF0006M Index -0.669 -0.669 -0.669 2016-12-08 1Y SFSW1V3 Curncy -0.743 -0.783 -0.823 2016-12-08 2Y SFSW2V3 Curncy -0.71 -0.75 -0.79 2016-12-08 3Y SFSW3V3 Curncy -0.664 -0.68 -0.695 2016-12-08 4Y SFSW4V3 Curncy -0.543 -0.583 -0.623 2016-12-08 5Y SFSW5V3 Curncy -0.453 -0.468 -0.483 2016-12-08 6Y SFSW6V3 Curncy -0.32 -0.36 -0.4 2016-12-08 7Y SFSW7V3 Curncy -0.207 -0.247 -0.287 2016-12-08 8Y SFSW8V3 Curncy -0.105 -0.145 -0.185 2016-12-08 9Y SFSW9V3 Curncy -0.01 -0.05 -0.09 2016-12-08 10Y SFSW10V3 Curncy 0.075 0.035 -0.005 2016-12-08 11Y SFSW11V3 Curncy 0.157 0.107 0.058 2016-12-08 12Y SFSW12V3 Curncy 0.196 0.171 0.146 2016-12-08 13Y SFSW13V3 Curncy 0 0 0 #N/A N/A 14Y SFSW14V3 Curncy 0 0 0 #N/A N/A 15Y SFSW15V3 Curncy 0.377 0.328 0.278 2016-12-08 20Y SFSW20V3 Curncy 0.52 0.47 0.42 2016-12-08 25Y SFSW25V3 Curncy 0.6 0.55 0.5 2016-12-08 30Y SFSW30V3 Curncy 0.652 0.602 0.553 2016-12-08 40Y SFSW40V3 Curncy 0 0 0 #N/A N/A 50Y SFSW50V3 Curncy 0 0 0 #N/A N/A

matthewgilbert commented 7 years ago

Will try and take a look at this when I next get access to a Bloomberg connection

matthewgilbert commented 7 years ago

If you are only interest in one historical date at a time, something like this would work

df = con.ref("BVIS0587 Index", "CURVE_TENOR_RATES", ovrds=[("CURVE_DATE", "20160625")]) 
df.head(n=6)
           ticker              field           value
0  BVIS0587 Index  CURVE_TENOR_RATES              3M
1  BVIS0587 Index  CURVE_TENOR_RATES  BV3M0101 Index
2  BVIS0587 Index  CURVE_TENOR_RATES    -2.42454e-14
3  BVIS0587 Index  CURVE_TENOR_RATES    -2.42454e-14
4  BVIS0587 Index  CURVE_TENOR_RATES           0.504
5  BVIS0587 Index  CURVE_TENOR_RATES      2016-06-24

However, this is not storing the field for the value column which is somewhat of a bug, i.e. looking at the received message we can see

DEBUG:root:Message Received:
 ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "BVIS0587 Index"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                CURVE_TENOR_RATES[] = {
                    CURVE_TENOR_RATES = {
                        Tenor = "3M"
                        Tenor Ticker = "BV3M0101 Index"
                        Ask Yield = -0.000000
                        Mid Yield = -0.000000
                        Bid Yield = 0.504000
                        Last Update = 2016-06-24
                    }
...

The ref_hist method should also handle this type of data, however in some sense that method is just a simple hack around iteratively calling ref with updated overrides to a reference time period. In it's current form it only supports REFERENCE_DATE whereas this is overriding the field CURVE_DATE.

matthewgilbert commented 7 years ago

This is fixed in 5d96b61fedda4fdd8b934a6283f7dd6c44916ff5. The API for ref_hist has slightly changed. What you are trying to do could be done with

con.ref_hist("BVIS0587 Index", "CURVE_TENOR_RATES", dates=['20160625'],
             date_field="CURVE_DATE")