A comprehensive, production-ready machine learning platform for stock price prediction using LSTM and attention mechanisms. Built with enterprise-grade architecture, including data pipelines, model training, serving, monitoring, and deployment infrastructure.
Transform a tutorial LSTM model into a production-grade system with:
- β Robust Data Engineering: Multi-source data ingestion with quality validation
- β Production-grade ML: Reproducible training, evaluation, and serving
- β Scalable Architecture: Kubernetes-ready, cloud-agnostic deployment
- β Comprehensive Monitoring: Performance, data quality, and business metrics
- β Complete Testing: Unit, integration, and performance tests
- β Enterprise Security: Authentication, encryption, audit logging
- β MLOps Best Practices: Experiment tracking, model registry, versioning
- Quick Start
- Architecture
- Project Structure
- Installation
- Usage
- Development
- Testing
- Deployment
- Documentation
- Contributing
- License
- Python 3.10+
- Docker & Docker Compose
- Git
- PostgreSQL 15
- Redis 7
# Clone the repository
git clone https://github.com/example/stock-predictor-prod.git
cd stock-predictor-prod
# Copy environment file
cp .env.example .env
# Set up development environment (installs dependencies)
make setup
# Start Docker services (PostgreSQL, Redis, MLflow, Airflow)
make docker-up
# Verify all services are running
make health-check# Start a training pipeline
make run-training
# Or use Airflow for scheduling
make run-scheduler
make run-webui # http://localhost:8080# Development server (with auto-reload)
make run-api
# Server will be available at http://localhost:8000
# API docs at http://localhost:8000/docs# Access MLflow tracking UI
open http://localhost:5000
# Monitor with Prometheus/Grafana
open http://localhost:3000 # Username: admin, Password: from .envβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Ingestion Layer β
β (Alpha Vantage, IEX Cloud, FMP, Yahoo Finance) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Data Processing Pipeline β
β (Validation, Cleaning, Feature Engineering, Feast) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Model Training & Evaluation β
β (PyTorch LSTM, Attention, Hyperparameter Tuning) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β MLflow Registry β
β (Experiment Tracking, Model Versioning, A/B Testing) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Model Serving & Prediction API β
β (FastAPI, Redis Caching, Load Balancing) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Monitoring, Alerting & Continuous Improvement β
β (Prometheus, Grafana, Data Drift Detection) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Technology | Purpose |
|---|---|---|
| Orchestration | Apache Airflow | Workflow scheduling & DAG management |
| ML Framework | PyTorch Lightning | Model training & distributed learning |
| Feature Store | Feast (upcoming) | Feature management & serving |
| Model Registry | MLflow | Experiment tracking & model versioning |
| API Serving | FastAPI | REST API for predictions |
| Caching | Redis | Feature & prediction caching |
| Database | PostgreSQL | Data storage & metadata |
| Monitoring | Prometheus + Grafana | Metrics & visualization |
| Deployment | Kubernetes | Container orchestration |
| CI/CD | GitHub Actions | Automated testing & deployment |
stock-predictor-prod/
βββ .github/
β βββ workflows/
β βββ ci.yml # CI/CD pipeline
βββ airflow/
β βββ dags/ # Airflow DAGs
β βββ logs/
β βββ plugins/
βββ configs/
β βββ default.yaml # Default configuration
β βββ production.yaml # Production settings
β βββ prometheus.yml # Prometheus config
β βββ grafana/
β βββ provisioning/ # Grafana dashboards
βββ data/
β βββ raw/ # Original data from APIs
β βββ processed/ # Cleaned & validated data
β βββ features/ # Engineered features
βββ docs/
β βββ architecture/ # System design docs
β β βββ adr/ # Architecture Decision Records
β βββ api/ # API documentation
β βββ guides/ # User guides
βββ docker/
β βββ Dockerfile.train # Training image
β βββ Dockerfile.serve # Serving image
β βββ Dockerfile.dev # Development image
β βββ Dockerfile.airflow # Airflow image
βββ k8s/
β βββ deployment.yaml # K8s deployment
β βββ service.yaml # K8s service
β βββ configmap.yaml # K8s config
β βββ secrets.yaml # K8s secrets
βββ notebooks/
β βββ exploration/ # Data exploration
β βββ experiments/ # Model experiments
βββ production/
β βββ data_ingestion/ # Data collection APIs
β β βββ __init__.py
β β βββ base.py
β β βββ alpha_vantage.py
β β βββ iex_cloud.py
β β βββ validators.py
β βββ features/ # Feature engineering
β β βββ __init__.py
β β βββ technical_indicators.py
β β βββ statistical.py
β β βββ feature_store.py
β βββ models/ # Model definitions
β β βββ __init__.py
β β βββ lstm.py
β β βββ attention.py
β β βββ ensemble.py
β βββ training/ # Training pipeline
β β βββ __init__.py
β β βββ train.py
β β βββ evaluate.py
β β βββ hyperparameter_tuning.py
β β βββ callbacks.py
β βββ serving/ # Prediction serving
β β βββ __init__.py
β β βββ api.py
β β βββ models_loader.py
β β βββ cache.py
β βββ monitoring/ # Monitoring & metrics
β β βββ __init__.py
β β βββ metrics.py
β β βββ data_drift.py
β β βββ alerting.py
β βββ utils/ # Shared utilities
β β βββ __init__.py
β β βββ config.py
β β βββ logging.py
β β βββ database.py
β βββ health_check.py # System health check
βββ scripts/
β βββ init_db.sql # Database initialization
β βββ train_model.py # Training script
β βββ evaluate_model.py # Evaluation script
β βββ deploy_model.py # Deployment script
βββ tests/
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ performance/ # Performance tests
βββ .env.example # Environment template
βββ .gitignore
βββ .pre-commit-config.yaml # Pre-commit hooks
βββ docker-compose.yml # Docker services
βββ Makefile # Development tasks
βββ pyproject.toml # Project metadata & dependencies
βββ README.md # This file
βββ requirements.txt # Python dependencies
git clone https://github.com/example/stock-predictor-prod.git
cd stock-predictor-prodUsing venv:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateUsing conda:
conda create -n stock-pred python=3.10
conda activate stock-pred# Install pyproject dependencies
pip install -e .
# Install dev dependencies for development
pip install -e ".[dev]"
# Run setup (installs pre-commit hooks)
make setup# Copy environment template
cp .env.example .env
# Edit .env with your API keys and credentials
nano .env# Start PostgreSQL via Docker
make docker-up
# Wait for PostgreSQL to be ready, then initialize
make db-initfrom production.data_ingestion import AlphaVantageProvider
provider = AlphaVantageProvider(api_key="your_key")
data = provider.get_daily("AAPL", start_date="2023-01-01")from production.features import TechnicalIndicators
from datetime import datetime, timedelta
indicators = TechnicalIndicators(lookback_period=60)
features = indicators.calculate_all(df)from production.training import Trainer
from production.models import LSTMWithAttention
model = LSTMWithAttention(
input_size=15, # Number of features
hidden_size=64,
num_layers=2,
dropout=0.2
)
trainer = Trainer(model)
history = trainer.fit(train_loader, val_loader, epochs=50)from production.serving import PredictionServer
server = PredictionServer()
prediction = server.predict(
ticker="AAPL",
days_ahead=5
)curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"ticker": "AAPL",
"days_ahead": 5,
"confidence_interval": 0.95
}'# Run all tests
make test
# Run only unit tests
make test-unit
# Run integration tests
make test-integration
# Run with coverage report
make test-cov
# Run specific test file
pytest tests/unit/test_feature_engineering.py -v# Format code
make format
# Lint code
make lint
# Type checking
make type-check
# Security scanning
make security# Start all services
make docker-up
# View logs
make docker-logs
# Access services
# PostgreSQL: localhost:5432
# Redis: localhost:6379
# MLflow: http://localhost:5000
# Airflow: http://localhost:8080
# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000
# Adminer: http://localhost:8081make notebook
# Open http://localhost:8888# Build training image
docker build -f docker/Dockerfile.train -t stock-predictor:latest .
# Build API image
docker build -f docker/Dockerfile.serve -t stock-predictor-api:latest .# Apply configurations
kubectl apply -f k8s/
# Check deployment status
kubectl get pods
kubectl logs -f <pod-name># Production deployment requires these environment variables
export POSTGRES_HOST=prod-db.example.com
export POSTGRES_PASSWORD=<secure-password>
export REDIS_HOST=prod-redis.example.com
export MLFLOW_TRACKING_URI=https://mlflow.example.com
export API_KEY_SECRET=<secure-api-key>make run-tracker # http://localhost:5000# Prometheus: http://localhost:9090
# Grafana: http://localhost:3000 (admin/admin)# View logs
docker-compose logs -f api
# Or in development
tail -f logs/app.logBuild and view complete documentation:
make docs
make docs-serveNavigate to http://localhost:8000 in your browser.
See the docs/ folder for:
- Architecture decisions (docs/architecture/adr/)
- System design (docs/architecture/system_design.md)
- API documentation (docs/api/)
- User guides (docs/guides/)
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- PyTorch Documentation
- MLflow Documentation
- FastAPI Documentation
- Airflow Documentation
- Prometheus Documentation
For issues, questions, or suggestions:
- Open an Issue
- Start a Discussion
- Contact: team@example.com
Built with β€οΈ by the ML Engineering Team