Data Feed
Data Feed
Toolbox
For Use with MATLAB ®
Computation
Visualization
Programming
User’s Guide
Version 1.2
How to Contact The MathWorks:
508-647-7000 Phone
508-647-7001 Fax
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP server
comp.soft-sys.matlab Newsgroup
Preface
Tutorial
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
i
Reference
2
Bloomberg Function Summary . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
bloomberg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
fetch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
isconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Directory Structure
A
ii Contents
Preface
Using this Guide . . . . . . . . . . . . . . . . . . . ii
Organization of the Document . . . . . . . . . . . . . . ii
Typographical Conventions . . . . . . . . . . . . . . . ii
Related Products . . . . . . . . . . . . . . . . . . . iv
Chapter Description
Typographical Conventions
We use some or all of these conventions in our manuals.
-2
Using this Guide
Menu names, menu items, and Boldface with an initial Choose the File menu.
controls capital letter
-3
Preface
Note The toolboxes listed below all include functions that extend MATLAB’s
capabilities.
Table 0-1:
Product Description
Financial Time Series Tool for analyzing time series data in the
Toolbox financial markets
-4
R12 Related Products
Table 0-1:
Product Description
Additional Software
If you want to use the Datafeed Toolbox to retrieve data from Bloomberg or
Interactive Data Corporation (IDC) data servers, you need to install client
software available from each of these companies. Contact your sales
representative for information. Information about the services offered by these
companies is available on the Web at http://www.bloomberg.com and
http://www.intdata.com.
-5
Preface
-6
1
Tutorial
Introduction . . . . . . . . . . . . . . . . . . . . 1-2
Introduction
This document describes the Datafeed Toolbox for MATLAB. The Datafeed
Toolbox effectively turns your MATLAB workstation into a financial data
acquisition terminal. Using the Datafeed Toolbox, you can download a wide
variety of security data from financial data servers into your MATLAB
workspace. Then, you can pass this data to MATLAB or to another toolbox,
such as the Financial Time Series Toolbox, for further analysis.
1-2
Communicating with a Financial Data Server
• Bloomberg (http://www.bloomberg.com)
• Interactive Data Corporation (IDC) (http://www.idc.com)
• Yahoo (http://www.yahoo.com)
Bloomberg and IDC both require that you install proprietary software on your
PC. To connect to Yahoo, you need to have access to the Internet and to install
a Web browser. The most commonly used browsers, Microsoft Internet
Explorer (http://www.microsoft.com) and Netscape Communicator
(http://www.netscape.com) are available for free download.
Communication Management
For each of the supported financial data servers, the Datafeed Toolbox uses
four commands to manage communication:
An additional function, fetch, obtains the desired data from the data server
and transfers it to your PC.
1-3
1 Tutorial
c =
connection: 84554360
ipaddress: ’123.456.54.123’
port: 8194
The connection field within the object c contains the Bloomberg connection
handle that will be used in processing future data requests.
If you want to accept the default port number and IP address provided when
your Bloomberg software was installed, enter
c = bloomberg
with no arguments.
returns the list of all valid connection properties and their values associated
with the connection object c.
1-4
Communicating with a Financial Data Server
p =
connection: 84554360
ipaddress: ’123.456.54.123’
port: 8194
socket: 248
version: 1.8000
The get command can return specific properties of a connection object. For
example, to obtain the port number and Bloomberg version for the connection
object c, use the command
p = get(c,{’Port’;’Version’})
which returns
p =
port: 8194
version: 1.8000
When returning a single property, for example, the connection handle, the
command
p = get(c,’Connection’)
returns
p =
84554360
You must have previously created the connection object with one of the
connection commands.
1-5
1 Tutorial
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.
Determining Header Fields. The list of valid header fields is stored in the file
@bloomberg/bbfields.mat. Use the command
load @bloomberg/bbfields
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
data = fetch(Connect, Security, ’HEADER’, Flag)
where:
- DEFAULT fills all fields with data from the most recent date with a bid, ask,
or trade.
1-6
Retrieving Data
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
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
1-7
1 Tutorial
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.
Determining Field Names. The complete list of valid field names is stored in the
file @bloomberg/bbfields.mat. Use the command
load @bloomberg/bbfields
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
d = fetch(Connect, Security, ’GETDATA’, Fields)
1-8
Retrieving Data
Then
d = fetch(c1,’IBM US Equity’,’GETDATA’, {’OpenPrice’;’LastPrice’})
returns
d =
OpenPrice: 126.2500
LastPrice: 125.1250
To obtain time series data for the current day, you can use the alternate forms
of the command
data = fetch(Connection, Security, ’TIMESERIES’, now)
or
data = fetch(Connection, Security, ’TICKS’).
To obtain time series data for IBM using an existing connection c1, enter the
command
data = fetch(c1, ’IBM US Equity’, ’TIMESERIES’, ’11/16/99’)
1-9
1 Tutorial
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.
to obtain historical data. Data for the field is returned for the date range from
FromDate to ToDate. See “Determining Field Names” on page 1-8 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
1-10
Retrieving Data
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
• 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
1-11
1 Tutorial
1-12
Datafeed Toolbox Graphical User Interface
For additional information about the Securities Lookup dialog box, see:
• “Securities Lookup Dialog Box (Bloomberg only)” on page 1-17
1-13
1 Tutorial
alternatively, just click on the Connect button and accept the default values
provided when the Bloomberg software was installed on your machine.
After connection
is made, click Click to establish
Data tab to begin connection.
data retrieval.
Enter IP address of
data server or use
default. (Bloomberg
only)
Click to close
highlighted
connection.
1 (Bloomberg only) Enter the port number on the data server in the Port
Number box (or use default).
2 (Bloomberg only) Enter the IP address of the data server in the IP Address
box (or use default).
1-14
Datafeed Toolbox Graphical User Interface
4 When the Connected message appears in the Status box, click on the Data
tab to begin the process of retrieving data from the data server. (For
information on the Data tab, see “Data Retrieval” on page 1-16.
1-15
1 Tutorial
Data Retrieval
The Data tab manages the retrieval of data from the data server.
Security fields.
Click to
retrieve
data.
Variable in MATLAB
workspace.
1-16
Datafeed Toolbox Graphical User Interface
2 Indicate the type of data you are seeking in the Data Selection panel.
3 Indicate whether you want the default or full set of data in the Fields panel.
4 Click the Get Data button to retrieve data from the data server.
Bloomberg Users If you do not know the symbol for a security, you can use
the Lookup button to find the name of the security. (See “Securities Lookup
Dialog Box (Bloomberg only)” on page 1-17.)
1-17
1 Tutorial
1-18
2
Reference
Bloomberg Function Summary . . . . . . . . . . . 2-2
2-2
Bloomberg Function Summary
This chapter provides detailed descriptions of the Bloomberg functions in the
Datafeed Toolbox.
Table 2-1: Datafeed Toolbox Functions
Function Purpose
2-3
bloomberg
Purpose 2bloomberg
Connect to Bloomberg
Example c = bloomberg(8194,’111.222.33.444’)
makes a connection to the Bloomberg server on port 8194 of the machine with
internet address 111.222.33.444.
2-4
close
Purpose 2close
Close Bloomberg connection
Syntax close(Connect)
Example c = bloomberg(8194,’111.222.33.444’)
2-5
fetch
Purpose 2fetch
Request data from Bloomberg
2-6
fetch
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)
Description For a given security, fetch returns header (default), field, time series, and
historical data via the Bloomberg connection
data = fetch(Connect, ’Security’) fills the header fields with data from
the most recent date with a bid, ask, or trade.
• If Flag is DEFAULT, fetch fills the header fields with data from the most
recent date with a bid, ask, or trade. (This is the equivalent of
data = fetch(Connect, Security)).
• If Flag is TODAY, fetch returns the header field data with data from today
only.
• If Flag is ENHANCED, fetch returns the header field data for the most recent
date of each individual field. In this case, for example, the bid and ask group
fields could come from different dates.
2-7
fetch
2-8
get
Purpose 2get
Get Bloomberg connection properties
Connection
IPAddress
Port
Socket
Version
Example c = bloomberg(8194,’111.222.33.444’)
returns
p =
port: 8194
ipaddress: 111.222.33.444
2-9
isconnection
Purpose 2isconnection
True if valid Bloomberg connection
Syntax x = isconnection(Connect)
2-10
IDC Function Summary
Function Purpose
2-11
close
Purpose 2close
Close IDC connection
Syntax close(Connect)
Arguments Connect IDC connection object created with the idc command.
Example c = idc
2-12
fetch
Purpose 2fetch
Request data from IDC
Arguments Connect IDC connection object created with the idc command.
Security A MATLAB string containing the name of a security in a
format recognizable by the IDC server.
Fields A MATLAB string or cell array of strings indicating
specific fields for which data is to be provided. Valid field
names are in the file @idc/idcfields.mat. The variable
bbfieldnames contains the list of field names.
FromDate Beginning date for historical data.
ToDate End date for historical data.
Period Period within date range.
String Search string.
Type Lookup type. Possible values are:
F (Fields)
S (Securities)
Market Market to search.
NumRecords Number of record to fetch.
StartRecord Starting record for fetch.
2-13
fetch
Examples d = fetch(c,’ford’,’lookup’,’s’,’equity’,4,1)
returns the first four securities containing the string ’ford’ starting with the
first record.
2-14
get
Purpose 2get
Get IDC connection properties
Arguments Connect IDC connection object created with the idc command.
PropertyName (optional) A MATLAB string or cell array of strings
containing property names. Property names are:
Connected
Connection
Queued
Example
2-15
idc
Purpose 2idc
Connect to IDC
Description Connect = idc connects to the Interactive Data Corporation data server.
Connect is a connection handle used by other functions to obtain data.
Example c = idc
2-16
isconnection
Purpose 2isconnection
True if valid IDC connection
Syntax x = isconnection(Connect)
Arguments Connect IDC connection object created with the idc command.
2-17
Yahoo Function Summary
This chapter provides detailed descriptions of the Yahoo functions in the
Datafeed Toolbox.
Table 2-3: Datafeed Toolbox Yahoo Functions
Function Purpose
2-18
close
Purpose 2close
Close Yahoo connection
Syntax close(Connect)
2-19
fetch
Purpose 2fetch
Request data from Yahoo
Symbol
Last
Date
Time
Change
Open
High
Low
Volume
Date Date string or serial date number indicating date for the
requested data. If today’s date is entered, yesterday’s
data is returned.
FromDate Beginning date for historical data.
2-20
fetch
Description data = fetch(Connect, ’Security’) returns data for all fields from Yahoo’s
web site for the indicated securities.
Examples Obtain the closing price for Coca Cola on April 6, 2000.
c = yahoo;
ClosePrice =
730582.00 45.75
2-21
fetch
2-22
get
Purpose 2 get
Get Yahoo connection properties
c =
url: ’http://quote.yahoo.com’
Now use the get command to retrieve the connection property value.
get(c, ’url’)
ans =
url: 'http://quote.yahoo.com'
2-23
isconnection
Purpose 2isconnection
True if valid Yahoo connection
Syntax x = isconnection(Connect)
2-24
yahoo
Purpose 2yahoo
Connect to Yahoo
Example Use the yahoo command to establish a connection to the Yahoo data server.
Connect = yahoo
Connect =
url: ’http://quote.yahoo.com’
2-25
yahoo
2-26
A
Directory Structure
A Directory Structure
File Purpose
File Purpose
A-2
Table A-3: <matlab>/datafeed/datafeed/@yahoo
File Purpose
File Purpose
A-3
A Directory Structure
A-4
Index
B
Bloomberg field data 1-8
connection handle 1-4 field names 1-8
connection object 1-3 Flag values 1-6
bloomberg 1-3, 2-4
G
C get 1-4, 1-5
close 1-5 Bloomberg 2-9
Bloomberg 2-5 IDC 2-15
IDC 2-12 yahoot 2-23
yahoo 2-19 GETDATA argument 1-8
connecting 1-3 graphical user interface 1-13
connection handle 1-4
connection object 1-3
Connection tab 1-13 H
HEADER argument 1-6
header data 1-6
D header fields 1-6
data historical data 1-10
default 1-6 HISTORY argument 1-10
field 1-8
header 1-6
historical 1-10 I
time series 1-9 idc 2-16
Data tab 1-16 IP address 1-3
Datafeed dialog box 1-13 isconnection 1-4
default data 1-6 Bloomberg 2-10
dftool 1-13 IDC 2-17
disconnecting 1-5 yahoo 2-24
F L
fetch 1-6 LOOKUP argument 1-11
Bloomberg 2-6
IDC 2-13
yahoo 2-20 M
markets 1-11, 2-7
I-1
Index
P
port number 1-3
R
retrieve properties 1-4
root directory
MATLAB A-2
S
Securities Lookup dialog box 1-13, 1-17
T
ticker symbols 1-11
time series data 1-9
TIMESERIES argument 1-9
V
verification 1-4
Y
yahoo 2-25
I-2