{"id":1799,"date":"2025-09-11T14:23:58","date_gmt":"2025-09-11T14:23:58","guid":{"rendered":"https:\/\/blogs.mathworks.com\/finance\/?p=1799"},"modified":"2025-09-11T14:23:58","modified_gmt":"2025-09-11T14:23:58","slug":"the-fred-connector-in-datafeed-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/finance\/2025\/09\/11\/the-fred-connector-in-datafeed-toolbox\/","title":{"rendered":"The FRED Connector in Datafeed Toolbox"},"content":{"rendered":"<p>If you work with macro, markets, or policy analysis, chances are you touch <a href=\"https:\/\/fred.stlouisfed.org\/\" target=\"_blank\" rel=\"noopener\">FRED\u00ae<\/a>\u2014the Federal Reserve Economic Data service. The <a href=\"https:\/\/www.mathworks.com\/products\/datafeed.html\">Datafeed Toolbox<\/a> 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 <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68247-fred-rest-for-matlab\">FRED\u00ae REST<\/a> helper on File Exchange.<\/p>\n<h1><strong>What the FRED connector is (and where to find it)<\/strong><\/h1>\n<p>The FRED connector is an object interface exposed by the <a href=\"https:\/\/www.mathworks.com\/help\/datafeed\/fred.html\">fred<\/a> 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 \u201cMATLAB native,\u201d returning a compact series descriptor plus an array\/table\/timetable for the observations.<\/p>\n<p>At a glance (core API):<\/p>\n<ul>\n<li>Create a connection (default FRED endpoint):<\/li>\n<\/ul>\n<pre>c = fred;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 % default URL: https:\/\/fred.stlouisfed.org\/<\/pre>\n<ul>\n<li>Or specify a URL explicitly:<\/li>\n<\/ul>\n<pre>c = fred(\"https:\/\/fred.stlouisfed.org\/\");<\/pre>\n<ul>\n<li>Retrieve data:<\/li>\n<\/ul>\n<pre>d = fetch(c, \"DEXUSEU\");\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 % full history\r\nd = fetch(c, \"DTB6\", floor(now)-90);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 % range of data from start date to most recent date\r\nd = fetch(c, \"DEXUSEU\", \"01\/01\/2025\", \"08\/31\/2025\");\u00a0 % range\r\n<\/pre>\n<h1><\/h1>\n<h1><strong>Return types: <\/strong><strong>table<\/strong><strong>\/<\/strong><strong>timetable<\/strong><strong> and <\/strong><strong>datetime<\/strong><\/h1>\n<p>Out of the box, fetch can return a <strong>structure<\/strong> whose Data field is a 2-column numeric array (serial datenum, values). That\u2019s efficient but not the most useful for economists. Two properties on the fred object that let you modify that are:<\/p>\n<ul>\n<li>DataReturnFormat \u2014 choose &#8216;table&#8217; or &#8216;timetable&#8217; for easier downstream analytics.<\/li>\n<li>DatetimeType \u2014 set to &#8216;datetime&#8217; to avoid manual datetime conversion.<\/li>\n<\/ul>\n<p>Example:<\/p>\n<pre>c = fred;\r\nc.DataReturnFormat = \"table\";\r\nc.DatetimeType\u00a0\u00a0\u00a0\u00a0 = \"datetime\";\r\nd = fetch(c, \"DEXUSEU\");\u00a0\u00a0\u00a0\u00a0 % d is a 1xN table of series metadata;<\/pre>\n<p>The toolbox<a href=\"https:\/\/www.mathworks.com\/help\/datafeed\/fred.html\"> documentation<\/a> 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.<\/p>\n<p>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.<\/p>\n<p>&nbsp;<\/p>\n<h1><strong>Everyday patterns (with quick wins)<\/strong><\/h1>\n<ol>\n<li><strong><strong>Pull a full series, then subset in MATLAB<br \/>\n<\/strong><\/strong><\/p>\n<pre>Prefer grabbing full history once and filtering in memory\u2014it minimizes network calls and lets you experiment quickly:\r\nd = fetch(c, \"CPIAUCSL\");\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 % Consumer Price Index, full history\r\ntt = d.Data{1};\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 % timetable with Time + Value\r\ntt2010s = tt(timerange(datetime(2010,1,1), datetime(2019,12,31)), :);<\/pre>\n<\/li>\n<li><strong><strong>Date-range fetch when performance matters<br \/>\n<\/strong><\/strong>If you only need a sliver (say the last 3 years), use the two-date fetch signature so you move less data:<\/p>\n<pre>d = fetch(c, \"UNRATE\", datetime(2022,1,1), datetime(2025,08,01));<\/pre>\n<\/li>\n<li><strong>Connectivity best practice<\/strong><br \/>\nUse isconnection(c) if needed and always close(c) when done\u2014especially inside scripts that run on schedules\/servers. These object functions are part of the FRED interface.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h1><strong>When you need the REST API: the (recently updated) File Exchange helper<\/strong><\/h1>\n<p>While Datafeed Toolbox\u2019s connector is the simplest way to stay \u201cofficial\u201d and integrated, sometimes you\u2019ll want <strong>direct REST<\/strong> access\u2014e.g., to explore endpoints not yet surfaced in the connector, to control parameters outside the documented surface, or to build microservices around FRED.<\/p>\n<p>The <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/68247-fred-rest-for-matlab\"><strong>FRED\u00ae REST for MATLAB<\/strong><\/a> 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.<\/p>\n<p><strong>Why it complements the connector:<\/strong><\/p>\n<ul>\n<li><strong>Coverage &amp; control:<\/strong> 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.<\/li>\n<li><strong>Microservice patterns:<\/strong> You can call REST routines from MATLAB, then package results to JSON\/Parquet for downstream pipelines<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1><strong>Bottom line<\/strong><\/h1>\n<p>For most workflows, the <strong>Datafeed Toolbox FRED connector<\/strong> 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 <strong>File Exchange REST helper<\/strong> in your toolkit for advanced catalog exploration and to track the newest API features.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you work with macro, markets, or policy analysis, chances are you touch FRED\u00ae\u2014the Federal Reserve Economic Data service. The Datafeed Toolbox gives you a first-class, native connector to FRED that&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/finance\/2025\/09\/11\/the-fred-connector-in-datafeed-toolbox\/\">read more >><\/a><\/p>\n","protected":false},"author":204,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/1799"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/users\/204"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/comments?post=1799"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/1799\/revisions"}],"predecessor-version":[{"id":1817,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/posts\/1799\/revisions\/1817"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/media?parent=1799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/categories?post=1799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/finance\/wp-json\/wp\/v2\/tags?post=1799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}