A package for exploratory time series analysis and forecasting with FRED integration.
Project description
FRED Timeseries Analysis Package
This package is currently under consideration for publication in the Journal of Open Source Software (JOSS).
| 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:
- Data fetching and resampling
- Stationarity testing (ADF)
- ARIMA and SARIMA modeling
- Automatic model selection
- Jupyter-optimized visualizations
An example notebook is included in the examples/ folder.
FRED API Key Requirement
In order to fetch data from the FRED database, you must obtain a free FRED API key.
How to get a FRED API key:
- Visit the FRED API Key Request page.
- Create a free account if you do not already have one.
- Request an API key from your account dashboard.
- You will receive a personal API key that you can use in all fetch operations.
Where to use the API key:
- The
fetch_seriesfunction requires your FRED API key as an input. - Provide it once when calling
fetch_series, and your data will load automatically.
Example usage:
from fredapi import Fred
fred = Fred(api_key='your-api-key-here')
fred_api_key = 'your-api-key-here'
gdp = fetch_series('GDP', start_date='2010-01-01', api_key=fred_api_key)
Package Structure
FRED-Timeseries-Analysis-Package/
│
├── fred_quincast/ <- the code folder (same name as PyPI project)
│ ├── __init__.py <- makes it a package
│ ├── ts.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.)
Installation
You can install the package directly from PyPI:
pip install fred-quincast
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):
fredapipandasstatsmodelsmatplotlibscikit-learnnumpy
Make sure you have Python 3.8 or later.
Important Note:
Thefredapipackage must be installed and imported separately when using this toolkit.
Whilefredapiis included as a dependency, users must create and manage their ownFredobject with their FRED API key when working with the toolkit’s functions.
from fredapi import Fred
fred = Fred(api_key='your-api-key-here')
Techniques and Defaults
-
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 (freqargument). -
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 unlessplot=False.
Function Descriptions
Import
from fred_quincast.ts 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.Seriesindexed 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.Seriesresampled.
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.Seriesafter 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:
- Dictionary summarizing ADF test results.
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:
- Dictionary summarizing ADF test on differenced series.
Default behavior:
First difference applied automatically.
quick_arima_forecast
Description:
Fits an ARIMA model and forecasts future periods.
Inputs:
- ARIMA orders (
p,d,q). forecast_steps(int): Number of periods ahead to forecast.
Outputs:
- Dictionary with model fit, forecast, AIC, BIC.
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:
- Dictionary with model, forecast, AIC, BIC, RMSE.
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:
- Search ranges for p, d, q.
ic(str): 'aic' or 'bic'.
Outputs:
- Best model, best order, forecast, AIC, BIC.
Default behavior:
Minimizes AIC, autoreject unstable models.
sarima_forecast
Description:
Manually fits SARIMA(p,d,q)x(P,D,Q,s) model.
Inputs:
- Non-seasonal (
p,d,q) and seasonal (P,D,Q,s) orders. - Forecast frequency (
freq) optional.
Outputs:
- Model fit, forecast, AIC, BIC.
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:
- Search ranges for p, d, q, P, D, Q, and seasonality s.
ic(str): 'aic' or 'bic'.
Outputs:
- Best model fit, best order, forecast, AIC, BIC.
Default behavior:
Default seasonality s=4 (quarterly). Autoreject unstable models.
Summary
Functions and Purposes
| 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 |
Techniques Used
| 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 |
License
This project is licensed under the MIT License.
See the LICENSE file for details.
Contributing
Contributions are welcome!
If you would like to improve this package, feel free to open:
- An Issue (for bug reports, feature requests, or clarifications)
- A Pull Request (for proposed changes or additions)
When contributing, please:
- Keep code style clean and readable
- Follow the organization structure (group similar functions together)
- Include clear function descriptions (Inputs, Outputs, Purpose)
- Update the
examples/notebook if you add major functionality
For large changes, it is recommended to open an issue first to discuss the proposed approach.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fred_quincast-0.1.6.tar.gz.
File metadata
- Download URL: fred_quincast-0.1.6.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50b1c05f52437fe0435d53f10f3a173676cbb98469ba9d04a9439ffd8c053562
|
|
| MD5 |
eaaa9c67a52d866a4eaec5df4a9d172a
|
|
| BLAKE2b-256 |
c8bac526936aef71b97e2e018dca69151957010b74999d869bbd09efc7f1a025
|
Provenance
The following attestation bundles were made for fred_quincast-0.1.6.tar.gz:
Publisher:
pypi-publish.yml on RoryQo/FRED-Timeseries-Analysis-Package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fred_quincast-0.1.6.tar.gz -
Subject digest:
50b1c05f52437fe0435d53f10f3a173676cbb98469ba9d04a9439ffd8c053562 - Sigstore transparency entry: 219826027
- Sigstore integration time:
-
Permalink:
RoryQo/FRED-Timeseries-Analysis-Package@ee70b158b1f8cb26e73c4f2ed791deda80b44d2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RoryQo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@ee70b158b1f8cb26e73c4f2ed791deda80b44d2e -
Trigger Event:
push
-
Statement type:
File details
Details for the file fred_quincast-0.1.6-py3-none-any.whl.
File metadata
- Download URL: fred_quincast-0.1.6-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3852b74139299f098915c6c4201404e5587b47fc925106b05908df446ef1bd74
|
|
| MD5 |
2404b5ff0f842546e4596a0d5d11e817
|
|
| BLAKE2b-256 |
6d0dc18d30386102af9189808155b423e5b1c0a881e4f8f50350bfb5f6585474
|
Provenance
The following attestation bundles were made for fred_quincast-0.1.6-py3-none-any.whl:
Publisher:
pypi-publish.yml on RoryQo/FRED-Timeseries-Analysis-Package
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fred_quincast-0.1.6-py3-none-any.whl -
Subject digest:
3852b74139299f098915c6c4201404e5587b47fc925106b05908df446ef1bd74 - Sigstore transparency entry: 219826029
- Sigstore integration time:
-
Permalink:
RoryQo/FRED-Timeseries-Analysis-Package@ee70b158b1f8cb26e73c4f2ed791deda80b44d2e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RoryQo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@ee70b158b1f8cb26e73c4f2ed791deda80b44d2e -
Trigger Event:
push
-
Statement type: