Products & Services Solutions Academia Support User Community Company

Learn more about Datafeed Toolbox   

Example: Retrieving Bloomberg Data

About This Example

The following example illustrates the use of the bloomberg.fetch function to retrieve data from a Bloomberg data server. Versions of the fetch function that retrieve data from other data servers work similarly.

Retrieving Header Data

A header (default) data request to a Bloomberg data server returns a fixed set of field data. Not all fields in the header data are relevant for a specific security.

Determining Header Fields

The list of valid header fields is stored in the file @bloomberg/bbfields.mat. To load this file, use the MATLAB load command:

load @bloomberg/bbfields

The variable headerfieldnames contains the list of header field names.

Obtaining Data

To retrieve header data using a connection to a Bloomberg data server, use the fetch function with the following syntax:

data = fetch(Connect, 'Security', 'HEADER', 'Flag')

Where:

Commands of the form:

data = fetch(Connection, Security)
data = fetch(Connection, Security, 'HEADER')
data = fetch(Connection, Security, 'HEADER', 'DEFAULT')

Are equivalent.

The returned data has a fixed set of fields. For example, a header inquiry for the security IBM US Equity returns data of the form:

                      Status:0
                        Open:93
             TodaysOpenPrice:93
                   HighPrice:93.1875
             TodaysHighPrice:93.1875
                    LowPrice:89
              TodaysLowPrice:89
                   LastPrice:90.9375
             TodaysLastPrice:0
                 SettlePrice:NaN
                    BidPrice:0
              TodaysBidPrice:NaN
                    AskPrice:0
              TodaysAskPrice:NaN
                    YieldBid:NaN
              TodaysYieldBid:NaN
                    YieldAsk:NaN
              TodaysYieldAsk:NaN
                     LimitUp:NaN
                   LimitDown:NaN
                OpenInterest:3359000
          LastPriceYesterday:95
                       Scale:1
               LastPriceTime:0.4993
           LastTradeExchange:7
               TickDirection:-1
                     BidSize:0
               TodaysBidSize:NaN
                     AskSize:NaN
               TodaysAskSize:0
                BidCondition:NaN
                AskCondition:NaN
          LastTradeCondition:NaN
         LastMarketCondition:NaN
                 Monitorable:1
                 TotalVolume:60018500
           TodaysTotalVolume:0
          TotalNumberOfTicks:63318
    TodaysTotalNumberofTicks:63318
            SessionStartTime:0.3958
              SessionEndTime:0.6875
                    Currency:538989397
                      Format:0
                 SecurityKey:{'IBM US Equity'}
                    AsOfDate:730441
              TodaysAsOfDate:730441

Retrieving Field Data

The fetch function with the GETDATA argument obtains Bloomberg field data. The entire set of field data provides statistics for all possible securities, but it does not apply universally to any one security.

Determining Field Names

The file @bloomberg/bbfields.mat stores the complete list of valid field names. To load this file, use the function:

load @bloomberg/bbfields

This command returns the following list of variables:

bbcategories
bbcurrency
bbdatamask
bbfieldids
bbfieldnames
bbfieldtypes
bbhelpfields
bboverrides
bbsectype
headerfieldnames 

The variable bbfieldnames contains a list of field names. This list includes the header field names plus many others. The other variables loaded extend the list of field names.

Obtaining Data

To obtain data for specific fields of a given security, use the fetch function with the following syntax:

d = fetch(Connect, Security, 'GETDATA', Fields)

For example, use the Bloomberg connection object c to retrieve the values of the fields Open and Last_Price:

d = fetch(c,'IBM US Equity','GETDATA', {'Open';'Last_Price'})
d = 
		Open: 126.2500
    Last_Price: 125.1250

Retrieving Time Series Data

The fetch function called with the 'TIMESERIES' argument returns price and volume data for a particular security on a specified date. Use the following command to return time-series data for a given security and a specific date:

data = fetch(Connection, Security, 'TIMESERIES', Date)

Date can be a MATLAB date string or serial date number.

To obtain time-series data for the current day, use the alternate form of the function:

data = fetch(Connection, Security, 'TIMESERIES', now)

To obtain time-series data for IBM using an existing connection c1, enter the function:

data = fetch(c1, 'IBM US Equity', 'TIMESERIES', '11/16/99')
data =
31.00     730440.31          130.00         1000.00
32.00     730440.31          130.00          200.00
32.00     730440.35          129.50        10000.00
31.00     730440.35          129.50          100.00
32.00     730440.35          129.50          100.00
 1.00     730440.56          129.25         4000.00
31.00     730440.56          129.38         1500.00
32.00     730440.56          129.50          500.00
 1.00     730440.56          129.63         5000.00
31.00     730440.56          129.63          400.00
32.00     730440.56          129.63          200.00
 1.00     730440.56          129.69         5000.00
31.00     730440.56          129.69          500.00
32.00     730440.56          129.69          500.00
31.00     730440.56          129.75          100.00
32.00     730440.56          130.00          100.00
 1.00     730440.56          130.00         5000.00
 1.00     730440.56          129.88         5000.00
31.00     730440.56          129.88          300.00

Column 1 contains the tick type flag. Column 2 contains the time stamp in MATLAB serial date number format. Column 3 contains the tick value. Column 4 contains the number of shares in the transaction.

Retrieving Historical Data

Use the fetch function with the 'HISTORY' argument to obtain historical data for a specific security.

To obtain historical data for a specified field of a particular security, run:

d = fetch(Connect,Security,'HISTORY',Field,FromDate,ToDate)

fetch returns data for the date range from FromDate to ToDate.

For instructions on determining valid field names, see Determining Field Names.

For example, to obtain the closing price for IBM for the dates July 15, 1999 to August 2, 1999 using the connection c1, enter:

data = fetch(c1, 'IBM US Equity', 'HISTORY', 'Last_Price',... 
'07/15/99', '08/02/99')
data =
     730316.00        136.31
     730317.00        136.25
     730320.00        134.63
     730321.00        128.25
     730322.00        129.00
     730323.00        123.88
     730324.00        124.81
     730327.00        123.00
     730328.00        126.25
     730329.00        128.38
     730330.00        125.38
     730331.00        125.69
     730334.00        122.25

Column 1 contains the date represented as a MATLAB date number, and column 2 contains the last price.

Finding Ticker Symbols

You can use the fetch function with the 'LOOKUP' argument to find a ticker symbol when you are not sure what the symbol is. To locate a specific ticker symbol, use the following syntax:

data = fetch(Connect, SearchString, 'LOOKUP', Market)

The SearchString argument is the comparison string used in the lookup operation. Market indicates the market in which the security trades. Allowable values for Market are:

For example, using fetch with the connection c1 to look up the ticker symbol for New Zealand government bonds returns a list of possible values:

data = fetch(c1, 'New', 'LOOKUP', 'Govt')
data = 
'NZTB     New Zealand Treasury Bill NZGB   New Zealand Governme'
'NZGB     New Zealand Government Bond NZ   New Zealand Govern'
'NZ       New Zealand Government International Bond HCNZ  Hous'
'ECNZ     Electric Corporation of New Zealand Bond ...
				NZTB NZGB NZ H'
  


Free Interactive Computational Finance CD

View demos and recorded presentations led by industry experts.

Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS