Using the FRED API to get and display key macro series

FRED, a database maintained by the Federal Reserve Bank of St. Louis, is a great, realiable source of macroecononomic and financial data. One can manually access it, download the needed data and manipulate it, but Python makes the process much easier and replicable. For one very current illustration, let us see using recent data if we can see evidence that changes in presidential administrations have a noticeable impact on the economy. Given the current climate, this notebook will just plot numbers. You can decide for yourself whether there is any inflection of note in those series.

The first step is to install the FRED API.

In [1]:
# pip install fredapi 

Next we will download the FRED API, ask the FED for an ID (go here), and enter it.

In [2]:
from fredapi import Fred 
fred = Fred(api_key='Insert your key here')

Next we get the data we need.

In [3]:
empl = fred.get_series('PAYEMS', observation_start='2009-1-1') # seasonally ajusted non-fram employment in thousands 
gdp = fred.get_series('GDPC1', observation_start='2009-1-1') # Seasonally adjusted real GDP # seasonally ajusted non-fram employment in thousands
unemp =fred.get_series('UNRATE', observation_start='2009-1-1') # seasonally ajusted unemployment rate in percent
SP500=fred.get_series('SP500', observation_start='2009-1-1')  # only starts in 2010 at Fred for some reason

Now we plot the results and try to find inflections in the series at any particular date. A formal break test could help us with that, but it hardly seems necessary. (Don't squint too hard.) The impact of COVID, of course, is enormous, but that's a different conversation.

In [4]:
import matplotlib.pyplot as plt #graphing module with matlab-like properties
%matplotlib inline 

fig, axs  = plt.subplots(2, 2,figsize=(12, 8))
fig.suptitle('US Economy since January 2009')

# plt.subplot(221)

axs[0][0].set_title("Real GDP, SA")
axs[0,0].set_ylabel("2012 $bn")

axs[0][1].set_title("Non-farm employment, SA")

axs[1][0].set_title("Unemployment, SA")