Bloomberg API in Python: How to Get Historical Reference Data

David Yang picture David Yang · Dec 19, 2017 · Viewed 8k times · Source

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?

Answer

Tanguy Bretagne picture Tanguy Bretagne · Dec 21, 2017

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.