import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from datetime import datetime
# Create synthetic macro data
np.random.seed(42)
dates = pd.date_range('2000-01-01', '2023-12-01', freq='M')
n = len(dates)
# Generate correlated macroeconomic variables
gdp_growth = np.random.normal(2.5, 1.5, n)
inflation = 2 + 0.5 * np.sin(2 * np.pi * np.arange(n) / 12) + np.random.normal(0, 0.8, n)
interest_rate = 3 + 0.3 * np.roll(inflation, 1) + np.random.normal(0, 0.5, n)
unemployment = 6 - 0.2 * gdp_growth + np.random.normal(0, 0.3, n)
macro_df = pd.DataFrame({
'GDP Growth': gdp_growth,
'Inflation': inflation,
'Interest Rate': interest_rate,
'Unemployment': unemployment
}, index=dates)
# Create subplot dashboard
fig, axes = plt.subplots(2, 2, figsize=(15, 10))
axes = axes.ravel()
for i, col in enumerate(macro_df.columns):
axes[i].plot(macro_df.index, macro_df[col], linewidth=2)
axes[i].set_title(f'{col}', fontsize=14, fontweight='bold')
axes[i].grid(True, alpha=0.3)
plt.suptitle('Macroeconomic Indicators Dashboard', fontsize=16, fontweight='bold')
plt.tight_layout()
plt.show()
# Correlation heatmap
plt.figure(figsize=(8, 6))
correlation_matrix = macro_df.corr()
sns.heatmap(correlation_matrix, annot=True, cmap='RdBu_r', center=0,
square=True, cbar_kws={'label': 'Correlation'})
plt.title('Macroeconomic Variables Correlation Matrix')
plt.tight_layout()
plt.show()