getFredData

Breaking update in April 2024: Change output to use Matlab datetime format (datenum was made redundant by Matlab). X.Data(:,1) used to be dates, now in X.Dates; X.Data(:,2) used to be data values, now in X.Data. All inputs unchanged, but you have option to use datetime instead of string as startdate and enddate.

You can import data directly from FRED using getFredData.m function I created. Some examples on how to use getFredData (and plotly) are here.

  • Download getFredData.m (you can either put it in your active folder, or better yet add it to the Matlab path). [Github]
  • Now just import the series you want (here M1 money for period 1960 to 2000):
    M1 = getFredData(‘M1SL’, ‘1960-01-01’, ‘2000-12-31’)
  • This will give you a structure M1, the data series itself is in M1.Data.
  • The M1 structure also contains other info, eg. M1.Title, or the dates in M1.Dates.
  • Dates are in Matlab’s datetime format.
  • More options: M1 is monthly by default, but we can ask for quarterly data (‘q’) and expressed as Percentage Change of Year Ago (‘pca’).
    M1 = getFredData(‘M1SL’, ‘1960-01-01’, ‘2000-12-31′,’pca’,’q’)
  • There are other, more advanced options in getFredData, including ALFRED historical data, either use Matlab help or read the m-file for details.
  • [Matlab has a built-in function fetch for accessing FRED, but it can’t change frequency or units. getFredData.m builds on an earlier version by Kim Ruhl]
    Note: It is possible to input start and end dates as datetime rather than strings.