fetch
Request data from FRED data servers
Description
Examples
Fetch All Available FRED® Data
Connect to the FRED® data server using the URL 'https://fred.stlouisfed.org/'
.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
Fetch all available daily foreign exchange rates between the US dollar and the Euro using the series 'DEXUSEU'
.
series = 'DEXUSEU';
d = fetch(c,series)
d = struct with fields: Title: ' U.S. / Euro Foreign Exchange Rate' SeriesID: ' DEXUSEU' Source: ' Board of Governors of the Federal Reserve System (US)' Release: ' H.10 Foreign Exchange Rates' SeasonalAdjustment: ' Not Seasonally Adjusted' Frequency: ' Daily' Units: ' U.S. Dollars to One Euro' DateRange: ' 1999-01-04 to 2017-02-03' LastUpdated: ' 2017-02-06 3:52 PM CST' Notes: ' Noon buying rates in New York City for cable transfers payable in foreign currencies.' Data: [4720×2 double]
d.Data
is an N-by-2 double array that contains dates in the first column and the series values in the second column.
Close the FRED® connection.
close(c)
Fetch FRED® Data for Date
Connect to the FRED® data server using the URL 'https://fred.stlouisfed.org/'
.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
Adjust the display data format for currency.
format bank
Fetch data for a day three months ago using the series 'DTB6'
.
series = 'DTB6';
date = floor(now)-90;
d = fetch(c,series,date)
d = struct with fields: Title: ' 6-Month Treasury Bill: Secondary Market Rate' SeriesID: ' DTB6' Source: ' Board of Governors of the Federal Reserve System (US)' Release: ' H.15 Selected Interest Rates' SeasonalAdjustment: ' Not Seasonally Adjusted' Frequency: ' Daily' Units: ' Percent' DateRange: ' 1958-12-09 to 2017-02-06' LastUpdated: ' 2017-02-07 3:51 PM CST' Notes: ' Discount Basis' Data: [736644.00 0.58]
d.Data
is an N-by-2 double array that contains the date in the first column and the series value in the second column.
Close the FRED® connection.
close(c)
Fetch FRED® Data for Date Range
Connect to the FRED® data server using the URL 'https://fred.stlouisfed.org/'
.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
Adjust the display data format for currency.
format bank
Retrieve historical data for the US / Euro Foreign Exchange Rate series.
series = 'DEXUSEU';
Fetch five months of data from January 1, 2007 through June 1, 2007.
startdate = '01/01/2007'; enddate = '06/01/2007'; d = fetch(c,series,startdate,enddate)
d = struct with fields: Title: ' U.S. / Euro Foreign Exchange Rate' SeriesID: ' DEXUSEU' Source: ' Board of Governors of the Federal Reserve System (US)' Release: ' H.10 Foreign Exchange Rates' SeasonalAdjustment: ' Not Seasonally Adjusted' Frequency: ' Daily' Units: ' U.S. Dollars to One Euro' DateRange: ' 1999-01-04 to 2017-02-03' LastUpdated: ' 2017-02-06 3:52 PM CST' Notes: ' Noon buying rates in New York City for cable transfers payable in foreign currencies.' Data: [110×2 double]
d.Data
is an N-by-2 double array that contains dates in the first column and the series values in the second column.
Close the FRED® connection.
close(c)
Retrieve Available FRED Data as Table
Connect to the FRED data server using the URL 'https://fred.stlouisfed.org/'
.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
Adjust the display format for currency.
format bank
Set the data return format to table using the DataReturnFormat
property of the fred
object.
c.DataReturnFormat = 'table';
Fetch all available daily foreign exchange rates between the US dollar and the Euro using the series 'DEXUSEU'
. The table d
contains one row for the series. Each variable describes a piece of information about the series.
series = 'DEXUSEU';
d = fetch(c,series)
d=1×11 table
Title SeriesID Source Release SeasonalAdjustment Frequency Units DateRange LastUpdated Notes Data
____________________________________ __________ ________________________________________________________ ______________________________ __________________________ _________ ___________________________ ___________________________ _________________________ ________________________________________________________________________________________ ______________
' U.S. / Euro Foreign Exchange Rate' ' DEXUSEU' ' Board of Governors of the Federal Reserve System (US)' ' H.10 Foreign Exchange Rates' ' Not Seasonally Adjusted' ' Daily' ' U.S. Dollars to One Euro' ' 1999-01-04 to 2018-05-04' ' 2018-05-07 3:51 PM CDT' ' Noon buying rates in New York City for cable transfers payable in foreign currencies.' [5045×2 table]
Access the data in the series from the Data
variable.
data = d.Data{1};
Display the first few foreign exchange rates. The first variable in the table is the date and the second variable is the foreign exchange rate. Also, the first variable is an array of MATLAB® date numbers.
head(data)
ans=8×2 table
Var1 Var2
_________ ____
730124.00 1.18
730125.00 1.18
730126.00 1.16
730127.00 1.17
730128.00 1.16
730131.00 1.15
730132.00 1.15
730133.00 1.17
Close the FRED connection.
close(c)
Retrieve Available FRED Data as Table with Datetime
Connect to the FRED data server using the URL 'https://fred.stlouisfed.org/'
.
url = 'https://fred.stlouisfed.org/';
c = fred(url);
Adjust the display format for currency.
format bank
Set the data return format to table using the DataReturnFormat
property of the fred
object. Also, set the date and time format to datetime
array using the DatetimeType
property.
c.DataReturnFormat = 'table'; c.DatetimeType = 'datetime';
Fetch all available daily foreign exchange rates between the US dollar and the Euro using the series 'DEXUSEU'
. The table d
contains one row for the series. Each variable describes a piece of information about the series.
series = 'DEXUSEU';
d = fetch(c,series)
d=1×11 table
Title SeriesID Source Release SeasonalAdjustment Frequency Units DateRange LastUpdated Notes Data
____________________________________ __________ ________________________________________________________ ______________________________ __________________________ _________ ___________________________ ___________________________ _________________________ ________________________________________________________________________________________ ______________
' U.S. / Euro Foreign Exchange Rate' ' DEXUSEU' ' Board of Governors of the Federal Reserve System (US)' ' H.10 Foreign Exchange Rates' ' Not Seasonally Adjusted' ' Daily' ' U.S. Dollars to One Euro' ' 1999-01-04 to 2018-06-22' ' 2018-06-25 3:51 PM CDT' ' Noon buying rates in New York City for cable transfers payable in foreign currencies.' [5080×2 table]
Access the data in the series from the Data
variable.
data = d.Data{1};
Display the first few foreign exchange rates. The first variable in the table is the date and the second variable is the foreign exchange rate. Also, the first variable is a datetime
array.
head(data)
ans=8×2 table
Var1 Var2
____________________ ____
04-Jan-1999 00:00:00 1.18
05-Jan-1999 00:00:00 1.18
06-Jan-1999 00:00:00 1.16
07-Jan-1999 00:00:00 1.17
08-Jan-1999 00:00:00 1.16
11-Jan-1999 00:00:00 1.15
12-Jan-1999 00:00:00 1.15
13-Jan-1999 00:00:00 1.17
Close the FRED connection.
close(c)
Input Arguments
c
— FRED connection
connection object
FRED connection, specified as a connection object created using
fred
.
series
— FRED series
character vector | string scalar
FRED series, specified as a character vector or string scalar.
Example: 'DEXUSEU'
Data Types: char
| string
date
— Date
datetime
| matrix | character vector | string scalar
Date, specified as a datetime
value, matrix, character
vector, or string scalar. For details about the data types, see datetime
.
Data Types: double
| char
| cell
| datetime
| string
startdate
— Start date
datetime
| matrix | character vector | string scalar
Start date in a date range, specified as a datetime
value, matrix, character vector, or string scalar. For details about the
data types, see datetime
.
Data Types: double
| char
| cell
| datetime
| string
enddate
— End date
datetime
| matrix | character vector | string scalar
End date in a date range, specified as a datetime
value, matrix, character vector, or string scalar. For details about the
data types, see datetime
.
Data Types: double
| char
| cell
| datetime
| string
Output Arguments
d
— FRED data
structure
FRED data, returned as a structure. For details about FRED data, see https://fred.stlouisfed.org/.
Version History
Introduced in R2006b
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)