Processing Financial Data with FRED API
Jump to navigation
Jump to search
Internal
Overview
This article describes the sequence of steps required to process financial data obtained from FRED API.
Procedure
Import the package and establish a connection to the FRED backend, providing the API Key obtained as described here.
from fredapi import Fred
fred = Fred(api_key='...')
Search for a dataset using full text search. The result is a DataFrame.
df = fred.search("S&P", limit=1000, order_by=None, sort_order=None, filter=None)
The exploration yields a series with the ID "SP500".
Retrieve the Series:
s = fred.get_series(series_id="SP500")
The series is already time-indexed:
2013-10-07 1676.12 2013-10-08 1655.45 2013-10-09 1656.40 2013-10-10 1692.56 2013-10-11 1703.20 ... 2023-10-02 4288.39 2023-10-03 4229.45 2023-10-04 4263.75 2023-10-05 4258.19 2023-10-06 4308.50 Length: 2610, dtype: float64
s.index
DatetimeIndex(['2023-10-01', '2023-10-02', '2023-10-03', '2023-10-04', '2023-10-05', '2023-10-06', '2023-10-07', '2023-10-08', '2023-10-09'], dtype='datetime64[ns]', name='date', freq=None)