A production-ready Nigerian FX forecasting platform that ingests macroeconomic data daily, retrains ML models nightly, and serves USD/NGN exchange rate forecasts through REST APIs and chat interfaces.
flowchart TB
subgraph "Data Sources"
CBN[CBN Exchange Rates]
WB[World Bank Reserves]
DMO[DMO Debt Data]
EIA[EIA Brent Oil]
NEWS[News Sentiment]
end
subgraph "Ingestion Layer"
PREFECT[Prefect Orchestrator]
INGEST[Data Ingestion Services]
end
subgraph "Processing Layer"
FEATURES[Feature Engineering]
VALIDATION[Data Validation]
STORAGE[(PostgreSQL)]
end
subgraph "ML Layer"
TRAINING[Model Training]
OPTUNA[Hyperparameter Optimization]
MLFLOW[MLflow Tracking]
MODELS[(Model Registry)]
end
subgraph "Serving Layer"
API[FastAPI Service]
CHAT[Chat Interface]
EXPLAIN[SHAP Explainer]
end
subgraph "Infrastructure"
DOCKER[Docker Compose]
MONITORING[Logging & Metrics]
end
CBN --> INGEST
WB --> INGEST
DMO --> INGEST
EIA --> INGEST
NEWS --> INGEST
PREFECT --> INGEST
INGEST --> FEATURES
FEATURES --> VALIDATION
VALIDATION --> STORAGE
STORAGE --> TRAINING
TRAINING --> OPTUNA
OPTUNA --> MLFLOW
MLFLOW --> MODELS
MODELS --> API
MODELS --> EXPLAIN
API --> CHAT
DOCKER --> API
DOCKER --> PREFECT
DOCKER --> MLFLOW
DOCKER --> STORAGE
API --> MONITORING
PREFECT --> MONITORING
- Docker and Docker Compose
- Make (optional, for convenience commands)
- curl and jq (for testing)
# Clone the repository
git clone https://github.com/ngfx/predictor.git
cd predictor
# Start the development environment
make dev_up
# Or manually with Docker Compose
docker-compose up -d postgres redis mlflow prefect
sleep 10
docker-compose up -d ngfx_api# Check system status
make status
# Or manually
curl http://localhost:8000/healthz | jq '.'# Get 1-day prediction
make example_pred
# Or manually
curl -X POST "http://localhost:8000/predict?horizon=1" | jq '.'# Ask for a forecast
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{"message": "What is the forecast for tomorrow?"}' | jq '.'# Get explanation for a specific date
curl "http://localhost:8000/explain?date=2024-01-15" | jq '.'Once the system is running, you can access:
- API Documentation: http://localhost:8000/docs
- MLflow Tracking: http://localhost:5000
- Prefect Orchestration: http://localhost:4200
- Prometheus Metrics: http://localhost:9090
- Grafana Dashboard: http://localhost:3000 (admin/admin)
ngfx-predictor/
βββ src/ngfx_predictor/ # Main application code
β βββ api/ # FastAPI application
β βββ config/ # Configuration management
β βββ data/ # Data layer (sources, models)
β βββ features/ # Feature engineering
β βββ models/ # ML models and training
β βββ inference/ # Model inference
β βββ orchestration/ # Prefect flows
β βββ monitoring/ # Metrics and logging
β βββ utils/ # Utilities
βββ tests/ # Test suites
βββ scripts/ # Deployment scripts
βββ monitoring/ # Monitoring configurations
βββ docs/ # Documentation
βββ docker-compose.yaml # Container orchestration
# Start development environment
make dev_up
# Run tests
make test
# Code quality checks
make lint
make format
# CI pipeline
make ci
# View logs
make logs
# Stop environment
make dev_downCopy env.example to .env and customize:
cp env.example .env
# Edit .env with your settingsKey settings:
DATABASE_URL: PostgreSQL connectionREDIS_URL: Redis connectionMLFLOW_TRACKING_URI: MLflow serverCBN_API_KEY: CBN API key (optional)EIA_API_KEY: EIA API key (optional)
# Get prediction for 1-5 days
POST /predict?horizon=1
# Response
{
"date": "2024-01-15",
"horizon": 1,
"usd_ngn": 1520.50,
"pi80": [1490.89, 1550.11],
"confidence": 0.8,
"model_version": "v1.2.3"
}# Get SHAP explanations
GET /explain?date=2024-01-15
# Response
{
"date": "2024-01-15",
"top_features": [
{"feature": "previous_rate", "contribution": 0.45, "direction": "positive"},
{"feature": "oil_price", "contribution": 0.23, "direction": "positive"}
],
"model_version": "v1.2.3"
}# Natural language queries
POST /chat
# Examples
"What's the forecast for tomorrow?"
"Predict the exchange rate for next week"
"Why did the rate change?"# Run all tests
make test
# Run specific test types
pytest tests/unit/
pytest tests/integration/
# With coverage
pytest --cov=src/ngfx_predictor --cov-report=htmlThe system includes comprehensive monitoring:
- Request latency and throughput
- Data source health
- Model performance
- System resources
- Structured JSON logging
- Request tracing
- Error tracking
- Audit logs
- Data staleness alerts
- Model performance degradation
- System health monitoring
- Change default passwords
- Set proper CORS origins
- Configure TLS certificates
- Set up API rate limiting
- Configure firewall rules
- Enable security scanning
- Set up secret management
# Vulnerability scanning
make security_scan
# Container security
trivy image ngfx-predictor:latest# Production deployment
docker-compose -f docker-compose.yaml up -d
# With custom configuration
docker-compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d# Apply Kubernetes manifests
kubectl apply -f k8s/
# Or use Helm
helm install ngfx-predictor ./charts/ngfx-predictorSee docs/setup_vm.md for detailed VM configuration.
- Create a new source class extending
BaseDataSource - Implement
fetch()andfetch_async()methods - Add configuration settings
- Write tests with VCR.py cassettes
- Create model trainer extending
ModelTrainer - Implement training and inference logic
- Add hyperparameter optimization
- Register with MLflow
- Implement feature engineering logic
- Add feature validation
- Update feature schema
- Add feature tests
Database Connection Error
# Check database status
docker-compose logs postgres
# Recreate database
make clean && make dev_upAPI Not Starting
# Check API logs
make logs
# Rebuild container
make build && make dev_upData Source Failures
# Check data source health
curl http://localhost:8000/data/status | jq '.'
# View detailed logs
docker-compose logs ngfx_api | grep -i "data source"- Prediction latency: < 100ms (p95)
- Data ingestion: 10,000 records/minute
- Model training: < 30 minutes
- API throughput: 1,000 requests/second
# Load testing
make perf_test
# Detailed benchmarking
ab -n 1000 -c 50 http://localhost:8000/predict?horizon=1We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Install development dependencies
pip install -e ".[dev]"
# Set up pre-commit hooks
pre-commit install
# Run full CI pipeline
make ciThis project is licensed under the MIT License - see the LICENSE file for details.
- Central Bank of Nigeria for exchange rate data
- World Bank for economic indicators
- EIA for oil price data
- Open source community for excellent tools
Built with β€οΈ for the Nigerian financial community
For questions or support, please contact team@ngfx.com