This repository contains tools for analyzing and identifying similar macroeconomic regimes throughout history. It fetches data from various sources, processes it, and applies machine learning techniques to identify historical periods that most closely match the current economic environment.
The system works by:
- Fetching macroeconomic data from FRED API and Yahoo Finance
- Processing and filling any missing values
- Analyzing the data to identify similar historical regimes
- Generating visualizations and outputs for analysis
- Python 3.6+
- FRED API key (obtain from https://fred.stlouisfed.org/docs/api/api_key.html)
-
Clone this repository:
git clone https://github.com/yourusername/macro-regime-matching.git cd macro-regime-matching -
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt -
Create a
.envfile in the root directory with your FRED API key:FRED_API_KEY=your_fred_api_key_here
To collect macroeconomic data from FRED and other sources:
python fetch_macro_data.py
This will create a CSV file containing various macroeconomic indicators including:
- GDP, Industrial Production, and other growth metrics
- Inflation measures (CPI, PCE)
- Employment statistics
- Financial market indicators
- Housing data
- And more
To handle missing values and ensure the dataset is up-to-date:
python fill_latest_values.py
This script will:
- Identify and fill missing values
- Ensure the most recent data points are included
- Prepare the data for analysis
For a more detailed analysis with carefully selected variables:
python refined_regime_analysis.py
This will:
- Process the data using a refined set of variables
- Calculate various metrics (percentage changes, absolute changes, etc.)
- Perform similarity analysis to identify historical regimes matching the current environment
- Generate visualizations and output files in the
results_refineddirectory
The analysis generates various outputs in dedicated directories:
results_refined: Refined analysis with carefully selected variables
Key outputs include:
- CSV files with similarity scores
- Visualizations of similar regimes
- Time series comparisons
- Feature importance analysis