File size: 8,188 Bytes
2b395f2 |
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
#!/usr/bin/env python3
"""
FRED ML Simple Demo
Shows system capabilities without requiring real credentials
"""
import os
import sys
import json
import time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import seaborn as sns
from datetime import datetime, timedelta
def demo_data_processing():
"""Demo data processing capabilities"""
print("π Data Processing Demo")
print("=" * 40)
# Create sample economic data
np.random.seed(42)
dates = pd.date_range('2020-01-01', '2024-01-01', freq='M')
# Simulate economic indicators
data = {
'GDP': np.random.normal(100, 5, len(dates)) + np.cumsum(np.random.normal(0, 0.5, len(dates))),
'UNRATE': np.random.normal(5, 1, len(dates)),
'CPIAUCSL': np.random.normal(200, 10, len(dates)) + np.cumsum(np.random.normal(0, 1, len(dates))),
'FEDFUNDS': np.random.normal(2, 0.5, len(dates)),
'DGS10': np.random.normal(3, 0.3, len(dates))
}
df = pd.DataFrame(data, index=dates)
print(f"β
Generated {len(df)} data points for {len(df.columns)} indicators")
print(f"π Date range: {df.index.min()} to {df.index.max()}")
# Basic statistics
print("\nπ Summary Statistics:")
print(df.describe().round(2))
# Correlation analysis
print("\nπ Correlation Matrix:")
correlation = df.corr()
print(correlation.round(3))
return df
def demo_visualization(df):
"""Demo visualization capabilities"""
print("\nπ¨ Visualization Demo")
print("=" * 40)
# 1. Time series plot
print("π Creating time series visualization...")
fig1 = go.Figure()
for col in df.columns:
fig1.add_trace(go.Scatter(
x=df.index,
y=df[col],
name=col,
mode='lines'
))
fig1.update_layout(
title="Economic Indicators Over Time",
xaxis_title="Date",
yaxis_title="Value",
height=500
)
# Save the plot
fig1.write_html("demo_time_series.html")
print("β
Time series plot saved as demo_time_series.html")
# 2. Correlation heatmap
print("π₯ Creating correlation heatmap...")
correlation = df.corr()
fig2 = px.imshow(
correlation,
text_auto=True,
aspect="auto",
color_continuous_scale="RdBu",
title="Correlation Matrix Heatmap"
)
fig2.write_html("demo_correlation.html")
print("β
Correlation heatmap saved as demo_correlation.html")
# 3. Distribution plots
print("π Creating distribution plots...")
fig3 = make_subplots(
rows=2, cols=3,
subplot_titles=df.columns,
specs=[[{"secondary_y": False}, {"secondary_y": False}, {"secondary_y": False}],
[{"secondary_y": False}, {"secondary_y": False}, {"secondary_y": False}]]
)
for i, col in enumerate(df.columns):
row = (i // 3) + 1
col_num = (i % 3) + 1
fig3.add_trace(
go.Histogram(x=df[col], name=col),
row=row, col=col_num
)
fig3.update_layout(height=600, title_text="Distribution of Economic Indicators")
fig3.write_html("demo_distributions.html")
print("β
Distribution plots saved as demo_distributions.html")
return True
def demo_analysis(df):
"""Demo analysis capabilities"""
print("\nπ Analysis Demo")
print("=" * 40)
# Trend analysis
print("π Trend Analysis:")
trends = {}
for col in df.columns:
# Simple linear trend
x = np.arange(len(df))
y = df[col].values
slope, intercept = np.polyfit(x, y, 1)
trends[col] = {
'slope': slope,
'trend_direction': 'Increasing' if slope > 0 else 'Decreasing',
'trend_strength': abs(slope)
}
for indicator, trend in trends.items():
print(f" {indicator}: {trend['trend_direction']} (slope: {trend['slope']:.4f})")
# Volatility analysis
print("\nπ Volatility Analysis:")
volatility = df.pct_change().std() * np.sqrt(252) # Annualized
for indicator, vol in volatility.items():
print(f" {indicator}: {vol:.2%} annualized volatility")
# Correlation analysis
print("\nπ Correlation Analysis:")
correlation = df.corr()
for i, col1 in enumerate(df.columns):
for j, col2 in enumerate(df.columns):
if i < j: # Avoid duplicates
corr = correlation.loc[col1, col2]
strength = 'Strong' if abs(corr) > 0.7 else 'Moderate' if abs(corr) > 0.3 else 'Weak'
print(f" {col1} vs {col2}: {corr:.3f} ({strength})")
return trends, volatility
def demo_system_architecture():
"""Demo system architecture"""
print("\nποΈ System Architecture Demo")
print("=" * 40)
architecture = {
"Frontend": {
"Technology": "Streamlit",
"Features": ["Interactive dashboard", "Real-time visualization", "User-friendly interface"],
"Status": "β
Ready"
},
"Backend": {
"Technology": "AWS Lambda",
"Features": ["Serverless processing", "Event-driven", "Auto-scaling"],
"Status": "β
Ready"
},
"Storage": {
"Technology": "AWS S3",
"Features": ["Scalable storage", "Lifecycle policies", "Versioning"],
"Status": "β
Ready"
},
"Scheduling": {
"Technology": "EventBridge",
"Features": ["Automated triggers", "Quarterly analysis", "CloudWatch monitoring"],
"Status": "β
Ready"
},
"Data Source": {
"Technology": "FRED API",
"Features": ["Economic indicators", "Real-time data", "Historical analysis"],
"Status": "β
Ready"
}
}
for component, details in architecture.items():
print(f"\n{component}:")
print(f" Technology: {details['Technology']}")
print(f" Features: {', '.join(details['Features'])}")
print(f" Status: {details['Status']}")
def demo_workflow():
"""Demo complete workflow"""
print("\nπ Complete Workflow Demo")
print("=" * 40)
steps = [
("Data Retrieval", "Fetching economic data from FRED API"),
("Data Processing", "Cleaning and preparing data for analysis"),
("Statistical Analysis", "Calculating correlations and trends"),
("Visualization", "Creating charts and graphs"),
("Report Generation", "Compiling results into reports"),
("Cloud Storage", "Uploading results to S3"),
("Scheduling", "Setting up automated quarterly analysis")
]
for i, (step, description) in enumerate(steps, 1):
print(f"{i}. {step}: {description}")
time.sleep(0.5) # Simulate processing time
print("\nβ
Complete workflow demonstrated!")
def main():
"""Main demo function"""
print("π FRED ML System Demo")
print("=" * 50)
print("This demo shows the capabilities of the FRED ML system")
print("without requiring real AWS credentials or FRED API key.")
print()
# Demo system architecture
demo_system_architecture()
# Demo data processing
df = demo_data_processing()
# Demo analysis
trends, volatility = demo_analysis(df)
# Demo visualization
demo_visualization(df)
# Demo complete workflow
demo_workflow()
print("\n" + "=" * 50)
print("π Demo completed successfully!")
print("\nπ Generated files:")
print(" - demo_time_series.html")
print(" - demo_correlation.html")
print(" - demo_distributions.html")
print("\nπ― Next steps:")
print("1. Set up real AWS credentials and FRED API key")
print("2. Run: python scripts/test_dev.py")
print("3. Launch: streamlit run frontend/app.py")
print("4. Deploy to production using CI/CD pipeline")
if __name__ == '__main__':
main() |