Main Content

Retrieve Historical Data Using FRED

This example shows how to connect to FRED®, retrieve historical foreign exchange rates, and determine when the highest rate occurred.

Create FRED Connection

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

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

Retrieve Historical Foreign Exchange Rates

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)
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 2018-06-15'
           LastUpdated: ' 2018-06-18 3:51 PM CDT'
                 Notes: ' Noon buying rates in New York City for cable transfers payable in foreign currencies.'
                  Data: [5075×2 double]

Display the numeric representation of the date and the foreign exchange rate for the first three rows of data.

d.Data(1:3,:)
ans = 3×2

     730124.00          1.18
     730125.00          1.18
     730126.00          1.16

Retrieve Historical Foreign Exchange Rates Using Date Range

Retrieve historical data from January 1 through June 1, 2012, for the US / Euro Foreign Exchange Rate series.

startdate = '01/01/2012'; % beginning of date range for historical data
enddate = '06/01/2012'; % ending of date range for historical data

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 2018-06-15'
           LastUpdated: ' 2018-06-18 3:51 PM CDT'
                 Notes: ' Noon buying rates in New York City for cable transfers payable in foreign currencies.'
                  Data: [110×2 double]

Determine Highest Foreign Exchange Rate in Date Range

Determine the highest foreign exchange rate maxforex in the date range. forex contains all the exchange rates in the data.

forex = d.Data(:,2);
maxforex = max(forex)
maxforex = 
          1.35

Determine when the highest foreign exchange rate occurred. To find the index idx for the highest foreign exchange rate, the function find uses the tolerance value. Retrieve the serial date number by indexing into the array of data using idx. Convert the serial date number to a character vector using the datestr function.

value = abs(forex-maxforex);
idx = find(value<0.001,1);
date = d.Data(idx,1);
datestr(date)
ans = 
'24-Feb-2012'

Close FRED Connection

close(c)

See Also

| | | |