David Yang
David Yang

Reputation: 2141

Bloomberg API in Python: How to Get Historical Reference Data

I'm trying to figure out how to get historical reference data through bloomberg api in python. Essentially, I am attempting to reproduce the following excel BDH in python:

=BDH("IBM US EQUITY","3MTH_IMPVOL_100.0%MNY_DF","2015-01-01","2016-01-01")

None of the python packages I've found seem to offer this functionality. For instance, while I can get reference data through tia:

from tia.bbg import LocalTerminal
resp = LocalTerminal.get_reference_data('SPX Index','3MTH_IMPVOL_100.0%MNY_DF')

I can't figure out how to pull the historical time series of implied vol as opposed to the single datapoint.

Has anyone done this before?

Upvotes: 4

Views: 14306

Answers (2)

mgilbert
mgilbert

Reputation: 3655

You could take a look at the pdblp package and ref_hist() function in particular. (Disclaimer: I am the author). This function acts as a simple wrapper to provide iterative calls to the ReferenceDataRequest Bloomberg Open API service, overriding the associated date field for the particular ticker, e.g. REFERENCE_DATE, CURVE_DATE, etc.

I don't currently have access to a Bloomberg terminal so cannot tell you what the date field for 3MTH_IMPVOL_100.0%MNY_DF is, but a simple example you should be able to adapt for your purposes is:

import pdblp
con = pdblp.BCon()
con.start()
con.ref_hist('AUD1M Curncy', 'DAYS_TO_MTY', dates=['20150625', '20150626'],
             date_field="REFERENCE_DATE")

Upvotes: 1

Tanguy Bretagne
Tanguy Bretagne

Reputation: 440

I don't know why you haven't found it but it is in tia.
get_historical is the function name.
The function to use is: resp = LocalTerminal.get_historical('SPX Index','3MTH_IMPVOL_100.0%MNY_DF', start="2015-01-01",end="2016-01-01")

You might have to do something like resp.as_frame() to get the dataframe of data.

I encourage you to go through the tia github to examine the code to understand how to get historical data for your other needs.

Upvotes: 2

Related Questions