Main Content

bloomberg

Bloomberg Desktop connection V3

Since R2021a

Description

The bloomberg function creates a bloomberg object. The bloomberg object represents a Bloomberg® Desktop connection using the Bloomberg V3 C++ API.

Other Datafeed Toolbox™ functions connect to different Bloomberg services: Bloomberg Server (bloombergServer) and Bloomberg B-PIPE® (bloombergBPIPE). For details about these services, see Comparing Bloomberg Connections.

For details about Bloomberg connection requirements, see Data Server Connection Requirements. To ensure a successful Bloomberg connection, perform the required steps before executing bloomberg. For details, see Installing Bloomberg and Configuring Connections.

Creation

Description

example

c = bloomberg creates a Bloomberg connection object with the Bloomberg Desktop C++ interface. You need a Bloomberg Desktop software license for the machine running the Datafeed Toolbox and MATLAB®.

example

c = bloomberg(port,ip,timeout) sets the Port and TimeOut properties, and uses the IP address of the local machine running Bloomberg to create a Bloomberg connection.

Caution

To refer to a Bloomberg connection in other functions, use the connection object created by the bloomberg function. Otherwise, using bloomberg as an input argument opens multiple Bloomberg connections, causing unexpected behavior and exhausting memory resources.

Input Arguments

expand all

IP address that identifies the local machine running Bloomberg, specified as a character vector or string scalar.

Example: 'localhost'

Data Types: char | string

Properties

expand all

This property is read-only.

Bloomberg V3 session, specified as a Bloomberg V3 API Session object.

Example: [1x1 datafeed.internal.BLPSession]

Port number of the local machine running Bloomberg, specified as a numeric scalar.

Example: 8194

Data Types: double

IP address of the local machine running Bloomberg, specified as a character vector.

The bloomberg function sets this property using the ip input argument.

Example: 'localhost'

Data Types: char

Timeout specifying the time in milliseconds that MATLAB attempts to connect to Bloomberg Desktop before timing out, specified as a numeric scalar.

Example: 10000

Data Types: double

Date and time data type, specified as one of these values.

ValueDescription
'' (default)Return date and time values as MATLAB date numbers.
'datetime'Return date and time values as a datetime array.

You can specify these values using a character vector or string (for example, "datetime").

When you create a bloomberg object, the bloomberg function leaves this property unset. To retrieve data, you must set this property value manually at the command line or in a script using dot notation, for example:

c.DatetimeType = 'datetime';
Then, you can use these supported functions:

  • getbulkdata

  • getdata

  • history

  • tahistory

  • timeseries

    Note

    If the DataReturnFormat property value is 'table' and the DatetimeType property value is 'datetime', then the returned data is a table that contains date and time values as a datetime array. If the DataReturnFormat property value is an empty character vector, then setting the DatetimeType property to 'datetime' returns date and time values for aggregated ticks and historical requests as MATLAB date numbers.

Data return format, specified as one of these values, which determine the data type of the returned data.

ValueData Type of Returned Data
'cell'cell array
'table'table
'timetable'timetable
'structure'structure

Note

The default data type of the returned data depends on the executed function. To specify the default data type, set the DataReturnFormat property to ''. For default data types, see the supported function list.

You can specify these values using a character vector or string (for example, "table").

When you create a bloomberg object, the bloomberg function leaves this property unset. To retrieve data, you must set this property value manually at the command line or in a script using dot notation, for example:

c.DataReturnFormat = 'structure';
Then, you can use these supported functions.

Supported FunctionValid Data Types for Returned Data
category
  • cell array (default)

  • structure

  • table

eqs
  • cell array (default)

  • structure

  • table

fieldinfo
  • cell array (default)

  • structure

  • table

fieldsearch
  • cell array (default)

  • structure

  • table

lookup
  • structure (default)

  • table

portfolio
  • structure (default)

  • table

getbulkdata
  • structure (default)

  • table

  • timetable

