A statistical computations and ML orientated Python package to predict stock price.
Last updated Jun 29, 2026
37
Stars
2
Forks
0
Issues
0
Stars/day
Attention Score
58
Topics
Language breakdown
Jupyter Notebook 80.2%
Python 19.7%
Dockerfile 0.1%
โธ Files
click to expand
README
STA410 Stock Prediction System
Overview
This is a comprehensive Python package for stock price prediction that combines statistical time series analysis with advanced machine learning techniques. The system integrates traditional forecasting methods with gradient boosting models and Hidden Markov Models to provide accurate stock price predictions.Key Features
- Hybrid Modeling Approach: Combines ARIMA, exponential smoothing, gradient boosting, and custom models
- Extensive Feature Engineering: Automatically calculates technical indicators and market features
- Multiple Prediction Horizons: Supports forecasting at various time intervals
- Comprehensive Evaluation: Includes metrics and visualization tools for model assessment
- Easy Integration: Simple API for incorporating into existing workflows
Installation
pip install stock-prediction-sta410 For optimal performance, use NumPy version 1.26.4: pip install numpy==1.26.4 Quick Start
from stock_prediction.core.predictor import StockPredictor
from datetime import date
Basic usage with default settings
StockPredictor.full_workflow(
"2024-01-01",
date.today(),
companies=["AAPL", "MSFT"],
model="arimaxgb",
)
Core Components
StockPredictor
The main interface for interacting with the system. It handles data loading, feature engineering, model training, and forecasting.Modeling Approaches
- ARIMAXGBoost: A hybrid model combining ARIMA time series analysis with gradient boosting
- Hidden Markov Models: Captures underlying market regimes and state transitions
- Custom Gradient Descent: Specialized implementation with momentum and adaptive learning
Feature Engineering
The system automatically calculates numerous technical indicators:- Moving averages (50, 200, 7, 21-day)
- Momentum indicators (RSI, MACD, Williams %R)
- Volatility measures (Bollinger Bands, ATR)
- Volume indicators and external economic data
Custom Gradient Descent Implementation
The package features a custom GradientDescentRegressor that outperforms scikit-learn's standard SGDRegressor in several important ways:
(Here is the link to the complete notebook of the comparison.)
Performance Advantages


As demonstrated in our benchmark tests:
- Superior Convergence: Our implementation achieves lower MSE in both training and testing datasets
- Faster Optimization: Reaches optimal performance in fewer iterations
- Better Generalization: Maintains consistent performance on unseen data
Key Technical Innovations
- Advanced Initialization: Uses QR decomposition to determine optimal starting coefficients, dramatically improving convergence speed compared to random or zero initialization
- Momentum Optimization: Implements configurable momentum with RMSProp option to escape local minima and smooth gradient updates
- Hybrid Regularization: Combines L1 and L2 penalties with independent control, providing better model generalization for financial time series
- Domain-Specific Loss Functions: Incorporates directional accuracy into optimization objectives, recognizing that predicting price movement direction is often more important than exact values in financial markets
Advanced Usage
For more detailed examples, see the example usage script.from stock_prediction.core.predictor import StockPredictor
Create a predictor instance
predictor = StockPredictor(
"AAPL",
start_date="2023-01-01",
end_date="2024-01-01",
interval="1d"
)
Load and prepare data
predictor.load_data()
Prepare models
predictor.prepare_models()
Generate forecasts
forecast = predictor.onestepforward_forecast(
horizon=5,
model="arimaxgb",
refit=True
)
Print forecast results
print(forecast)
Architecture
The system is built with a modular architecture:stock_prediction/
โโโ core/
โ โโโ predictor.py # Main StockPredictor class
โ โโโ models.py # Implementation of prediction models
โ โโโ hmm_model.py # Hidden Markov Model implementation
โโโ utils/
โ โโโ preprocessing.py # Data preprocessing utilities
โ โโโ evaluation.py # Model evaluation functions
โโโ docs/
โโโ example_usage.py # Usage examples
Contributing
Contributions are welcome! Please feel free to submit a Pull Request or fork.Authors
Yue Yu (Undergraduate student at the University of Toronto)License
This project is licensed under the MIT License - see the LICENSE file for details.Disclaimer
This project is solely for educational purposes only. This repo may not be as capable of capturing the live market as hedge fund. Use the model at your own discretion and risk, and always consult with financial professionals before making any investment decisions.Wiki pages you might want to explore:
๐ More in this category