Processing Financial Data with FRED API: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 20: Line 20:
</syntaxhighlight>
</syntaxhighlight>


fred.search("text", limit=1000, order_by=None, sort_order=None, filter=None)
The exploration yields a series with the ID "SP500".
 
Retrieve the [[Pandas_Series|Series]]:
 
<syntaxhighlight lang='py'>
s = fred.get_series(series_id="SP500")
</syntaxhighlight>
</syntaxhighlight>
Do a full text search for series in the FRED data set. Returns the results as a [[Pandas_Concepts#Data_Frame|data frame]].


==Get Series==
The series is already time-indexed:
<font size=-2>
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
</font>
 
<syntaxhighlight lang='py'>
s.index
</syntaxhighlight>
<font size=-2>
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)
</font>

Latest revision as of 19:41, 8 October 2023

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)