This repository contains a comprehensive project for predicting stock prices using historical data and machine learning techniques. The project includes data fetching, feature engineering, model training, evaluation, and visualization of predictions.
- Installation
- Project Overview
- Features
- Tech Stack
- File Structure
- Usage
- Logic and Implementation
- Contributing
- License
-
Clone the repository:
git clone https://github.com/mann-uofg/stock-price-prediction.git cd stock-price-prediction -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\\Scripts\\activate`
-
Install dependencies:
pip install -r requirements.txt
This project aims to predict stock prices based on historical data using machine learning models such as LSTM and Random Forest. It includes a visualization component to display historical and predicted prices along with trade volumes.
- Fetch historical stock data using the Yahoo Finance API.
- Implement feature engineering techniques like moving averages and technical indicators.
- Train machine learning models for stock price prediction.
- Evaluate models using metrics such as RMSE, MAE, and directional accuracy.
- Visualize historical prices, future predictions, and feature importance.
- Programming Language: Python
- Libraries:
- Data Handling:
pandas,numpy - Machine Learning:
scikit-learn,tensorflow - Visualization:
matplotlib,mplcursors - Data Fetching:
yfinance
- Data Handling:
src/
├── data/
│ ├── stock_data.py # Fetch stock data
│ ├── data_loader.py # Data loading logic
├── features/
│ ├── feature_engineering.py # Create features
│ ├── technical_indicators.py # Add technical indicators
├── models/
│ ├── lstm_model.py # LSTM model logic
│ ├── random_forest_model.py # Random Forest logic
├── visualization/
│ ├── plotter.py # Plot historical and predicted prices
│ ├── hover_annotations.py # Add hover annotations
└── main.py # Entry point for the project
-
Fetch stock data:
python src/data/stock_data.py
-
Train models:
python src/models/train_model.py
-
Visualize predictions:
python3 predict.py
- Data Fetching: Stock data is fetched from Yahoo Finance using the
yfinancelibrary. - Feature Engineering: Create new features to enhance predictive performance, such as moving averages and momentum indicators.
- Model Training: Train models like LSTM for time-series forecasting and Random Forest for feature-based predictions.
- Evaluation: Use evaluation metrics like RMSE and MAE to compare model performance.
- Visualization: Plot historical stock prices, predicted values, and trade volumes using
matplotlib.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name. - Make your changes and commit them:
git commit -m 'Add feature'. - Push the changes:
git push origin feature-name. - Submit a pull request.
This project is licensed under the MIT License.