Skip to content

Repository files navigation

Stock Trading Bot with Deep Learning

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.

Database

  1. Install Kaggle Dataset from https://www.kaggle.com/datasets/jacksoncrow/stock-market-dataset
  2. pip install -r requirements.txt to install all dependencies

Project Phases

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.

Pre-Trained Models

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

Features

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.

Installation

To get started, clone the repository and install the required packages.

Copy code

  1. git clone https://github.com/your-username/stock-trading-bot.git

  2. cd stock-trading-bot

  3. pip install -r requirements.txt

Data Preparation:

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.

Running the Models:

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.

Running the deployable app (app.py)

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 seaborn

Then start the app:

python app.py

Choose 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.

Hosting on Gradio (Hugging Face Spaces)

To host the app online so others can use it (e.g. for your portfolio):

  1. Create a free account at huggingface.co.
  2. Create a New Space → choose Gradio as the SDK.
  3. Upload app.py, requirements.txt, and your archive/stocks/ folder (with CSV files) to the Space.

See HOSTING.md for step-by-step instructions and troubleshooting.

Gradio Interface:

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.

Evaluation Metrics

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

Releases

Packages

Used by

Contributors

Languages