Stock Trend Pattern Recognition — Amazon SageMaker MLOps
A production MLOps pipeline built on Amazon SageMaker for stock trend pattern detection. The model architecture — a stacked LSTM trained on 60-day sequences of 25 technical indicators across AAPL, MSFT, and GOOGL — classifies whether the next 5 trading days are likely to trend up or down.
Training runs as a managed SageMaker Training Job on ml.m5.large, with hyperparameters passed via argparse and the model saved in TensorFlow SavedModel format to S3. The trained model is registered in SageMaker Model Registry with full versioning and approval status tracking — the production equivalent of the manual model_registry.csv pattern used in telco-churn-predictor. Inference is served via a SageMaker Real-Time Endpoint, eliminating cold starts and enabling sub-100ms latency.
The Flask frontend runs on Azure App Service and calls the SageMaker endpoint via boto3 — a deliberate multi-cloud architecture that mirrors enterprise deployments where Azure handles application infrastructure and AWS handles the ML backend. AWS credentials are stored as Azure App Service environment variables, never in code. CI/CD is intentionally omitted — each pipeline run is a manual, deliberate decision to control costs on a personal AWS account.
The UI displays two independent signals side by side: the LSTM prediction (probability from the SageMaker endpoint) and a classic MA crossover signal (golden cross / death cross based on SMA 20 vs SMA 50). The prediction date range and model training date are surfaced on every result for transparency.
Includes Amazon Bedrock (Claude Haiku) zero-shot pattern interpretation as a comparator, completing the four-project cross-task benchmark: tabular classification (churn), short text (spam), long text (sentiment), and time series (trend).
Quick Facts
Overview
Problem
Demonstrating the gap between ad-hoc ML (local training, committed model files, Flask inference) and production MLOps (managed training jobs, model registry, dedicated inference endpoints) — and implementing both patterns on the same model so the architectural difference is clear.
Solution
Full SageMaker MLOps pipeline: prepare_data.py uploads training data to S3, run_training_job.py launches a managed Training Job, register_model.py versions the artefact in Model Registry, deploy_endpoint.py creates a Real-Time Endpoint, and a Flask app on Azure App Service calls it. A delete_endpoint.py script handles cleanup to prevent runaway charges. The UI shows both LSTM and MA crossover signals with full temporal context. The trained model artefact remains in S3 permanently — the endpoint can be restored at any time without retraining. When the endpoint is offline, the app serves the last live prediction with a clear notice explaining it was shut down to avoid charges.
Challenges
SageMaker Training Jobs require strict conventions that differ from local training: data paths from environment variables, hyperparameters via argparse, SavedModel format at SM_MODEL_DIR/1/, and Keras 3 (TF 2.16) requiring model.export() instead of model.save() for directory-format output. The multi-cloud authentication pattern — storing AWS credentials as Azure App Service environment variables — requires careful handling to avoid committing credentials to Git. Endpoint cost management (deleting after demo) is a production consideration absent from local deployments. Azure limits one Linux F1 plan per region per subscription, requiring Central US for this project as West Europe was already used by a prior project.
Results / Metrics
ROC-AUC: 0.574 — meaningfully above random (0.5) without the overfit that would indicate data leakage. Precision 66.3%: when the model predicts bullish, it is correct two-thirds of the time. Training completed in ~5 minutes on ml.m5.large. Endpoint latency ~100ms. Total AWS cost for development and portfolio demo under $1.
Screenshots
Click to enlarge.
Click to enlarge.