Main Content

haver

Connect to local Haver Analytics database

Description

The haver function creates a haver object. The haver object represents a Haver Analytics® database connection.

After you create a haver object, you can use the object functions to retrieve all historical data for a variable. You can also retrieve historical data in a date range.

Creation

Description

c = haver(databasename) establishes a connection to a Haver Analytics database and sets the DatabaseName property.

Requirement:

You need both read and write permissions on the database file to establish a connection. Otherwise, this error message appears at the command line: Unable to open specified database file.

example

Input Arguments

expand all

Database name, specified as a character vector or string scalar. The database name is the full path to the Haver Analytics database file on the local machine.

Example: 'C:\haver\haverd.dat'

Data Types: char | string

Properties

expand all

This property is read-only.

Database name, specified as a character vector. The database name is the full path to the Haver Analytics database file on the local machine.

The haver function sets this property using the databasename input argument.

Example: 'C:\haver\haverd.dat'

Data Types: char

Data return format, specified as one of these values, which determine the data type of the returned data.

ValueData Type of Returned Data

'' (default)

structure or numeric array
'table'table
'timetable'timetable

You can specify these values using a character vector or string (for example, "table").

When you create a haver object, the haver function leaves this property unset. Set this property value manually at the command line or in a script using dot notation, for example:

c.DataReturnFormat = 'table';

The default data type value depends on the function. The following table describes the default value for each corresponding supported function.

Supported FunctionDefault Data Type
fetch

numeric array

info

structure

nextinfo

structure

Date and time data type, specified as one of these values.

ValueData Type of Returned Data
'' (default)MATLAB® date numbers or character vectors
'datetime'datetime array

You can specify these values using a character vector or string (for example, "datetime").

When you create a haver object, the haver function leaves this property unset. Set this property value manually at the command line or in a script using dot notation, for example:

c.DatetimeType = 'datetime';

The default data type value depends on the function. The following table describes the default value for each corresponding supported function.

Supported FunctionDefault Data Type
fetch

numeric scalar

info

character vector

nextinfo

character vector

Note

If you leave the DataReturnFormat property set to the default value and you retrieve data using the fetch function, the date and time data type remains a numeric scalar. To retrieve date and time values as a datetime array, set the DataReturnFormat property to 'timetable', or set the DataReturnFormat property to 'table' and the DatetimeType property to 'datetime'.

Object Functions

closeClose Haver Analytics database
fetchRequest data from Haver Analytics database
getRetrieve properties from Haver Analytics connection objects
infoRetrieve information about Haver Analytics variables
isconnectionDetermine if connections to Haver Analytics data servers are valid
nextinfoRetrieve information about next Haver Analytics variable

Examples

collapse all

Create a Haver Analytics database connection. Then, retrieve historical data for a specified date range.

Create the Haver Analytics database connection using the local Haver Analytics database file. c is a haver object.

databasename = 'C:\haver\usecon.dat';
c = haver(databasename)
c = 

  haver with properties:

        DatabaseName: 'C:\haver\usecon.dat'
        DatetimeType: ''
    DataReturnFormat: ''

Adjust the display format for currency.

format bank

Retrieve historical data from January 1, 2005, through December 31, 2005, for 'FFED'.

variable = 'FFED'; % return data for FFED
startdate = '01/01/2005'; % start of date range
enddate = '12/31/2005';   % end of date range

d = fetch(c,variable,startdate,enddate);

Display the first three rows of data. d contains the numeric representation of the date in the first column and the closing value in the second column.

d(1:3,:)
ans =

     732315.00          2.25
     732316.00          2.25
     732317.00          2.25

Close the Haver Analytics connection.

close(c)

Version History

Introduced in R2007a