Datafeed Toolbox | ![]() ![]() |
Retrieving Data
The fetch
command controls data retrieval from a data server connection. fetch
returns different information depending upon which data server is being accessed. See the version of fetch
appropriate for your data server for further information.
Example: Retrieving Bloomberg Data
This section illustrates the use of the fetch
command to retrieve data from a Bloomberg data server. Versions of the fetch
command that retrieve data from other data servers work similiarly.
Retrieving Header (Bloomberg Default) Data
A header (default) data request to Bloomberg 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
. Use the command
to load this file. The variable headerfieldnames
contains the list of header field names.
Obtaining Data. To retrieve header data from the Bloomberg connection, use fetch
with the syntax
Connect
is a Bloomberg connection object established with the bloomberg
command.
Security
is the list of securities for which data is requested.
Flag
denotes the dates for which data can be retrieved. Flag
has three possible values:
DEFAULT
fills all fields with data from the most recent date with a bid, ask, or trade.
TODAY
fills the fields with data from today only.
ENHANCED
fills the fields with data for the most recent event for each individual field. In this case, for example, the bid and ask group fields could come from different dates.
data = fetch(Connection, Security) data = fetch(Connection, Security, 'HEADER') data = fetch(Connection, Security, 'HEADER', 'DEFAULT')
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 OpenPrice: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
Not all fields are applicable to IBM US Equity
, the security about which we inquired.
Retrieving Field Data
The fetch
command with the GETDATA
argument obtains Bloomberg field data. The entire set of field data provides statistics for all possible securities but does not apply universally to any one security.
Determining Field Names. The complete list of valid field names is stored in the file @bloomberg/bbfields.mat
. Use the command
to load this file. The variable bbfieldnames
contains the list of field names. This list includes the header field names plus numerous others.
Obtaining Data. To obtain data for specific fields of a given security, use the fetch
command with the syntax
For example, use the bloomberg
command to establish a connection c1
to a Bloomberg data server.
Retrieving Time Series Data
The fetch
command with the TIMESERIES
argument returns price and volume data for a particular security on a specified date. Time series data for a given security and a specific date are returned using the syntax
Date
may be a MATLAB date string or serial date number.
To obtain time series data for the current day, you can use the alternate forms of the command
To obtain time series data for IBM using an existing connection c1
, enter the command
The result will look like this:
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, and column 4 contains the number of shares in the transaction.
Retrieving Historical Data
Use the fetch
command with the HISTORY
argument to obtain historical data for a specific security.
For a specified field of a particular security use the syntax
to obtain historical data. Data for the field is returned for the date range from FromDate
to ToDate
. See Determining Field Names for instructions on determining valid 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(connection, 'IBM US Equity', 'HISTORY',... 'LastPrice', '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 is the date represented as a MATLAB date number, and column 2 is the last price.
Finding Ticker Symbols
You can use the fetch
command with the LOOKUP
argument to find a ticker symbol when you are uncertain what the symbol might be. Use the syntax
to locate a specific ticker symbol.
The SearchString
argument is the comparison string used in the lookup operation, and Market
indicates the type of security (the market in which the security trades). The allowable values for Market
are
Comdty
(Commodities)
Corp
(Corporate Bonds)
Curncy
(Currencies)
Equity
(Equities)
Govt
(Government Bonds)
Index
(Indexes)
M-Mkt
(Money Market Securities)
Mtge
(Mortgage-backed Securities)
Muni
(Municipal Bonds)
Pfd
(Preferred Stocks)
For example, using fetch
with the connection c1
to look up the ticker symbol for New Zealand government bonds returns
returns a list of possible values:
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'
![]() | Disconnecting from a Data Server | Datafeed Toolbox Graphical User Interface | ![]() |