File size: 4,608 Bytes
f35bff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38a6b6a
 
 
 
 
 
 
 
 
f35bff2
 
 
 
38a6b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f35bff2
 
 
 
 
 
38a6b6a
f35bff2
 
38a6b6a
 
 
 
 
 
 
f35bff2
 
 
 
 
 
 
 
 
 
38a6b6a
f35bff2
 
38a6b6a
 
f35bff2
 
38a6b6a
f35bff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38a6b6a
f35bff2
 
 
 
38a6b6a
 
f35bff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# FRED Economic Data Analysis Tool

A comprehensive Python tool for collecting, analyzing, and visualizing Federal Reserve Economic Data (FRED) using the FRED API.

## Features

- **Data Collection**: Fetch economic indicators from FRED API
- **Data Analysis**: Generate summary statistics and insights
- **Visualization**: Create time series plots and charts
- **Data Export**: Save data to CSV format
- **Flexible Configuration**: Easy customization of indicators and date ranges

## Setup

### 1. Install Dependencies

```bash
pip install -r requirements.txt
```

### 2. API Key Configuration

1. Get your FRED API key from [FRED API](https://fred.stlouisfed.org/docs/api/api_key.html)
2. Copy `.env.example` to `.env`:
   ```bash
   cp .env.example .env
   ```
3. Edit `.env` and add your API key:
   ```
   FRED_API_KEY=your_actual_api_key_here
   ```

### 3. Project Structure

```
FRED_ML/
β”œβ”€β”€ config/               # Configuration settings
β”‚   β”œβ”€β”€ settings.py       # Environment variables and settings
β”‚   └── pipeline.yaml     # Pipeline configuration
β”œβ”€β”€ src/                  # Source code
β”‚   β”œβ”€β”€ core/            # Core functionality
β”‚   β”œβ”€β”€ analysis/        # Analysis modules
β”‚   β”œβ”€β”€ utils/           # Utility functions
β”‚   └── visualization/   # Visualization modules
β”œβ”€β”€ scripts/             # Executable scripts
β”œβ”€β”€ tests/               # Test files
β”œβ”€β”€ data/                # Data directories
β”‚   β”œβ”€β”€ raw/            # Raw data
β”‚   β”œβ”€β”€ processed/      # Processed data
β”‚   └── exports/        # Exported files
β”œβ”€β”€ requirements.txt     # Python dependencies
β”œβ”€β”€ .env.example        # Environment variables template
└── README.md           # This file
```

## Usage

### Basic Usage

Run the EDA script to perform exploratory data analysis:

```bash
python scripts/run_eda.py
```

Or run the advanced analytics:

```bash
python scripts/run_advanced_analytics.py
```

This will:
- Fetch data for key economic indicators (GDP, Unemployment Rate, CPI, Federal Funds Rate, 10-Year Treasury Rate)
- Generate summary statistics
- Create visualizations
- Save data to CSV files

### Custom Analysis

You can customize the analysis by importing the modules:

```python
from src.core.fred_client import FREDDataCollectorV2
from src.analysis.advanced_analytics import AdvancedAnalytics

# Initialize collector
collector = FREDDataCollectorV2()

# Custom series and date range
custom_series = ['GDP', 'UNRATE', 'CPIAUCSL']
start_date = '2020-01-01'
end_date = '2024-01-01'

# Run analysis
df, summary = collector.run_analysis(
    series_ids=custom_series,
    start_date=start_date,
    end_date=end_date
)
```

## Available Economic Indicators

The tool includes these common economic indicators:

| Series ID | Description |
|-----------|-------------|
| GDP | Gross Domestic Product |
| UNRATE | Unemployment Rate |
| CPIAUCSL | Consumer Price Index |
| FEDFUNDS | Federal Funds Rate |
| DGS10 | 10-Year Treasury Rate |
| DEXUSEU | US/Euro Exchange Rate |
| PAYEMS | Total Nonfarm Payrolls |
| INDPRO | Industrial Production |
| M2SL | M2 Money Stock |
| PCE | Personal Consumption Expenditures |

## Output Files

### Data Files
- CSV files saved in the `data/` directory
- Timestamped filenames (e.g., `fred_economic_data_20241201_143022.csv`)

### Visualization Files
- PNG plots saved in the `plots/` directory
- High-resolution charts with economic indicator time series

## API Rate Limits

The FRED API has rate limits:
- 120 requests per minute
- 1000 requests per day

The tool includes error handling for rate limit issues.

## Configuration

Edit `config/settings.py` to customize:
- Default date ranges
- Output directories
- Default indicators

The API key is now managed through environment variables (see Setup section above).

## Dependencies

- `fredapi`: FRED API client
- `pandas`: Data manipulation
- `numpy`: Numerical computing
- `matplotlib`: Plotting
- `seaborn`: Statistical visualization
- `jupyter`: Interactive notebooks (optional)

## Error Handling

The tool includes comprehensive error handling for:
- API connection issues
- Invalid series IDs
- Rate limit exceeded
- Data format errors

## Contributing

To add new features:
1. Extend the `FREDDataCollector` class
2. Add new methods for specific analysis
3. Update the configuration as needed

## License

This project is for educational and research purposes. Please respect FRED API terms of service.

## Support

For issues with the FRED API, visit: https://fred.stlouisfed.org/docs/api/