Skip to content
sstinivasPublic

About

stock prediction model

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPR - Stock Prediction & Research

A cross-platform stock prediction system combining deep learning (TensorFlow), time series forecasting (Prophet), and classical machine learning (XGBoost, Random Forest) for comprehensive market analysis.

Python 3.8+ TensorFlow License: MIT

Features

  • Multi-Model Ensemble: 9 models (LSTM, GRU, Conv1D, BiLSTM, Prophet×3, XGBoost, Random Forest)
  • 80+ Technical Indicators: Comprehensive feature engineering with automatic selection
  • Cross-Platform: Works on Windows, macOS (Intel & Apple Silicon), and Linux
  • Interactive UI: Streamlit web interface with real-time charts
  • Telegram Alerts: Automated notifications for predictions
  • Direction Accuracy: Targeting 70%+ prediction accuracy

Quick Start

Installation

# Clone the repository
git clone https://github.com/yourusername/SPR.git
cd SPR

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # Linux/macOS
# or: venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

Platform-Specific Notes

Windows
  • Install Visual C++ Build Tools if you get compilation errors
  • Use PowerShell or Command Prompt as Administrator for installation
macOS (Intel)
  • All packages should work out of the box
  • Use Homebrew Python: brew install python@3.10
macOS (Apple Silicon)
  • Install TensorFlow for Apple Silicon: pip install tensorflow-macos tensorflow-metal
  • Some packages may need conda-forge: conda install -c conda-forge prophet
Linux
  • Install build dependencies: sudo apt install python3-dev build-essential
  • For GPU support: Install CUDA toolkit and cuDNN

Basic Usage

# 1. Train models for a ticker (takes 10-20 minutes)
python train_model.py AAPL --period 2y

# 2. Get predictions
python run_prediction.py AAPL

# 3. Launch web interface
streamlit run streamlit_app/app.py

Command Reference

Training Models

python train_model.py TICKER [options]

Options:
  --period {6mo,1y,2y,3y,5y,10y}  Training data period (default: 2y)
  --sequence-length INT            Sequence length for LSTM/GRU (default: 60)
  -v, --verbose                    Show detailed output
  -vv                              Show debug output
  -q, --quiet                      Suppress all output except errors

Examples:
  python train_model.py AAPL                    # Train with defaults
  python train_model.py GOOGL --period 5y       # More training data
  python train_model.py MSFT -v                 # Verbose output

Running Predictions

python run_prediction.py TICKER [options]

Options:
  --period {3mo,6mo,1y,2y}  Context data period (default: 6mo)
  --send-alert              Send Telegram notification
  --no-save                 Don't save predictions to JSON
  --json-only               Output only JSON (for scripting)
  -v, --verbose             Show detailed output
  -q, --quiet               Suppress all output

Examples:
  python run_prediction.py AAPL                  # Basic prediction
  python run_prediction.py AAPL --send-alert     # With Telegram alert
  python run_prediction.py AAPL --json-only      # For scripts/automation

Evaluating Accuracy

python evaluate_accuracy.py TICKER [options]

Options:
  --period {3mo,6mo,1y}  Evaluation period (default: 6mo)

Example:
  python evaluate_accuracy.py AAPL GOOGL MSFT --period 6mo

Web Interface

streamlit run streamlit_app/app.py

Open http://localhost:8501 in your browser.

Project Structure

SPR/
├── config/keys.py           # Configuration and hyperparameters
├── data/
│   ├── loaders.py           # Data fetching from Yahoo Finance
│   └── selections/          # Feature selection JSONs per ticker
├── features/technicals.py   # 80+ technical indicators
├── models/
│   ├── tf_multi/models.py   # LSTM, GRU, Conv1D, BiLSTM
│   ├── prophet/             # Prophet time series models
│   └── classical/           # XGBoost, Random Forest
├── training/trainer.py      # Unified training pipeline
├── inference/predictor.py   # Prediction pipeline
├── streamlit_app/app.py     # Web UI
├── train_model.py           # Training CLI
├── run_prediction.py        # Prediction CLI
└── evaluate_accuracy.py     # Accuracy evaluation

Configuration

Edit config/keys.py to customize:

MODEL_CONFIG = {
    "lstm_units": [256, 128, 64, 32],  # LSTM layer sizes
    "dropout_rate": 0.3,               # Dropout for regularization
    "learning_rate": 0.0005,           # Adam optimizer LR
    "epochs": 150,                     # Max training epochs
    "sequence_length": 90,             # Days of history
}

Telegram Alerts (Optional)

  1. Create a bot with @BotFather
  2. Get your chat ID from @userinfobot
  3. Create .env file:
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id

Output Example

==================================================
PREDICTIONS FOR AAPL
==================================================
Current Price: $185.23
Ensemble Prediction: $187.45
Change: +1.20%
Signal: HOLD
Confidence: 65.0%

Individual Model Predictions:
  TensorFlow: $186.89
  Prophet: $188.12 (Range: $183.45 - $192.78)
  Classical ML: $187.34

Buy Confidence: 35.2%
Sell Confidence: 12.8%
==================================================

Models Overview

Model Type Description
LSTM Deep Learning 4-layer Long Short-Term Memory
GRU Deep Learning 3-layer Gated Recurrent Unit
Conv1D Deep Learning 1D Convolutional Network
BiLSTM Deep Learning Bidirectional LSTM
Prophet Time Series Facebook's forecasting tool (3 configs)
XGBoost Classical ML Gradient boosting
Random Forest Classical ML Ensemble decision trees

Documentation

Troubleshooting

Issue Solution
"No trained models found" Run python train_model.py TICKER first
"Insufficient data" Use longer period: --period 2y
TensorFlow GPU not detected Install CUDA toolkit or use CPU
Prophet installation fails Try: conda install -c conda-forge prophet
Telegram alerts not working Check .env file has correct credentials

License

MIT License - see LICENSE for details.

Disclaimer

⚠️ This software is for educational and research purposes only. It is not financial advice. Stock market predictions are inherently uncertain. Always do your own research and consult financial professionals before making investment decisions. Past performance does not guarantee future results.

About

stock prediction model

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages