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(:,2).
- The M1 structure also contains other info, eg. M1.Title, or the dates in M1.Data(:,1).
- Dates are in Matlab’s datenum format, counts days starting from 0000-01-01. You can convert them using Matlab functions datestr and datevec, graph them with dateticks. Sometimes you will want them in a format telling you the quarter; use datevec, get months, and then turn months to quarters using ceil(‘month’/3).
- 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]