Retrieve Bloomberg Historical Data

This example shows how to retrieve historical data from Bloomberg® for a single security. The example shows retrieving weekly data within a date range and retrieving data with a default period. Then, the example also shows how to retrieve data for multiple securities. To create a successful Bloomberg connection, see Connect to Bloomberg.

Connect to Bloomberg

Create a Bloomberg Desktop connection.

c = blp;

Alternatively, you can connect to the Bloomberg Server using blpsrv or Bloomberg B-PIPE® using bpipe.

Retrieve Historical Data for One Security

Retrieve monthly closing and open price data from January 1, 2012, through December 31, 2012, for Microsoft®.

s = 'MSFT US Equity';
f = {'LAST_PRICE';'OPEN'}; 
fromdate = '1/01/2012'; 
todate = '12/31/2012'; 
period = 'monthly'; 

[d,sec] = history(c,s,f,fromdate,todate,period)
d = 

     734899.00         27.87         25.06
     734928.00         30.16         28.12
     734959.00         30.65         30.34
     ...

sec =

  cell

    'MSFT US Equity'

d contains the numeric representation of the date in the first column, closing price in the second column, and open price in the third column. Each row represents data for one month in the date range. sec contains the Bloomberg security name for Microsoft.

Retrieve Weekly Historical Data

Retrieve the weekly closing prices from November 1, 2010 through December 23, 2010 for the Microsoft security using US currency. In this case, the anchor date depends on the date December 23, 2010. Because this date is a Thursday, each previous value is reported for the Thursday of the week in question.

f = 'LAST_PRICE';
fromdate = '11/01/2010'; 
todate =  '12/23/2010'; 
period = {'weekly'}; 
currency = 'USD'; 

[d,sec] = history(c,s,f,fromdate,todate, ... 
    period,currency)
d =

     734446.00         27.14
     734453.00         26.68
     734460.00         25.84
     734467.00         25.37
     734474.00         26.89
     734481.00         27.08
     734488.00         27.99
     734495.00         28.30


sec =

  1×1 cell array

    {'MSFT US Equity'}

d contains the numeric representation for the date in the first column and the closing price in the second column. sec contains the name of the Microsoft security.

Retrieve Historical Data Using Default Period

Retrieve the closing prices from August 1, 2010 through September 10, 2010 for the Microsoft security in US currency, and set the default period of the data by using []. The default period of a security depends on the security itself.

fromdate = '8/01/2010'; 
todate = '9/10/2010'; 
currency = 'USD'; 

[d,sec] = history(c,s,f,fromdate,todate, ...
    [],currency)
d =

     734352.00         26.33
     734353.00         26.16
     734354.00         25.73
     ...

sec =

  1×1 cell array

    {'MSFT US Equity'}

d contains the numeric representation for the date in the first column and the closing price in the second column. sec contains the name of the Microsoft security.

Retrieve Historical Data for Multiple Securities

Retrieve monthly closing and open prices from January 1, 2012, through December 31, 2012, for the IBM® and Ford Motor Company® securities.

d is a cell array of double matrices that contains the historical data for both securities. sec contains the Bloomberg security names for the IBM and Ford Motor Company securities in a cell array. Each security name is a character vector.

s = {'IBM US Equity','F US Equity'};
f = {'LAST_PRICE';'OPEN'}; 
fromdate = '1/01/2012'; 
todate = '12/31/2012'; 
period = 'monthly'; 

[d,sec] = history(c,s,f,fromdate,todate,period)
d =

  2×1 cell array

    [12×3 double]
    [12×3 double]


sec =

  2×1 cell array

    'IBM US Equity'
    'F US Equity'

Display the closing and open prices for the first security.

d{1}
ans =

     734899.00        192.60        186.73
     734928.00        196.73        193.21
     734959.00        208.65        197.23
     ...

The data in the double matrix is:

  • First column — Numeric representation of the date

  • Second column — Closing price

  • Third column — Open price

Each row represents data for one month in the date range.

Close Bloomberg Connection

close(c)

See Also

| |

Related Examples

More About