getdata
  • structure (default)

  • table

  • timetable

history
  • numeric array (default)

  • table

  • timetable

tahistory
  • structure (default)

  • table

  • timetable

timeseries
  • cell array (default for raw tick data)

  • numeric array (default for interval tick data)

  • table

  • timetable

Note

Regardless of the DatetimeType property value, if the DataReturnFormat property value is 'timetable', then the getdata and getbulkdata functions return a table that contains date and time values as datetime arrays.

Object Functions

expand all

closeClose Bloomberg Desktop connection V3
isconnectionDetermine Bloomberg Desktop connection V3
eqsEquity screening data for Bloomberg Desktop connection V3
getProperties of Bloomberg Desktop connection V3
getbulkdataBulk data with header information for Bloomberg Desktop connection V3
getdataCurrent data for Bloomberg Desktop connection V3
historyHistorical data for Bloomberg Desktop connection V3
portfolioCurrent portfolio data for Bloomberg Desktop connection V3
realtimeReal-time data for Bloomberg Desktop connection V3
tahistoryHistorical technical analysis for Bloomberg Desktop connection V3
timeseriesIntraday tick data for Bloomberg Desktop connection V3
categoryField category search for Bloomberg Desktop connection V3
fieldinfoField information for Bloomberg Desktop connection V3
fieldsearchField search for Bloomberg Desktop connection V3
lookupFind information about securities for Bloomberg Desktop connection V3

Examples

collapse all

First, create a Bloomberg Desktop connection. Then, request last and open prices for a security. The current data you see when running this code can differ from the output data here.

Create the Bloomberg connection using the Bloomberg Desktop C++ interface.

c = bloomberg
c =

  bloomberg with properties:

    Session: [1×1 datafeed.internal.BLPSession]
    IPAddress: "localhost"
    Port: 8194.00
    TimeOut: 0
    DatetimeType: ''
    DataReturnFormat: ''

The bloomberg function creates a bloomberg object c with these properties:

  • Bloomberg V3 API Session object

  • IP address of the local machine

  • Port number of the local machine

  • Number of milliseconds specifying how long MATLAB® attempts to connect to Bloomberg Desktop before timing out

  • Date and time data type

  • Data return format

Request last and open prices for Microsoft®.

[d,sec] = getdata(c,'MSFT US Equity',{'LAST_PRICE';'OPEN'})
d = 
    LAST_PRICE: 33.3401
          OPEN: 33.6000

sec = 
    'MSFT US Equity'

getdata returns a structure d with the last and open prices. Also, getdata returns the name of the security in sec.

Close the Bloomberg connection.

close(c)

First, create a Bloomberg Desktop connection with a timeout value. Then, request last and open prices for a security. The current data you see when running this code can differ from the output data here.

Create the Bloomberg connection using the Bloomberg Desktop C++ interface. Specify a timeout value of 10,000 milliseconds.

c = bloomberg([],[],10000)
c =

  bloomberg with properties:

    Session: [1×1 datafeed.internal.BLPSession]
    IPAddress: "localhost"
    Port: 8194.00
    TimeOut: 10000
    DatetimeType: ''
    DataReturnFormat: ''

The bloomberg function creates a bloomberg object c with these properties:

  • Bloomberg V3 API Session object

  • IP address of the local machine

  • Port number of the local machine

  • Number of milliseconds specifying how long MATLAB® attempts to connect to Bloomberg Desktop before timing out

  • Date and time data type

  • Data return format

Request last and open prices for Microsoft.

[d,sec] = getdata(c,'MSFT US Equity',{'LAST_PRICE';'OPEN'})
d = 
    LAST_PRICE: 33.3401
          OPEN: 33.6000

sec = 
    'MSFT US Equity'

getdata returns a structure d with the last and open prices. Also, getdata returns the name of the security in sec.

Close the Bloomberg connection.

close(c)

Version History

Introduced in R2021a