getdata
Syntax
Description
Examples
Last and Open Price for Security
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;
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
security in sec
.
Close the Bloomberg connection.
close(c)
Specified Fields Given Override Fields and Values
First, create a Bloomberg Desktop connection. Then, request data for specific fields for a security using an override field and value. 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;
Request data for Bloomberg fields 'YLD_YTM_ASK'
,
'ASK'
, and 'OAS_SPREAD_ASK'
when
the Bloomberg field 'OAS_VOL_ASK'
is
'14.000000'
.
[d,sec] = getdata(c,'030096AF8 Corp',... {'YLD_YTM_ASK','ASK','OAS_SPREAD_ASK','OAS_VOL_ASK'},... {'OAS_VOL_ASK'},{'14.000000'})
d = YLD_YTM_ASK: 5.6763 ASK: 120.7500 OAS_SPREAD_ASK: 307.9824 OAS_VOL_ASK: 14 sec = '030096AF8 Corp'
getdata
returns a structure d
with
the resulting values for the requested fields.
Close the Bloomberg connection.
close(c)
Request for Security Using CUSIP Number
First, create a Bloomberg Desktop connection. Then, use the CUSIP number for a security to request last price. 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;
Request the last price for IBM® with the CUSIP number.
d = getdata(c,'/cusip/459200101','LAST_PRICE')
d = LAST_PRICE: 182.5100
getdata
returns a structure d
with
the last price.
Close the Bloomberg connection.
close(c)
Last Price for Security with Pricing Source
First, create a Bloomberg Desktop connection. Then, request the last price for a security. Specify the security using the CUSIP number with a pricing source. 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;
Specify IBM with the CUSIP number and the pricing source
BGN
after the @
symbol.
d = getdata(c,'/cusip/459200101@BGN','LAST_PRICE')
d = LAST_PRICE: 186.81
getdata
returns a structure d
with
the last price.
Close the Bloomberg connection.
close(c)
Constituent Weights Using Date Override
First, create a Bloomberg Desktop connection. Then, request the constituent weights of an index using a date override. 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;
Return the constituent weights for the Dow Jones Index as of January 1,
2010, using a date override with the required date format
YYYYMMDD
.
d = getdata(c,'DJX Index','INDX_MWEIGHT','END_DT','20100101')
d = INDX_MWEIGHT: {{30x2 cell}}
getdata
returns a structure d
with a
cell array where the first column is the index and the second column is the
constituent weight.
Display the constituent weights for each index.
d.INDX_MWEIGHT{1,1}
ans = 'AA UN' [1.1683] 'AXP UN' [2.9366] 'BA UN' [3.9229] 'BAC UN' [1.0914] ...
Close the Bloomberg connection.
close(c)
Current Data and Dates as Table with Datetime
Create a Bloomberg connection, and then request current data for specific fields. The
getdata
function returns data for dates as a
datetime
array.
Create the Bloomberg connection using the Bloomberg Desktop C++ interface.
c = bloomberg;
Return data as a table by setting the DataReturnFormat
property of the connection object. If you do not set this property, the
getdata
function returns data as a structure.
Return dates as a datetime
array by setting the
DatetimeType
property of the connection object. In
this case, the table contains dates in variables that are
datetime
arrays.
c.DataReturnFormat = 'table'; c.DatetimeType = 'datetime';
Request current data for these fields:
Last update date
Last price
Number of trades
Previous real-time trading date
s = 'IBM US Equity'; f = {'LAST_UPDATE_DT','LAST_PRICE', ... 'NUM_TRADES_RT','PREV_TRADING_DT_REALTIME'}; d = getdata(c,s,f)
d = 1×4 table LAST_UPDATE_DT LAST_PRICE NUM_TRADES_RT PREV_TRADING_DT_REALTIME ____________________ __________ _____________ ________________________ 21-Dec-2017 00:00:00 152.2 24846 20-Dec-2017 00:00:00
Display the last update date. This date is a datetime
array.
d.LAST_UPDATE_DT
ans = datetime 21-Dec-2017 00:00:00
Close the Bloomberg connection.
close(c)
Input Arguments
c
— Bloomberg connection
bloomberg
object
Bloomberg connection, specified as a bloomberg
object.
s
— Security list
character vector | string scalar | cell array of character vectors | string array
Security list, specified as a character vector or string scalar for one security or a cell array of character vectors or string array for multiple securities. You can specify the security by name or by CUSIP, and with or without the pricing source.
Data Types: char
| cell
| string
f
— Bloomberg data fields
character vector | string scalar | cell array of character vectors | string array
Bloomberg data fields, specified as a character vector, string scalar, cell array of character vectors, or string array. A character vector or string denotes one Bloomberg data field name. A cell array of character vectors or string array denotes multiple Bloomberg data field names. For details about the fields you can specify, see the Bloomberg API Developer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
Example: {'LAST_PRICE';'OPEN'}
Data Types: char
| cell
| string
o
— Bloomberg override field
[]
(default) | character vector | string scalar | cell array of character vectors | string array
Bloomberg override field, specified as a character vector, string scalar, cell array of character vectors, or string array. A character vector or string denotes one Bloomberg override field name. A cell array of character vectors or string array denotes multiple Bloomberg override field names. For details about the fields you can specify, see the Bloomberg API Developer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
Example: 'END_DT'
Data Types: char
| cell
| string
ov
— Bloomberg override field value
[]
(default) | character vector | string scalar | cell array of character vectors | string array
Bloomberg override field value, specified as a character vector, string scalar, cell array of character vectors, or string array. A character vector or string denotes one Bloomberg override field value. A cell array of character vectors or string array denotes multiple Bloomberg override field values. Use this field value to filter the Bloomberg data result set.
Example: '20100101'
Data Types: char
| cell
| string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'returnEids',true
returnEids
— Entitlement identifiers
true | false
Entitlement identifiers, specified as the comma-separated pair consisting of
'returnEids'
and a Boolean. true
adds a name
and value for the entitlement identifier (EID) date to the return data.
Data Types: logical
returnFormattedValue
— Return format
true | false
Return format, specified as the comma-separated pair consisting of
'returnFormattedValue'
and a Boolean. true
forces all data to be returned as the data type character vector.
Data Types: logical
useUTCTime
— Date time format
true | false
Date time format, specified as the comma-separated pair consisting of
'useUTCTime'
and a Boolean. true
returns date
and time values as Coordinated Universal Time (UTC) and false
defaults to the Bloomberg
TZDF <GO> settings of the requestor.
Data Types: logical
forcedDelay
— Latest reference data
true | false
Latest reference data, specified as the comma-separated pair consisting of
'forcedDelay'
and a Boolean. true
returns the
latest data up to the delay period specified by the exchange for the security.
Data Types: logical
Output Arguments
d
— Bloomberg data
structure (default) | table | timetable
Bloomberg data, returned as a structure, table, or timetable. The data type of the Bloomberg data depends on the DataReturnFormat and DatetimeType properties of the connection object. For details about the data, see the Bloomberg API Developer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
sec
— Security list
cell array of character vectors
Security list, returned as a cell array of character vectors
for the corresponding securities in s
. The contents
of sec
are identical in value and order to s
.
You can return securities with any of the following identifiers:
buid
cats
cins
common
cusip
isin
sedol1
sedol2
sicovam
svm
ticker
(default)wpk
Tips
Bloomberg V3 data supports additional name-value pair arguments. To access further information on these additional name-value pairs, see the Bloomberg API Developer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
You can check data and field availability by using the Bloomberg Excel® Add-In.
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)