fredpy.series
class¶
- class fredpy.series(series_id=None, observation_date=None, cache=True)¶
Creates an instance of
fredpy.series
that stores information about the specified data series from FRED with the unique series ID code given byseries_id
.- Parameters:
series_id (str) – unique FRED series ID. If
series_id
equalsNone
, an emptyfredpy.series
instance is created.observation_date (str) – Desired date at which data are observed. Either YYYY-MM-DD or MM-DD-YYYY format. If
observation_date
isNone
, today’s date is used.cache (bool) – Whether to store a copy of the downloaded data in memory to avoid repeating calls to the FRED API. Default:
True
.
Attributes:
- data:
(Pandas Series) – data values.
- date_range:
(string) – specifies the dates of the first and last observations.
- frequency:
(string) – data frequency. ‘Daily’, ‘Weekly’, ‘Monthly’, ‘Quarterly’, or ‘Annual’.
- frequency_short:
(string) – data frequency. Abbreviated. ‘D’, ‘W’, ‘M’, ‘Q’, ‘SA, or ‘A’.
- last_updated:
(string) – date series was last updated.
- notes:
(string) – details about series. Not available for all series.
- observation_date:
(string) – vintage date at which data are observed.
- release:
(string) – statistical release containing data.
- seasonal_adjustment:
(string) – specifies whether the data has been seasonally adjusted.
- seasonal_adjustment_short:
(string) –specifies whether the data has been seasonally adjusted. Abbreviated.
- series_id:
(string) – unique FRED series ID code.
- source:
(string) – original source of the data.
- t:
(integer) – number corresponding to frequency: 365 for daily, 52 for weekly, 12 for monthly, 4 for quarterly, and 1 for annual.
- title:
(string) – title of the data series.
- units:
(string) – units of the data series.
- units_short:
(string) units of the data series. Abbreviated.
Methods:
- apc(log=False, backward=True)¶
Computes the percentage change in the data over one year.
- Parameters:
log (bool) – If True, computes the percentage change as \(100\cdot\log(x_{t}/x_{t-k})\), where \(k\) is the number of observations per year. If False (default), compute the percentage change as \(100\cdot\left( x_{t}/x_{t-k} - 1\right)\).
backward (str) – If True (default), compute percentage change from the previous year. If False, compute percentage change from current to next year.
- Returns:
- as_frequency(freq=None, method='mean')¶
Convert a
fredpy.series
to a lower frequency.- Parameters:
- Returns:
- bp_filter(low=None, high=None, K=None)¶
Computes the bandpass (Baxter-King) filter of the data. Returns two
fredpy.series
instances containing the cyclical and trend components of the data:new_series_cycle, new_series_trend
Recommendations:
Monthly data: low=24, high=84, K=84
Quarterly data: low=6, high=32, K=12
Annual data: low=1.5, high=8, K=3
- Parameters:
- Returns:
two
fredpy.series
instances
Note
In computing the bandpass filter, K observations are lost from each end of the original series so the attributes dates, datetimes, and data are 2K elements shorter than their counterparts in the original series.
- cf_filter(low=None, high=None)¶
Computes the Christiano-Fitzgerald filter of the data. Returns two
fredpy.series
instances containing the cyclical and trend components of the data:new_series_cycle, new_series_trend
Recommendations:
Monthly data: low=18, high=96
Quarterly data: low=6, high=32
Annual data: low=2, high=8
- Parameters:
- Returns:
two
fredpy.series
instances
- copy()¶
Returns a copy of the
fredpy.series
instance.- Parameters:
None
- Returns:
- diff_filter()¶
Computes the first difference filter of original series. Returns two
fredpy.series
instances containing the cyclical and trend components of the data:new_series_cycle, new_series_trend
- Parameters:
- Returns:
two
fredpy.series
instances
Note
In computing the first difference filter, the first observation from the original series is lost so the attributes dates, datetimes, and data are 1 element shorter than their counterparts in the original series.
- divide(object2)¶
Divides the data from the current fredpy series by the data from
object2
.- Parameters:
object2 (fredpy.series) – A
fredpy.series
instance, number, array, or similar.- Returns:
- drop_nan()¶
Removes NaN values from fredpy series.
- Returns:
- hp_filter(lamb=None)¶
Computes the Hodrick-Prescott filter of the data. Returns two
fredpy.series
instances containing the cyclical and trend components of the data:new_series_cycle, new_series_trend
Recommendations:
Daily data: lamb= 104976000000
Monthly data: lamb=129600
Quarterly data: lamb=1600
Annual data: lamb=6.25
- Parameters:
lamb (int) – Default
None
, recommended value used.- Returns:
two
fredpy.series
instances
- linear_filter()¶
Computes a simple linear filter of the data using OLS. Returns two
fredpy.series
instances containing the cyclical and trend components of the data:new_series_cycle, new_series_trend
- Parameters:
- Returns:
two
fredpy.series
instances
- log()¶
Computes the natural log of the data.
- Parameters:
- Returns:
- ma(length, center=False)¶
Computes a moving average with window equal to
length
. Ifcenter
is True, then the two-sided moving average is computed. Otherwise, the moving average will be one-sided.- Parameters:
- Returns:
- minus(object2)¶
Subtracts the data from
object2
from the data from the current fredpy series.- Parameters:
object2 (fredpy.series) – A
fredpy.series
instance, number, array, or similar.- Returns:
- pc(log=False, backward=True, annualized=False)¶
Computes the percentage change in the data from the preceding period.
- Parameters:
log (bool) – If True, computes the percentage change as \(100\cdot\log(x_{t}/x_{t-1})\). If False (default), compute the percentage change as \(100\cdot\left( x_{t}/x_{t-1} - 1\right)\).
backward (str) – If True, compute percentage change from the previous period. If ‘forward’, compute percentage change from current to subsequent period.
annualized (bool) – Default: False: If True, percentage change is computed at an annual rate. E.g., if the data were monthly and log==False, then the annualized percentage change would be: \(100\cdot\left[ \left(x_{t}/x_{t-1}\right)^{12} - 1\right]\).
- Returns:
- per_capita(total_pop=True)¶
Transforms the data into per capita terms by dividing by a measure of the total population of the United States.
- Parameters:
total_pop (str) – If
total_pop
is True, then use the toal population (Default). Else, use civilian noninstitutional population defined as persons 16 years of age and older.- Returns:
- plot(**kwargs)¶
Equivalent to calling
.plot()
method on the.data
attribute (which is a Pandas Series object). See https://pandas.pydata.org/docs/reference/api/pandas.Series.plot.html for documenation on usage.
- plus(object2)¶
Adds the data from the current fredpy series to the data from
object2
.- Parameters:
object2 (fredpy.series) – A :py:class:
fredpy.series
instance, number, array, or similar.- Returns:
- recent(N)¶
Restrict the data to the most recent N observations.
- Parameters:
N (int) – Number of periods to include in the data window.
- Returns:
- recessions(ax=None, color='0.5', alpha=0.5)¶
Creates recession bars for plots. Unless ‘ax’ is specified, be used after a plot has been made but before either (1) a new plot is created or (2) a show command is issued.
- times(object2)¶
Multiplies the data from the current fredpy series with the data from
object2
.- Parameters:
object2 (fredpy.series) – A
fredpy.series
instance, number, array, or similar.- Returns:
- window(win)¶
Restricts the data to the most recent N observations.
- Parameters:
win (list) – is an ordered pair:
win = [win_min, win_max]
wherewin_min
is the date of the minimum date desired andwin_max
is the date of the maximum date. Date strings must be entered in either YYYY-MM-DD or MM-DD-YYYY format.- Returns: