history
Retrieve historical data from Datastream Web Services from Refinitiv
Syntax
Description
Examples
Retrieve Historical Data for Security
Use a Datastream Web Services connection to retrieve historical data for the specified security.
Create a Datastream Web Services connection using your user name and password.
username = 'ABCDEF'; password = 'abcdef12345'; c = datastreamws(username,password)
c = datastreamws with properties: Username: 'ABCDEF' TimeOut: 100
c
is the datastreamws
connection object with the
Username
and TimeOut
properties. The
Username
property contains the specified user name. The
TimeOut
property specifies waiting for a maximum of 100 seconds to
return historical data before canceling the request.
Adjust the display format to display currency.
format bank
Retrieve historical end-of-day price data for the last year. Specify the
VOD
security. d
is a timetable that contains the
date in the first variable and the end-of-day price in the second variable.
sec = 'VOD';
d = history(c,sec);
Display the first few prices.
head(d)
ans = 8×1 timetable Time VOD ____________________ ______ 03-May-2017 00:00:00 202.95 04-May-2017 00:00:00 203.70 05-May-2017 00:00:00 204.95 08-May-2017 00:00:00 205.15 09-May-2017 00:00:00 205.15 10-May-2017 00:00:00 206.60 11-May-2017 00:00:00 206.25 12-May-2017 00:00:00 211.05
Use the end-of-day prices to make investment decisions for the VOD
security.
Return Historical Data for Specified Fields and Date
Use a Datastream Web Services connection to retrieve historical data for the specified security, fields, and date.
Create a Datastream Web Services connection using your user name and password.
c
is the datastreamws
connection object.
username = 'ABCDEF'; password = 'abcdef12345'; c = datastreamws(username,password);
Adjust the display format to display currency.
format bank
Retrieve and display historical end-of-day price data for March 29, 2018. Specify
the VOD
security and these fields:
Opening price
High price
Last closing price
d
is a timetable with the date in the first variable
and the fields in the subsequent variables.
sec = "VOD"; fields = ["PO";"PH";"P"]; date = datetime('03-29-2018','InputFormat','MM-dd-yyyy'); d = history(c,sec,fields,date)
d = 1×3 timetable Time PO PH P ____________________ ______ ______ ______ 29-Mar-2018 00:00:00 194.94 196.01 194.22
Use the end-of-day prices for each field to make investment decisions for the
VOD
security.
Return Historical Data for Date Range
Use a Datastream Web Services connection to retrieve historical data for the specified security, fields, and date range.
Create a Datastream Web Services connection using your user name and password.
c
is the datastreamws
connection object.
username = 'ABCDEF'; password = 'abcdef12345'; c = datastreamws(username,password);
Adjust the display format to display currency.
format bank
Retrieve historical end-of-day price data from April 1, 2018, through April 30,
2018. Specify the VOD
security and these fields:
Opening price
High price
Last closing price
d
is a timetable with the date in the first variable
and the fields in the subsequent variables.
sec = "VOD"; fields = ["PO";"PH";"P"]; startdate = datetime('04-01-2018','InputFormat','MM-dd-yyyy'); enddate = datetime('04-30-2018','InputFormat','MM-dd-yyyy'); d = history(c,sec,fields,startdate,enddate);
Display the first few prices.
head(d)
ans = 8×3 timetable Time PO PH P ____________________ ______ ______ ______ 02-Apr-2018 00:00:00 NaN NaN 194.22 03-Apr-2018 00:00:00 193.70 194.15 193.90 04-Apr-2018 00:00:00 196.64 198.10 197.22 05-Apr-2018 00:00:00 200.45 203.90 203.65 06-Apr-2018 00:00:00 203.15 205.15 204.00 09-Apr-2018 00:00:00 204.35 205.45 203.65 10-Apr-2018 00:00:00 204.45 205.90 205.60 11-Apr-2018 00:00:00 205.50 207.70 206.30
Use the end-of-day prices for each field to make investment decisions for the
VOD
security.
Return Historical Data Using Period
Use a Datastream Web Services connection to retrieve historical data for the specified security, fields, date range, and period.
Create a Datastream Web Services connection using your user name and password.
c
is the datastreamws
connection object.
username = 'ABCDEF'; password = 'abcdef12345'; c = datastreamws(username,password);
Adjust the display format to display currency.
format bank
Retrieve and display historical end-of-day price data from January 1, 2017, through
December 31, 2017. Specify the VOD
security and these fields:
Opening price
High price
Last closing price
Specify a quarterly period. d
is a timetable with the
date in the first variable and the fields in the subsequent variables.
sec = "VOD"; fields = ["PO";"PH";"P"]; startdate = datetime('01-01-2017','InputFormat','MM-dd-yyyy'); enddate = datetime('12-31-2017','InputFormat','MM-dd-yyyy'); period = 'Q'; d = history(c,sec,fields,startdate,enddate,period)
d = 4×3 timetable Time PO PH P ____________________ ______ ______ ______ 01-Jan-2017 00:00:00 NaN NaN 199.85 01-Apr-2017 00:00:00 209.00 209.10 206.65 01-Jul-2017 00:00:00 217.65 219.20 218.70 01-Oct-2017 00:00:00 209.35 211.60 210.50
Use the quarterly prices for each field to make investment decisions for the
VOD
security.
Input Arguments
c
— Datastream Web Services connection
datastreamws
object
Datastream Web Services connection, specified as a datastreamws
object.
sec
— Security
character vector | cell array of character vectors | string scalar | string array
Security, specified as a character vector, cell array of character vectors, string
scalar, or string array. Use a character vector or string scalar to specify one
security. Use a cell array of character vectors or string array to specify multiple
securities. For a constituent list, specify a single security in the
sec
input argument, for example,
"LFTSE100"
.
Example: "VOD"
Data Types: char
| string
| cell
fields
— Field list
character vector | cell array of character vectors | string scalar | string array
Field list, specified as a character vector, cell array of character vectors, string scalar, or string array. Use a character vector or string scalar to specify one field. Use a cell array of character vectors or string array to specify multiple fields.
Example: ["PH","PO","P"]
Data Types: char
| string
| cell
date
— Date
datetime
array | numeric scalar | string scalar | character vector
Date, specified as a datetime
array, numeric scalar, string
scalar, or character vector. Use this date to retrieve historical data for a specific
day.
Example: datetime('03-29-2018','InputFormat','MM-dd-yyyy')
Data Types: double
| char
| string
| datetime
startdate
— Start date
datetime
array | numeric scalar | string scalar | character vector
Start date of a date range, specified as a datetime
array,
numeric scalar, string scalar, or character vector. The default start date is the first
date of available historical data for the specified security
sec
.
Example: datetime('04-01-2018','InputFormat','MM-dd-yyyy')
Data Types: double
| char
| string
| datetime
enddate
— End date
datetime
array | numeric scalar | string scalar | character vector
End date of a date range, specified as a datetime
array, numeric
scalar, string scalar, or character vector. The default end date is the latest date of
available historical data for the specified security sec
.
Example: datetime('04-30-2018','InputFormat','MM-dd-yyyy')
Data Types: double
| char
| string
| datetime
period
— Period
'D'
| 'W'
| 'M'
| 'Q'
| 'Y'
Period, specified as one of these values:
'D'
— Daily'W'
— Weekly'M'
— Monthly'Q'
— Quarterly'Y'
— Yearly
You can specify the value as a character vector or string scalar. The default period
depends on the specified security sec
.
Output Arguments
d
— Historical data
timetable | table
Historical data, returned as a timetable or table. The history
function returns a timetable with data for one security. For multiple securities, the
history
function returns a timetable for the first syntax only
and a table of nested timetables for the other syntaxes. To access one of the nested
timetables, use dot notation, for example, d.VOD
.
response
— Response message
matlab.net.http.ResponseMessage
Response message, returned as a matlab.net.http.ResponseMessage
object. The
ResponseMessage
object contains an error message. To access the
error message, see Access Datastream Web Services Error Messages.
Version History
Introduced in R2018b
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)