Thursday 7 December 2017

Using Bloomberg From R and Excel


Bloomberg from R

First, you need to be logged on to Bloomberg.

If the Bloomberg/Excel add-in does not work, then:
1. Close Excel and/or R
2. Keep Bloomberg running
3. Go to Start-> Bloomberg -> API Environment Diagnostics
4. Click Start when the Bloomberg API Diagnostics window has loaded
5. If a “Login to wintrv…” message below then pops up, this occurs when Bloomberg isn’t open – it is highly recommended that you have Bloomberg running; you can proceed without it, but you may not be able to resolve some errors if you do so
6. Once the check is finished, you will get a 'Diagnostics completed' message
7. If the Repair button is available to press on the Bloomberg API Diagnostics window, it means it needs to run the repair and you should do so by clicking Repair (it should take a couple of minutes)
8. Once the check is done, and repair if necessary, the ideal state is all green ticks except for 2 yellow “!” for Dotnet Installation and Excel Throttle Interval only. Else, you can still run Excel or R-Studio and see if the Bloomberg-associated functionality is working.

# install the Bloomberg package, and connect
install.packages("Rblpapi")
library (Rblpapi)
blpConnect()

# get the Bloomberg data history for SPY US Equity - last 100 days - and plot it
x <-  bdh("SPY US Equity", "PX_LAST", start.date=Sys.Date()-100)
plot(x)

# find out what other fields are available for prices
res <- fieldSearch("price")
res

# get the Bloomberg data history for SPY US Equity - last 100 days - and plot it
x <-  bdh("SPY US Equity", "OPEN", start.date=Sys.Date()-100)
plot(x)

Bloomberg from Excel

As above, if the Bloomberg/Excel add-in does not work, then repair (Steps 1-8).
Open an Excel Sheet, and type the following into a cell:
Historical prices: BDH("F US Equity", "PX_LAST", “16/11/2000”, “15/11/2016”)
This will give you the last traded price (PX_LAST) for 'F US Equity (Ford Motor  Company) from 16/11/2000 to 15/11/2016. The first parameter must be the Bloomberg stock code.

For DMU students, this URL shows how to get data from Bloomberg into Excel.
Also for DMU students, this URL shows how to use Bloomberg.