Built by Teckgeekz ยท Advanced AI & Machine Learning Engineering
End-to-end deep learning pipeline for cryptocurrency or Stocks price forecasting using stacked LSTM networks
Inspired by Stock-Prediction-using-Transformer-NN
Google Colab link
This repository contains a production-grade LSTM model developed by Teckgeekz for forecasting SOL-USD (Solana) prices across multiple time horizons. The pipeline spans data ingestion, feature engineering, model training, evaluation, and future forecasting โ built with software engineering best practices throughout.
Forecast horizons: 1-day ยท 3-day ยท 7-day ahead predictions with 95% confidence intervals
| Capability | Details |
|---|---|
| ๐ฅ Resilient data ingestion | yfinance with 3-attempt retry + exponential backoff |
| ๐ง Feature engineering | Returns, MA-7, MA-14, 14-day volatility, RSI(14) |
| ๐๏ธ Stacked LSTM architecture | 128 โ 64 units with BatchNorm + Dropout regularisation |
| ๐ Early stopping | restore_best_weights=True, patience = 20 |
| ๐ LR scheduling | ReduceLROnPlateau (factor 0.5, patience 10) |
| ๐ Multi-metric evaluation | MAE ยท RMSE ยท MAPE ยท Rยฒ |
| ๐ฎ Multi-horizon forecasting | 1, 3, 7 days ahead with 95% CI |
| ๐ Rich visualisations | Training curves, actual vs predicted, error fills |
Input: (batch, 14 timesteps, 1 feature)
โ
โโ LSTM(128) โ BatchNorm โ Dropout(0.2)
โโ LSTM(64) โ BatchNorm โ Dropout(0.2)
โโ Dense(32, relu) โ Dropout(0.1)
โโ Dense(16, relu)
โโ Dense(1) โ price output
Optimiser: Adam (lr = 0.001) ยท Loss: MSE ยท Epochs: up to 200 (early stopped) ยท Batch size: 16
Raw OHLCV data (yfinance)
โ
โผ
Feature Engineering
(Returns ยท MA-7 ยท MA-14 ยท Volatility ยท RSI)
โ
โผ
MinMaxScaler [0, 1]
โ
โผ
Train / Test split (80 / 20)
โ
โผ
Sliding window sequences (lookback = 14)
โ
โผ
Stacked LSTM training
+ EarlyStopping + ReduceLROnPlateau
โ
โผ
Evaluation (MAE ยท RMSE ยท MAPE ยท Rยฒ)
โ
โผ
Future forecasts (1d ยท 3d ยท 7d)
+ 95% Confidence Intervals
sol-lstm-prediction/
โ
โโโ Stock_Prediction_Production.ipynb # Main training notebook
โโโ README.md # This file
โโโ requirements.txt # Python dependencies
โโโ outputs/
โโโ training_curves.png # Loss & MAE plots
โโโ predictions_vs_actual.png # Test set overlay
All hyperparameters are centralised at the top of the notebook for easy experimentation:
# Asset & data
STOCK = 'SOL-USD'
LOOKBACK_DAYS = 1095 # 3 years of history
# Sequence
N_STEPS = 14 # 2-week lookback window
LOOKUP_STEPS = [1, 3, 7] # Forecast horizons
# Training
TRAIN_TEST_SPLIT = 0.80
BATCH_SIZE = 16
EPOCHS = 200
VALIDATION_SPLIT = 0.15
# Architecture
LSTM_UNITS_1 = 128
LSTM_UNITS_2 = 64
DENSE_UNITS = 32
DROPOUT_RATE = 0.2
LEARNING_RATE = 0.001- Python 3.9+
- pip or conda
# Clone the repository
git clone https://github.com/teckgeekz/lstm-prediction.git
cd lstm-prediction
# Install dependencies
pip install -r requirements.txt# Launch Jupyter
jupyter notebook Stock_Prediction_Production.ipynbOr run all cells end-to-end in one shot:
jupyter nbconvert --to notebook --execute Stock_Prediction_Production.ipynb \
--output executed_output.ipynbyfinance>=0.2.0
pandas>=2.0
numpy>=1.24
scikit-learn>=1.3
tensorflow>=2.13
matplotlib>=3.7
seaborn>=0.12
scipy>=1.11
The notebook reports four metrics on the held-out test set:
| Metric | Formula | Interpretation |
|---|---|---|
| MAE | Mean |actual โ predicted| | Dollar error on average |
| RMSE | โMean(actual โ predicted)ยฒ | Penalises large errors more heavily |
| MAPE | Mean |actual โ predicted| / actual ร 100 | Scale-independent % error |
| Rยฒ | 1 โ SS_res / SS_tot | Variance explained (1.0 = perfect) |
Quality thresholds used by the model:
MAPE < 5% โ โ
Excellent โ production ready
MAPE < 10% โ โ
Good โ use with regular monitoring
MAPE < 20% โ โ ๏ธ Acceptable โ consider architecture changes
MAPE โฅ 20% โ โ Poor โ retrain or redesign
======================================================================
FUTURE PRICE PREDICTIONS FOR SOL-USD
======================================================================
Day 1 (2025-05-04):
Predicted: $148.32
Range (95% CI): $141.18 - $155.46
Day 3 (2025-05-06):
Predicted: $151.07
Range (95% CI): $143.93 - $158.21
Day 7 (2025-05-10):
Predicted: $155.44
Range (95% CI): $148.30 - $162.58
======================================================================
Current Price: $146.88
======================================================================
Two-layer stacked LSTM (128 โ 64 units) with BatchNormalisation and Dropout between each block prevents overfitting and stabilises training on the high-variance SOL-USD series.
EarlyStopping with restore_best_weights=True automatically rolls back to the lowest-validation-loss checkpoint, eliminating the need for manual epoch tuning. ReduceLROnPlateau halves the learning rate when progress stalls, enabling fine convergence.
Future predictions include 95% confidence intervals derived from the standard deviation of test-set residuals, giving a principled uncertainty band rather than a single point estimate.
Exponential backoff retry logic handles transient yfinance API failures, and explicit MultiIndex column handling ensures compatibility with the new yfinance โฅ 0.2.x API structure.
- Wire engineered features (RSI, volatility, MAs) into LSTM input as multi-channel time series
- Implement iterative multi-step forecasting for 3- and 7-day horizons
- Add walk-forward cross-validation for more robust metric estimates
- Persist model with
model.save()and scaler withjoblib.dump() - Experiment with additional features: volume, on-chain metrics, BTC correlation
- Containerise with Docker for reproducible deployment
- REST API endpoint for real-time inference (FastAPI)
This project is built for research and educational purposes only. Price predictions from any machine learning model carry inherent uncertainty and should not be used as the sole basis for financial decisions. Always apply risk management when trading.
Contributions, issues, and feature requests are welcome.
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for details.
Made with precision by Teckgeekz
Building production-grade AI systems ยท Deep Learning ยท Time Series ยท Quantitative Finance
โญ Star this repo if you found it useful