matthewgilbert / pdblp

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

Issue with overrides. Is this because the field is a bdp and not BBG #10

Closed FDara closed 7 years ago

FDara commented 7 years ago
import pdblp

con = pdblp.BCon(debug=False)
con.start()

print con.bdh('SPY US EQUITY', 'SP_VOL_SURF_MID','20150629','20150630',longdata=True,ovrds=[('REFERENCE_DATE','20170525'),('VOL_SURF_EXPIRY_OVR','20180119'),('VOL_SURF_STRIKE_OVR','200')])
matthewgilbert commented 7 years ago

It's helpful to include a full print out of messages to the console with con.debug = True for debugging purposes. Running your above snippet (with or without any overrides) I am seeing

import pdblp
con = pdblp.BCon(debug=True)
con.start()
con.bdh('SPY US EQUITY', 'SP_VOL_SURF_MID', '20150629', '20150630')
DEBUG:root:Sending Request:
 HistoricalDataRequest = {
    securities[] = {
        "SPY US EQUITY"
    }
    fields[] = {
        "SP_VOL_SURF_MID"
    }
    startDate = "20150629"
    endDate = "20150630"
    overrides[] = {
    }
}

DEBUG:root:Message Received:
 HistoricalDataResponse = {
    securityData = {
        security = "SPY US EQUITY"
        eidData[] = {
        }
        sequenceNumber = 0
        fieldExceptions[] = {
            fieldExceptions = {
                fieldId = "SP_VOL_SURF_MID"
                errorInfo = {
                    source = "236::bbdbh1"
                    code = 1
                    category = "BAD_FLD"
                    message = "Not valid historical field"
                    subcategory = "NOT_APPLICABLE_TO_HIST_DATA"
                }
            }
        }
        fieldData[] = {
        }
    }
}

Which seems to indicate this field is not available through a HistoricalDataRequest and is unrelated to any overrides.

FDara commented 7 years ago

Thanks. This is a bdp function and not BDH. It's what It is ReferenceDataRequest. Is ReferenceDataRequest not supported in pdblp?

matthewgilbert commented 7 years ago

ReferenceDataRequests are supported through BCon.ref, you can take a look at the tutorial to give you more info on relevant functionality https://matthewgilbert.github.io/pdblp/tutorial. When I run

con.ref('SPY US EQUITY', 'SP_VOL_SURF_MID')
DEBUG:root:Sending Request:
 ReferenceDataRequest = {
    securities[] = {
        "SPY US EQUITY"
    }
    fields[] = {
        "SP_VOL_SURF_MID"
    }
    overrides[] = {
    }
}

DEBUG:root:Message Received:
 ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "SPY US EQUITY"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
            }
        }
    }
}

I am not getting any errors in the response message however I am also not getting any data. This could be a permission issue of my end though, since for the field SP_VOL_SURF_MID I see

Single point volatility surface mid interpolated from BVOL... BVOL source data is for privileged Bloomberg Valuation (BVAL) users only.

FDara commented 7 years ago

Thank you I got it working the following way. Can you also tell me how can I choose a range for REFERENCE_DATE override. Right now it is set to 1 day only. Should I loop and append? or there is a way to pass in a range in the function?

import pdblp

con = pdblp.BCon(debug=True)
con.start()

print con.ref('SPY US EQUITY', 'SP_VOL_SURF_MID',ovrds=[('REFERENCE_DATE','20170525'),('VOL_SURF_EXPIRY_OVR','20180119'),('VOL_SURF_STRIKE_OVR','200')])

          ticker            field      value
0  SPY US EQUITY  SP_VOL_SURF_MID  19.261268
 ReferenceDataRequest = {
    securities[] = {
        "SPY US EQUITY"
    }
    fields[] = {
        "SP_VOL_SURF_MID"
    }
    overrides[] = {
        overrides = {
            fieldId = "REFERENCE_DATE"
            value = "20170525"
        }
        overrides = {
            fieldId = "VOL_SURF_EXPIRY_OVR"
            value = "20180119"
        }
        overrides = {
            fieldId = "VOL_SURF_STRIKE_OVR"
            value = "200"
        }
    }
}

DEBUG:root:Message Received:
 ReferenceDataResponse = {
    securityData[] = {
        securityData = {
            security = "SPY US EQUITY"
            eidData[] = {
            }
            fieldExceptions[] = {
            }
            sequenceNumber = 0
            fieldData = {
                SP_VOL_SURF_MID = 19.261268
            }
        }
    }
}
matthewgilbert commented 7 years ago

Looping and appending is one way, you could also take a look at the ref_hist method. Since I don't have access to this data it is difficult for me to provide more help, but given that you are overriding the REFERENCE_DATE the ref_hist method should work.