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.
# pip install fredapi
Next we will download the FRED API, ask the FED for an ID (go here), and enter it.
from fredapi import Fred
fred = Fred(api_key='Insert your key here')
Next we get the data we need.
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.
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].plot(gdp.index,gdp.values)
axs[0][0].set_title("Real GDP, SA")
axs[0,0].set_ylabel("2012 $bn")
axs[0][1].plot(empl.index,empl.values)
axs[0][1].set_title("Non-farm employment, SA")
axs[0,1].set_ylabel("thousands")
axs[1][0].plot(unemp.index,unemp.values)
axs[1][0].set_title("Unemployment, SA")
axs[1,0].set_ylabel("%")
axs[1][1].plot(SP500.index,SP500.values)
axs[1][1].set_title("S&P500")
plt.show()