Main Content

fred

Connect to FRED data servers

Description

The fred function creates a fred object. The fred object represents a FRED® connection.

After you create a fred object, you can use the object functions to retrieve economic data for a FRED series. You can also retrieve data for a specific date or date range.

Creation

Description

example

c = fred returns a FRED connection to the FRED data server using the default URL 'https://fred.stlouisfed.org/'.

example

c = fred(url) returns a FRED connection using the specified URL.

Input Arguments

expand all

URL of the FRED data server, specified as a character vector or string scalar.

Example: 'https://fred.stlouisfed.org/'

Data Types: char | string

Properties

expand all

URL of the FRED data server, specified as a character vector.

The fred function sets this property using the url input argument.

Example: 'https://fred.stlouisfed.org/'

Data Types: char

IP address of the proxy server, specified as a character vector.

Data Types: char

Port number of the proxy server, specified as a numeric scalar.

Data Types: double

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
'table'table
'timetable'timetable

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

When you create a fred object, the fred 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';

After setting the DataReturnFormat property, use the fetch function to retrieve data.

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

ValueData Type of Returned Data
[] (default)MATLAB® date numbers
'datetime'datetime array

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

When you create a fred object, the fred 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';

After setting the DatetimeType property, use the fetch function to retrieve data.

Object Functions

fetchRequest data from FRED data servers
isconnectionDetermine if connections to FRED data servers are valid
closeClose connections to FRED data servers

Examples

collapse all

Connect to the FRED® data server, and then retrieve historical data for a series.

Connect to the FRED data server.

c = fred

c is a FRED connection with these properties:

  • URL for the FRED data server

  • IP address of the proxy server

  • Port number of the proxy server

  • Date and time data type for returned data

  • Data return format for returned data

Retrieve the ip property of the FRED connection c.

c.IP

Retrieve the port property of the FRED connection c.

c.Port

Adjust the display data format for currency.

format bank

Retrieve all historical data for the US / Euro Foreign Exchange Rate series. d contains the series description.

series = 'DEXUSEU'; 

d = fetch(c,series);

Close the FRED connection.

close(c)

Connect to the FRED® data server using a URL, and then retrieve historical data for a series.

Connect to the FRED data server using the URL 'https://fred.stlouisfed.org/'.

url = 'https://fred.stlouisfed.org/';
c = fred(url)

c is a FRED connection with these properties:

  • URL for the FRED data server

  • IP address of the proxy server

  • Port number of the proxy server

  • Date and time data type for returned data

  • Data return format for returned data

Retrieve the ip property of the FRED connection c.

c.IP

Retrieve the port property of the FRED connection c.

c.Port

Adjust the display data format for currency.

format bank

Retrieve all historical data for the US / Euro Foreign Exchange Rate series. d contains the series description.

series = 'DEXUSEU'; 

d = fetch(c,series);

Close the FRED connection.

close(c)

Version History

Introduced in R2006b