Introduction This project explores the application of deep learning techniques to predict stock prices. We developed a custom Convolutional Neural Network (CNN) and experimented with pre-trained models like ResNet50, InceptionV3, and DenseNet121. The goal is to predict stock prices based on historical market data and make informed trading decisions. This repository includes the implementation of the models, data preprocessing, evaluation, and deployment using a user-friendly interface.
- Install Kaggle Dataset from https://www.kaggle.com/datasets/jacksoncrow/stock-market-dataset
- pip install -r requirements.txt to install all dependencies
Custom CNN Model: Developed a CNN model to predict stock prices from historical market data. Pre-Trained Models: Fine-tuned pre-trained models (ResNet50, InceptionV3, DenseNet121) for stock price prediction. Ensemble Model: Combined predictions from multiple models using an ensemble approach. Deployment: Created a Gradio interface for user interaction and prediction visualization.
ResNet50: (https://keras.io/api/applications/resnet/#resnet50-function)
InceptionV3: https://keras.io/api/applications/inceptionv3/
DenseNet121: https://keras.io/api/applications/densenet/#densenet121-function
Stock Price Prediction: Predict future stock prices based on historical data.
Custom and Pre-Trained Models: Utilize both custom CNN and pre-trained models.
Ensemble Learning: Combine predictions from multiple models for improved accuracy.
User Interface: Interactive Gradio interface for easy user interaction.
To get started, clone the repository and install the required packages.
Copy code
-
git clone https://github.com/your-username/stock-trading-bot.git
-
cd stock-trading-bot
-
pip install -r requirements.txt
Ensure that the stock data is available in the archive/stocks directory. Each stock's data should be in a separate CSV file with the stock symbol as the filename.
You can run the setup.ipynb Jupyter notebook to train the models and make predictions. The notebook includes detailed steps for data preprocessing, model training, and evaluation.
The web app uses data from archive/stocks (CSV files). Install dependencies in the same environment you use to run the app:
# If you use a virtual environment, activate it first, e.g.:
# source venv/bin/activate (macOS/Linux)
# .\venv\Scripts\activate (Windows)
pip install -r requirements.txt
# or at minimum:
pip install yfinance tensorflow gradio pandas numpy matplotlib scikit-learn seabornThen start the app:
python app.pyChoose a stock and click Predict to use the default Last 3 years range. The Date range menu also offers Last 1 year, Last 5 years, and All available history. Presets use the latest date in the selected stock's CSV and stay within its available history. Choose Custom to edit the start and end dates manually. Selecting another stock refreshes the dates for its data.
If you see missing graphs or TensorFlow errors, run the pip install commands above in that environment and restart the app.
To host the app online so others can use it (e.g. for your portfolio):
- Create a free account at huggingface.co.
- Create a New Space → choose Gradio as the SDK.
- Upload
app.py,requirements.txt, and yourarchive/stocks/folder (with CSV files) to the Space.
See HOSTING.md for step-by-step instructions and troubleshooting.
Launch the Gradio interface for an interactive experience.
Gradio Interface
The Gradio interface allows users to:
Select a stock symbol.
Set initial capital, start, and end dates.
View predicted prices, plots, and trading decisions.
The interface also includes a chatbot for quick stock-related queries.
The models were evaluated using the following metrics:
Mean Squared Error (MSE)
Mean Absolute Error (MAE)
R-squared (R²)
Confusion Matrix
ROC Curve
Precision-Recall Curve