
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
fred-timeseries-toolkit
Advanced tools
A toolkit for time series analysis and forecasting with FRED integration.
Table of Contents | |
1. Overview |
2. FRED API Key Requirement |
3. Installation |
4. Package Structure |
5. Techniques and Defaults |
6. Function Descriptions |
7. Summary Β Β Β - Functions and Purposes Β Β Β - Techniques Used |
8. License |
Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β 9. Contributing |
FRED-Timeseries-Analysis-Package is a Python package for fetching, analyzing, and forecasting economic time series data, built on top of FRED, pandas
, and statsmodels
.
It includes:
An example notebook is included in the examples/
folder.
In order to fetch data from the FRED database, you must obtain a free FRED API key.
How to get a FRED API key:
Where to use the API key:
fetch_series
function requires your FRED API key as an input.fetch_series
, and your data will load automatically.Example usage:
fred_api_key = 'your-api-key-here'
gdp = fetch_series('GDP', start_date='2010-01-01', api_key=fred_api_key)
FRED-Timeseries-Analysis-Package/
β
βββ timeseries_toolkit/ <- the code folder (same name as PyPI project)
β βββ __init__.py <- makes it a package
β βββ ts_toolkit.py <- (check_stationarity, check_stationarity_diff)
β
βββ examples/ <- Jupyter notebooks showing usage
β βββ basic_usage.ipynb
β
βββ README.md <- describe project, functions
βββ pyproject.toml <- (for packaging)
βββ requirements.txt <- dependencies (fredapi, pandas, statsmodels, matplotlib, etc.)
You can install the package directly from PyPI:
pip install fred-timeseries-toolkit
Or install it from the GitHub repository:
pip install git+https://github.com/RoryQo/FRED-Timeseries-Analysis-Package.git
Requirements (automatically handled with pip install):
fredapi
pandas
statsmodels
matplotlib
scikit-learn
numpy
Make sure you have Python 3.8 or later.
Important Note:
Thefredapi
package must be installed and imported separately when using this toolkit.
Whilefredapi
is included as a dependency, users must create and manage their ownFred
object with their FRED API key when working with the toolkitβs functions.
from fredapi import Fred
fred = Fred(api_key='your-api-key-here')
Missing Data Handling:
By default, series are cleaned using .dropna()
. When resampling, missing periods are filled by forward-fill (ffill
) unless otherwise specified.
Frequency Handling:
Functions can infer time series frequency from the index or allow manual override (freq
argument).
Model Stability Checks:
Automatic model selection (ARIMA and SARIMA) rejects unstable fits (e.g., AR/MA terms near 1, singular covariance matrices).
Plotting:
All forecasting functions plot observed + forecasted values unless plot=False
.
Import
from fred_timeseries_toolkit.ts_toolkit import (
fetch_series,
resample_series,
log_diff,
check_stationarity,
check_stationarity_diff,
quick_arima_forecast,
quick_arima_forecast_testing,
auto_arima_forecast,
sarima_forecast,
auto_sarima_forecast)
from fredapi import Fred
fetch_series
Description:
Fetches a single time series from the FRED database.
Inputs:
series_id
(str): The FRED series ID.start_date
, end_date
(optional, str or datetime): Date range.api_key
(str): Userβs FRED API key.Outputs:
pandas.Series
indexed by dates.Default behavior:
Entire available series is fetched if no date range is specified.
Reminder:
This function requires that you manage your own Fred
object separately.
Ensure that fredapi
is installed and imported before fetching data.
See the Installation section for guidance on how to properly import fredapi
.
resample_series
Description:
Resamples a series to a new frequency.
Inputs:
series
(pandas.Series): Input series.freq
(str): Target frequency ('Q'
, 'M'
, 'A'
, etc.).method
(str): Fill method ('ffill'
or 'bfill'
).Outputs:
pandas.Series
resampled.Default behavior:
Forward-fill (ffill
) is used for missing values.
log_diff
Description:
Applies log transformation and differencing to stabilize variance and mean.
Inputs:
series
(pandas.Series): Input series.periods
(int): Number of periods to difference.Outputs:
pandas.Series
after log and differencing.Default behavior:
1-period difference.
check_stationarity
Description:
Performs the Augmented Dickey-Fuller (ADF) test for stationarity.
Inputs:
series
(pandas.Series)alpha
(float): Significance level (default 0.05).regression
(str): Trend type ('c', 'ct', 'ctt', 'n').autolag
(str): Criterion for lag selection ('AIC', 'BIC').resample_freq
, resample_method
(optional): If provided, resample before testing.Outputs:
Default behavior:
Original series used without resampling. Displays formatted summary and plot.
check_stationarity_diff
Description:
Same as check_stationarity
but first differences the series before applying the ADF test.
Inputs:
Same as check_stationarity
.
Outputs:
Default behavior:
First difference applied automatically.
quick_arima_forecast
Description:
Fits an ARIMA model and forecasts future periods.
Inputs:
p
, d
, q
).forecast_steps
(int): Number of periods ahead to forecast.Outputs:
Default behavior:
Forecast 5 future periods, plot results.
quick_arima_forecast_testing
Description:
Splits data into train/test sets, fits ARIMA, forecasts, and evaluates RMSE.
Inputs:
train_ratio
(float): Fraction of data to train on (default 0.8).Outputs:
Default behavior:
80% train / 20% test split, forecast matching test set size.
auto_arima_forecast
Description:
Automatically searches ARIMA(p,d,q) models using AIC or BIC.
Inputs:
ic
(str): 'aic' or 'bic'.Outputs:
Default behavior:
Minimizes AIC, autoreject unstable models.
sarima_forecast
Description:
Manually fits SARIMA(p,d,q)x(P,D,Q,s) model.
Inputs:
p,d,q
) and seasonal (P,D,Q,s
) orders.freq
) optional.Outputs:
Default behavior:
No seasonality unless specified. Forecast 5 periods ahead.
auto_sarima_forecast
Description:
Automatically selects best SARIMA(p,d,q)x(P,D,Q,s) model.
Inputs:
ic
(str): 'aic' or 'bic'.Outputs:
Default behavior:
Default seasonality s=4
(quarterly). Autoreject unstable models.
Function | Purpose |
---|---|
fetch_series | Fetch time series data from FRED |
resample_series | Resample to new frequency |
log_diff | Log-transform and difference a series |
check_stationarity | ADF stationarity test |
check_stationarity_diff | ADF test after differencing |
quick_arima_forecast | Fit ARIMA and forecast |
quick_arima_forecast_testing | ARIMA with train/test evaluation |
auto_arima_forecast | Auto-select ARIMA model |
sarima_forecast | Fit SARIMA manually |
auto_sarima_forecast | Auto-select SARIMA model |
Feature | Behavior |
---|---|
Missing Data | .dropna() at start; resample() uses 'ffill' |
Frequency | Infer from index if not provided, or manually set |
Model Stability | Auto-reject AR/MA terms near unit root or singular covariance |
Plotting | Enabled by default, can be turned off |
Forecasting | Extends beyond last date, aligns future dates automatically |
This project is licensed under the MIT License.
See the LICENSE
file for details.
Contributions are welcome!
If you would like to improve this package, feel free to open:
When contributing, please:
examples/
notebook if you add major functionalityFor large changes, it is recommended to open an issue first to discuss the proposed approach.
FAQs
A toolkit for time series analysis and forecasting with FRED integration.
We found that fred-timeseries-toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnamβs Telegram ban.