The FRED Connector in Datafeed Toolbox
If you work with macro, markets, or policy analysis, chances are you touch FRED®—the Federal Reserve Economic Data service. The Datafeed Toolbox gives you a first-class, native connector to FRED that makes pulling series, slicing by date ranges, and fitting the data into your analytics pipeline straightforward. Below is a practical tour of the connector, how to shape its outputs for modern MATLAB workflows (tables/timetables + datetime), and how it compares to the FRED® REST helper on File Exchange.
What the FRED connector is (and where to find it)
The FRED connector is an object interface exposed by the fred function in Datafeed Toolbox. You create a connection, then call fetch to retrieve one or more series, optionally for a specific date range. The connector keeps things “MATLAB native,” returning a compact series descriptor plus an array/table/timetable for the observations.
At a glance (core API):
- Create a connection (default FRED endpoint):
c = fred; % default URL: https://fred.stlouisfed.org/
- Or specify a URL explicitly:
c = fred("https://fred.stlouisfed.org/");
- Retrieve data:
d = fetch(c, "DEXUSEU"); % full history d = fetch(c, "DTB6", floor(now)-90); % range of data from start date to most recent date d = fetch(c, "DEXUSEU", "01/01/2025", "08/31/2025"); % range
Return types: table/timetable and datetime
Out of the box, fetch can return a structure whose Data field is a 2-column numeric array (serial datenum, values). That’s efficient but not the most useful for economists. Two properties on the fred object that let you modify that are:
- DataReturnFormat — choose ‘table’ or ‘timetable’ for easier downstream analytics.
- DatetimeType — set to ‘datetime’ to avoid manual datetime conversion.
Example:
c = fred; c.DataReturnFormat = "table"; c.DatetimeType = "datetime"; d = fetch(c, "DEXUSEU"); % d is a 1xN table of series metadata;
The toolbox documentation lists these properties and how to set them, and provides examples that return tables, as well as tables whose Data{1} contains a 2-column table with dates and values.
Why this matters: Once you have a timetable, operations like retime, synchronize across series, plotting, and model fitting (Econometrics/Statistics) become frictionless. It also eliminates error-prone conversions from serial date numbers.
Everyday patterns (with quick wins)
- Pull a full series, then subset in MATLAB
Prefer grabbing full history once and filtering in memory—it minimizes network calls and lets you experiment quickly: d = fetch(c, "CPIAUCSL"); % Consumer Price Index, full history tt = d.Data{1}; % timetable with Time + Value tt2010s = tt(timerange(datetime(2010,1,1), datetime(2019,12,31)), :);
- Date-range fetch when performance matters
If you only need a sliver (say the last 3 years), use the two-date fetch signature so you move less data:d = fetch(c, "UNRATE", datetime(2022,1,1), datetime(2025,08,01));
- Connectivity best practice
Use isconnection(c) if needed and always close(c) when done—especially inside scripts that run on schedules/servers. These object functions are part of the FRED interface.
When you need the REST API: the (recently updated) File Exchange helper
While Datafeed Toolbox’s connector is the simplest way to stay “official” and integrated, sometimes you’ll want direct REST access—e.g., to explore endpoints not yet surfaced in the connector, to control parameters outside the documented surface, or to build microservices around FRED.
The FRED® REST for MATLAB submission on File Exchange is built and maintained by the MathWorks Computational Finance Team. It requires MATLAB and Datafeed Toolbox and is compatible with R2018a and later releases.
Why it complements the connector:
- Coverage & control: If FRED exposes new REST parameters or endpoints (releases, sources, tags, categories), the REST helper can give you early access while the connector catches up.
- Microservice patterns: You can call REST routines from MATLAB, then package results to JSON/Parquet for downstream pipelines
Bottom line
For most workflows, the Datafeed Toolbox FRED connector is the quickest way to get high-quality, analysis-ready time series into MATLAB. Set DataReturnFormat and DatetimeType once, then build your models. Keep the File Exchange REST helper in your toolkit for advanced catalog exploration and to track the newest API features.
- Category:
- Econometrics
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.