This script retrieves and visualizes economic indicators using the FRED API. You can customize it further based on your specific needs or preferences.
This Python script retrieves and visualizes key economic indicators from the Federal Reserve Economic Data (FRED) API. The indicators include:
- M2 Money Supply
- Consumer Price Index (CPI) for inflation
- Unemployment Rate
- Overnight Reverse Repo
- Daily Reserves
- Treasury General Account (TGA)
The script generates plots for each indicator, displaying historical data and the latest values.
To run this script, you need the following Python packages:
pandasmatplotlibfredapi
You can install these packages using pip:
pip install pandas matplotlib fredapi-
FRED API Key: You need to obtain an API key from the FRED website. Replace the placeholder in the script with your actual API key:
api_key = 'your_api_key' # Replace with your actual FRED API key
-
Run the Script: Execute the script in your Python environment. The script will retrieve the latest data for the specified economic indicators and generate plots.
- Data Retrieval: The script uses the
fredapilibrary to fetch data for various economic indicators. - Data Visualization: Each indicator is plotted using
matplotlib, with the latest value annotated on the plot. - Legend Positioning: Legends are positioned on the left side of each plot for better visibility.
- Maximized Plots: Each plot window is maximized for an enhanced viewing experience.
- Imports: The necessary libraries are imported at the beginning of the script.
- API Key Setup: The FRED API key is initialized.
- Data Retrieval and Plotting: The script retrieves data for each economic indicator and generates corresponding plots.
To run the script, simply execute it in your Python environment:
python economic_indicators_visualization.pyThe script will display plots for each economic indicator, showing historical trends and the latest values. Each plot will be maximized and will have the legend positioned on the left side.
The script includes basic error handling to manage issues that may arise during data retrieval. If an error occurs, a message will be printed to the console.
Sunny Chase, All Rights Reserved 2025
- FRED API for providing access to economic data.
- Matplotlib for data visualization.