Main Content

history

Retrieve historical data from Datastream Web Services from Refinitiv

Description

d = history(c,sec) retrieves historical Datastream™ Web Services data for a specified security for the last year.

example

d = history(c,sec,fields,date) retrieves historical data for specified fields and a specific date.

example

d = history(c,sec,fields,startdate,enddate) retrieves historical data for a date range.

example

d = history(c,sec,fields,startdate,enddate,period) retrieves historical data using a period.

example

[d,response] = history(___) returns a ResponseMessage object that contains an error message. To access the error message, see Access Datastream Web Services Error Messages.

Examples

collapse all

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.

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.

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.

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

collapse all

Datastream Web Services connection, specified as a datastreamws object.

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

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, 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

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

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, 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

collapse all

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 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

Go to top of page