fetch
Request data from Haver Analytics database
Syntax
Description
returns historical data between the dates data
= fetch(c
,variable
,startdate
,enddate
,haverParams
)startdate
and
enddate
, where haverParams
is an
optional comma-separated list of HaverView™ API flags and c
is a
haverview
connection object. For more information, see
the
HaverView API documentation on the Haver Analytics website.
Examples
Retrieve Haver Analytics Variable Data
Connect to a Haver Analytics database.
c = haver('c:\work\haver\usecon.dat');
Retrieve all historical data for the Haver Analytics variable FFED
. The descriptor for
this variable is Federal Funds [Effective] Rate (% p.a.).
variable = "FFED"; % return data for FFED data = fetch(c,variable);
Display the first three rows of data.
data(1:3,:)
ans = 715511.00 2.38 715512.00 2.50 715515.00 2.50
data
contains the numeric representation of the
date in the first column and the closing value in the second
column.
Close the Haver Analytics connection.
close(c)
Retrieve Haver Analytics Data for Specified Date Range Using DLX Direct
Create a DLX Direct connection by using the
haverdirect
function and specifying the
Haver Analytics database that you want to connect to. In this example,
replace USECON
with the name of your database.
databasename = "USECON";
c = haverdirect(databasename)
c = haverdirect with properties: DatabaseName: "USECON" DatetimeType: '' DataReturnFormat: ''
Retrieve historical data from January 1, 2005, through December 31,
2005, for the FFED
variable and display the first
three rows.
variable = "FFED"; startdate = "01/01/2005"; enddate = "12/31/2005"; data = fetch(c,variable,startdate,enddate); data(1:3,:)
ans = 732343.00 2.28 732371.00 2.50 732402.00 2.63
Retrieve Haver Analytics Quarterly Data for Specified Date Range
Connect to the Haver Analytics database.
c = haver('c:\work\haver\usecon.dat');
Retrieve the information of the Haver Analytics variable FFED
. The descriptor for
this variable is Federal Funds [Effective] Rate (% p.a.).
variable = "FFED";
x = info(c,variable);
info
returns the structure x
containing fields describing the Haver Analytics variable.
Retrieve quarterly data. When you specify a date that is outside the
date range in the variable, you might experience unexpected results.
To prevent this outcome, use the EndDate
field for
the end of the date range.
startdate = '06/01/2000'; % start of date range enddate = x.EndDate; % end of date range period = 'q'; % quarterly data data = fetch(c,variable,startdate,enddate,period)
Display the first three rows of data.
data(1:3,:)
ans = 730759.00 6.52 730851.00 6.50 730941.00 5.61
data
contains the numeric representation of the
date in the first column and the closing value in the second
column.
Close the Haver Analytics connection.
close(c)
Retrieve Haver Analytics Variable Data in Table Format with Datetime
Connect to the Haver Analytics database.
c = haver('c:\work\haver\usecon.dat');
Adjust the display format for currency.
format bank
Set the data return format to table using the
DataReturnFormat
property of the
haver
object. Also, set the date and time return
format to a datetime
array using the
DatetimeType
property.
c.DataReturnFormat = 'table'; c.DatetimeType = 'datetime';
Retrieve historical data from January 1, 2005, through December 31,
2005, for ABQ
and display the results.
ABQ
provides bankruptcy filings in the
US.
variable = "ABQ"; % return data for ABQ startdate = '01/01/2005'; % start of date range enddate = '12/31/2005'; % end of date range data = fetch(c,variable,startdate,enddate)
ans = 4×2 table Time TotalBankruptcyFilings_U_S__Units_ ____________________ __________________________________ 31-Mar-2005 00:00:00 401149.00 30-Jun-2005 00:00:00 467333.00 30-Sep-2005 00:00:00 542002.00 31-Dec-2005 00:00:00 667431.00
data
is a table with the date and time in the
first variable and the bankruptcy amount in the second variable. The
first variable is a datetime
array.
Close the Haver Analytics connection.
close(c)
Retrieve HaverView Data Using API Flags
Create a HaverView connection using a valid authentication token and
database name. In this example, replace
681b61cf-dc7d-4698-a168-74c79b0c1a04
with your
authentication token and replace USECON
with the
name of your database.
token = "681b61cf-dc7d-4698-a168-74c79b0c1a04"; databasename = "USECON"; c = haverview(token,databasename)
c = haverview with properties: DatabaseName: "USECON" TimeOut: 200.00
Retrieve time series data by specifying two HaverView API flags as name-value arguments. This example
retrieves data for the variable named AB
with flags
set for annual aggregation and percentage period.
variable = "AB"; startdate = datetime("01-Jan-2015"); enddate = datetime("01-Jan-2021"); data = fetch(c,variable,startdate,enddate,"aggregation"=10,"function"="DIFF%")
data = 7x1 timetable Time nSeriesData ___________ ___________ 01-Jan-2015 0.90 01-Jan-2016 1.02 01-Jan-2017 0.92 01-Jan-2018 0.85 01-Jan-2019 0.98 01-Jan-2020 1.02 01-Jan-2021 0.85
Retrieve HaverView Data and Return Response Message
Create a HaverView connection using a valid authentication token and
database name. In this example, replace
681b61cf-dc7d-4698-a168-74c79b0c1a04
with your
authentication token and replace USECON
with the
name of your database.
token = "681b61cf-dc7d-4698-a168-74c79b0c1a04"; databasename = "USECON"; c = haverview(token,databasename)
c = haverview with properties: DatabaseName: "USECON" TimeOut: 200.00
Retrieve time series data and response message by specifying two
Haver API flags as name-value arguments. This example retrieves data
for a variable named "AB"
with flags set for annual
aggregation and percentage period.
variable = "AB"; startdate = datetime("01-Jan-2015"); enddate = datetime("01-Jan-2021"); [data.response] = fetch(c,variable,startdate,enddate,"aggregation"=10,"function"="DIFF%")
data = 7x1 timetable Time nSeriesData ___________ ___________ 01-Jan-2015 0.90 01-Jan-2016 1.02 01-Jan-2017 0.92 01-Jan-2018 0.85 01-Jan-2019 0.98 01-Jan-2020 1.02 01-Jan-2021 0.85 response = ResponseMessage with properties: StatusLine: 'HTTP/1.1 200 OK' StatusCode: OK Header: [1x12 matlab.net.http.HeaderField] Body: [1x1 matlab.net.http.MessageBody] Completed: 0
Input Arguments
c
— Haver Analytics connection
haver
object | haverdirect
object | haverview
object
Haver Analytics connection, specified as the following connection objects:
haver
,haverdirect
, orhaverview
in the first two syntaxeshaver
orhaverdirect
in the third syntaxhaverview
in the fourth and fifth syntaxes
variable
— Haver Analytics variable
character vector | string scalar | cell array of character vectors | string array
Haver Analytics variable, specified as a character vector, string scalar, cell array of character vectors, or string array to denote which historical data to retrieve. For information about the variables that you can use, see the API documentation on the Haver Analytics website.
Example: "FFED"
Data Types: char
| string
| cell
startdate
— Start date
character vector | string scalar | MATLAB® date number | datetime
Start date of the date range to retrieve data, specified as a
character vector, string scalar, or MATLAB date number for haver
and
haverdirect
input objects. You can also
specify the start date as a datetime
for
haverview
input objects.
Data Types: double
| char
| string
| datetime
enddate
— End date
character vector | string scalar | MATLAB date number | datetime
End date of the date range to retrieve data, specified as a character
vector, string scalar, or MATLAB date number for haver
and
haverdirect
input objects. You can also
specify the end date as a datetime
for
haverview
input objects.
Data Types: double
| char
| string
| datetime
period
— Period
'd'
| 'w'
| 'm'
| 'q'
| 'a'
Period, specified as one of these values that denotes the time period for the historical data:
'd'
for daily values'w'
for weekly values'm'
for monthly values'q'
for quarterly values'a'
for annual values
haverParams
— HaverView API arguments
HaverView API argument list
HaverView API arguments, specified as a comma-separated list. For more information, see the HaverView API documentation on the Haver Analytics website.
Output Arguments
data
— Historical data
matrix
Historical data, returned as a matrix with the numeric representation of the date in the first column and the value in the second column.
response
— HTTP request response
ResponseMessage
object
HTTP request response, returned as a
ResponseMessage
object. For details, see
matlab.net.http.ResponseMessage
.
Version History
Introduced in R2007a
See Also
close
| get
| isconnection
| haver
| haverdirect
| info
| nextinfo
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)