history

Retrieve Quandl historical data

Description

example

d = history(c,s) retrieves Quandl® historical data using a Quandl connection and a security.

example

d = history(c,s,startdate,enddate) also specifies a date range for the historical data to retrieve.

example

d = history(c,s,startdate,enddate,periodicity) also specifies the periodicity for the historical data to retrieve.

example

d = history(c,s,startdate,enddate,periodicity,QueryName1,QueryValue1,...,QueryNameN,QueryValueN) also specifies web service query parameters as one or more pairs of name-value arguments.

Examples

collapse all

Use a Quandl connection to retrieve historical data for a security within the available date range for the specified security.

Create a Quandl connection using a Quandl API key.

apikey = 'abcdef12345';
c = quandl(apikey)
c = 

  quandl with properties:

    TimeOut: 100

c is the quandl connection object with the TimeOut property. 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 data for the CHRIS/ASX_WM2 security within the available date range for the security. This security provides historical future prices for Eastern Australian Wheat Futures, Continuous Contract #2. The specified security indicates the default periodicity (in this case, daily). d is a timetable with the time in the first variable and the previous settlement price in the second variable.

s = 'CHRIS/ASX_WM2';
d = history(c,s);

Display the first few rows of historical prices.

head(d)
ans =

  8×1 timetable

       Time        PreviousSettlement
    ___________    __________________

    28-Apr-2018          294.00      
    27-Apr-2018          294.00      
    26-Apr-2018          294.00      
    25-Apr-2018          287.00      
    24-Apr-2018          287.00      
    23-Apr-2018          289.50      
    21-Apr-2018          291.00      
    20-Apr-2018          291.00      

Decide to buy or sell this contract based on the historical prices.

Use a Quandl connection to retrieve historical data for a security within a specified date range.

Create a Quandl connection using a Quandl API key.

apikey = 'abcdef12345';
c = quandl(apikey);

Adjust the display format to display currency.

format bank

Retrieve historical data for the CHRIS/ASX_WM2 security from March 1, 2018 through March 31, 2018. This security provides historical future prices for Eastern Australian Wheat Futures, Continuous Contract #2. The specified security indicates the default periodicity (in this case, daily). d is a timetable with the time in the first variable and the previous settlement price in the second variable.

s = 'CHRIS/ASX_WM2';
startdate = datetime('03-01-2018','InputFormat','MM-dd-yyyy');
enddate = datetime('03-31-2018','InputFormat','MM-dd-yyyy');
d = history(c,s,startdate,enddate);

Display the first few rows of historical prices.

head(d)
ans =

  8×1 timetable

       Time        PreviousSettlement
    ___________    __________________

    31-Mar-2018          277.50      
    30-Mar-2018          277.50      
    29-Mar-2018          277.50      
    28-Mar-2018          278.50      
    27-Mar-2018          278.00      
    26-Mar-2018          278.50      
    24-Mar-2018          280.00      
    23-Mar-2018          280.00      

Decide to buy or sell this contract based on the historical prices.

Use a Quandl connection to retrieve historical data for a security within the specified date range and using the specified periodicity.

Create a Quandl connection using a Quandl API key.

apikey = 'abcdef12345';
c = quandl(apikey);

Adjust the display format to display currency.

format bank

Retrieve historical data for the CHRIS/ASX_WM2 security from March 1, 2018 through March 31, 2018. This security provides historical future prices for Eastern Australian Wheat Futures, Continuous Contract #2. Use a weekly period for the returned data. d is a timetable with the time in the first variable and the previous settlement price in the second variable.

s = 'CHRIS/ASX_WM2';
startdate = datetime('03-01-2018','InputFormat','MM-dd-yyyy');
enddate = datetime('03-31-2018','InputFormat','MM-dd-yyyy');
periodicity = 'weekly';
d = history(c,s,startdate,enddate,periodicity);

Display the historical prices.

d
d =

  5×1 timetable

       Time        PreviousSettlement
    ___________    __________________

    01-Apr-2018          277.50      
    25-Mar-2018          280.00      
    18-Mar-2018          281.50      
    11-Mar-2018          279.50      
    04-Mar-2018          283.00      

Decide to buy or sell this contract based on the historical prices.

