Learn what FRED is and how to use the FRED Python API to access 816,000 US and international timeseries datasets.
You can download the code at the Analyzing Alpha GitHub Repo.
What Is FRED?
FRED, an abbreviation of Federal Reserve Economic Data, is a database consisting of 816,000+ economic datasets from private and public sources. FRED began in the 90s to help people better understand the Fed’s policy decisions. It grew organically and is maintained by The Research Department at the Federal Reserve Bank of St. Louis.
Get Data From The Federal Reserve (FRED)
Install FRED API
!pip install fredapi
Import Packages & Modules
import fredapi as fa
import pandas as pd
from local_settings import fred as settings
fred = fa.Fred(settings['api_key'])
If you don’t want to use a local_settings.py file, you can enter your api_key directly.
fred = fa.Fred(api_key='api_key')
gdp = fred.get_series('GDP')
gdp.name = 'gdp'
gdp.tail()
2020-07-01 21138.574
2020-10-01 21477.597
2021-01-01 22038.226
2021-04-01 22740.959
2021-07-01 23173.496
Name: gdp, dtype: float64
wcurcir = fred.get_series('WCURCIR')
wcurcir.name = 'wcurcir'
df = pd.merge(gdp, wcurcir, left_index=True, right_index=True)
df
gdp wcurcir
1986-01-01 4507.894 197.252
1986-10-01 4657.627 200.310
1987-04-01 4806.160 207.376
1987-07-01 4884.555 214.574
1992-01-01 6363.102 307.620
1992-04-01 6470.763 302.935
1992-07-01 6566.641 310.268
1997-01-01 8362.655 449.867
1997-10-01 8765.907 457.144
1998-04-01 8969.699 473.740
1998-07-01 9121.097 482.139
2003-01-01 11174.129 686.685
2003-10-01 11772.234 696.782
2008-10-01 14608.208 836.296
2009-04-01 14381.236 902.604
2009-07-01 14448.882 907.936
2014-01-01 17144.281 1240.461
2014-10-01 17852.540 1289.118
2015-04-01 18193.707 1357.822
2015-07-01 18306.960 1366.614
2020-01-01 21481.367 1805.880
2020-04-01 19477.444 1876.839
2020-07-01 21138.574 1967.076
The Bottom Line
The FRED API allows developers to retrieve economic data from the FRED database. You now know how to get a FRED API key, install and import the FRED modules, and query and retrieve economic data for financial analysis.