Skip to main content

fred_forecaster

A Python package for time series forecasting of Federal Reserve Economic Data (FRED).

Python Version License

Features

  • Flexible FRED data retrieval: Fetch any FRED series using its ID (e.g., GFDEBTN for total public debt).
  • Multiple forecasting approaches:
    • Classical SARIMAX modeling: Fit SARIMAX(1,1,1)x(0,1,0)[4] to quarterly data.
    • Bayesian structural time series: Decompose data into level, trend, and seasonal components using PyMC.
  • Simulation: Generate multiple (e.g., 1,000) random simulations for future quarters.
  • Calibration: Reweight simulations to match external targets (e.g., CBO forecasts).
  • Probability analysis: Calculate probabilities of quarter-over-quarter declines.
  • Visualization: Create plots of forecasts, probability distributions, and model components.

Installation

From PyPI

pip install fred-forecaster

From source

git clone https://github.com/maxghenis/fred-forecaster.git
cd fred-forecaster
pip install -e .  # Install core package
pip install -e ".[dev]"  # Include development dependencies
pip install -e ".[app]"  # Include Streamlit app dependencies

Usage

Basic usage

import os
from fred_forecaster import (
    fetch_fred_data,
    fit_sarimax_model,
    generate_simulations,
    plot_forecasts
)

# Set your FRED API key
os.environ["FRED_API_KEY"] = "your_api_key_here"

# Fetch FRED data
data = fetch_fred_data("GFDEBTN")  # Federal debt

# Fit SARIMAX model
model = fit_sarimax_model(data["Debt"])

# Generate simulations
simulations, forecast_index = generate_simulations(model, data, end="2028Q4", N=1000)

# Plot results
fig = plot_forecasts(data, simulations, forecast_index)
fig.savefig("forecast.png")

Bayesian forecasting

from fred_forecaster import (
    fetch_fred_data,
    fit_bayesian_model,
    generate_bayesian_simulations,
    plot_forecasts
)

# Fetch data
data = fetch_fred_data("GFDEBTN")

# Fit Bayesian model
model, idata = fit_bayesian_model(data["Debt"])

# Generate simulations
simulations, forecast_index = generate_bayesian_simulations(
    model, idata, data, end="2028Q4", N=1000
)

# Plot results
fig = plot_forecasts(data, simulations, forecast_index)

Calibration to external targets

from fred_forecaster import calibrate_simulations

# Define your own targets (or use the default CBO targets)
targets = {2024: 35.230, 2025: 37.209}

# Calibrate simulations
weights = calibrate_simulations(simulations, forecast_index, targets)

# Plot calibrated results
fig = plot_forecasts(data, simulations, forecast_index, weights)

Demo App

The package includes a Streamlit demo app that showcases its functionality:

cd demo
streamlit run app.py

This will open a web browser with an interactive interface where you can:

  • Select a FRED series ID
  • Choose between SARIMAX and Bayesian models
  • Toggle calibration to CBO targets
  • Adjust simulation parameters
  • View forecasts and probability analyses

Development

Setup

pip install -e ".[dev]"

Running tests

pytest  # Run regular tests
pytest --run-slow  # Include slow tests (e.g., Bayesian model tests)
pytest --cov=fred_forecaster  # Run with coverage

License

MIT

Acknowledgments

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fred_forecaster-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fred_forecaster-0.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file fred_forecaster-0.1.0.tar.gz.

File metadata

  • Download URL: fred_forecaster-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for fred_forecaster-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f0fa643f77311646ffcbff584a3e8def2d0b44813d607e1075d143bde27567a5
MD5 4ca3e581e6f5c49f0b54f82863bf6490
BLAKE2b-256 2e45ea15dd3a51149c9c89683a874952ed23ab6877866c05f868e03fe7fbdbbb

See more details on using hashes here.

File details

Details for the file fred_forecaster-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fred_forecaster-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aac3a1894acc058a800e5593667aec7679cded045f13580a7ec593616eeec3ef
MD5 2a68053aa716dc302702627519a18f7a
BLAKE2b-256 ef7b731add62c1f10cfd4038ea9dc564a104b62390083f7a76f4536b878d96c6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page