Use a Quandl connection to retrieve historical data for a security within a specified date range. Return data with a weekly periodicity and price transformation.

Create a Quandl connection using a Quandl API key.

apikey = 'abcdef12345';
c = quandl(apikey);

Adjust the display format to display currency.

format bank

Retrieve historical data for the CHRIS/ASX_WM2 security from March 1, 2018 through March 31, 2018. This security provides historical future prices for Eastern Australian Wheat Futures, Continuous Contract #2. Use a weekly period for the returned data. Transform the historical price data by calculating the row-on-row percent change. Specify the calculation using the name-value argument "transform" with the "rdiff" value. d is a timetable with the time in the first variable and the percent change of the previous settlement price in the second variable.

s = 'CHRIS/ASX_WM2';
startdate = datetime('03-01-2018','InputFormat','MM-dd-yyyy');
enddate = datetime('03-31-2018','InputFormat','MM-dd-yyyy');
periodicity = 'weekly';
d = history(c,s,startdate,enddate,periodicity, ...
    "transform","rdiff");

Display the percent changes.

d
d =

  4×1 timetable

       Time        PreviousSettlement
    ___________    __________________

    01-Apr-2018          -0.01       
    25-Mar-2018          -0.01       
    18-Mar-2018           0.01       
    11-Mar-2018          -0.01       

Decide to buy or sell this contract based on the percent changes in the historical prices.

Input Arguments

collapse all

Quandl connection, specified as a quandl object.

Security, specified as a character vector or string scalar.

Example: "CHRIS/ASX_WM2"

Data Types: char | string

Start date of the date range, specified as a datetime array, numeric scalar, string scalar, or character vector. By default, the start date is the date of the first available historical data for the specified security s.

If you specify the enddate input argument, then you must specify the startdate input argument.

Example: datetime('03-01-2018','InputFormat','MM-dd-yyyy')

Example: 737121

Data Types: double | char | string | datetime

End date of the date range, specified as a datetime array, numeric scalar, string scalar, or character vector. By default, the end date is the date of the last available historical data for the specified security s.

If you specify the startdate input argument, then you must specify the enddate input argument.

Example: datetime('03-31-2018','InputFormat','MM-dd-yyyy')

Example: 737181

Data Types: double | char | string | datetime

Periodicity, specified as one these values:

  • 'daily'

  • 'weekly'

  • 'monthly'

  • 'quarterly'

  • 'annual'

You can specify these values as a character vector or string scalar.

The default periodicity depends on the specified security s.

Web service query parameters, specified as one or more pairs of name-value arguments. A QueryName argument is a character vector or string scalar that specifies the name of a query parameter. A QueryValue argument is a character vector or string scalar that specifies the value of the query parameter.

This table describes the valid names and values for the name-value arguments. Specify the name using a character vector or string scalar.

NameDescriptionValueDefault ValueValue Data Type
"limit"

Number of rows to return

nReturn all rows of datacharacter vector, string scalar, or numeric scalar
"column_index"

Column index of Quandl historical data to return

nReturn all columns of Quandl historical datacharacter vector, string scalar, or numeric scalar
"order"

Sort order for the dates in the returned data

"asc" or "desc"

"desc"character vector or string scalar
"transform"

Applied calculation on the returned data

See the following table for the values and their descriptions"none"character vector or string scalar

This table describes the values for the "transform" name-value argument.

ValueDescription
"none"

No calculation on the returned data

"diff"

Row-on-row change

"rdiff"

Row-on-row percent change

"rdiff_from"

Latest value as percent increment

"cumul"

Cumulative sum

"normalize"

Scale series starts at 100

Example: "limit",10 limits the returned data to 10 rows.

Example: "transform","diff" calculates the row-on-row change for the returned historical data.

Data Types: char | string

Output Arguments

collapse all

Quandl historical data, returned as a timetable or a matlab.net.http.ResponseMessage object.

If the historical data request is successful, then the history function returns data as a timetable. The timetable contains the time in the first variable. The subsequent variables in the timetable correspond to the returned data. The variables of the returned data depend on the specified security s.

If the historical data request is unsuccessful, the history function returns the error message in the matlab.net.http.ResponseMessage object. To access the error message, see Access Quandl Error Messages.

Introduced in R2018b