Skip to content

kongchenglc/QuantitativeTrading

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📈 Quantitative Trading: Nvidia Stock Prediction 🚀

The project includes a predictive model that generates trading signals ( buy / sell / hold ) for Nvidia’s stock based on historical data using an LSTM-based neural network.

You can run the model directly, and the predicted signal for the next trading day will be displayed in the command line:

python -m models.model_loder.lstm_loader

Screenshot on 2025-07-08:

Results (2024-12-05 to 2025-07-08):

  • Initial Capital: $10,000.00
  • Final Portfolio Value: $15,385.39
  • Strategy Return: +53.85%
  • Buy & Hold Return: +10.30%
  • Max Drawdown: 17.80%
  • Sharpe Ratio: 1.64
  • Win Rate: 55.00%
  • Total Trades: 120

Hope this helps you get rich 💰 — or at least lose money more elegantly. 💸

If this project makes you rich, feel free to buy me a coffee ☕ or a Tesla 🏎️.


🧠 LSTM Stock Prediction Model

The LSTM model is designed to predict the closing prices of Nvidia stock based on historical price data. It uses a sequence-based model where past prices are used to predict future prices.

Key Components:

  • LSTM Model:
    • Input: Historical closing prices (last n_steps days).
    • Output: Predicted closing price for the next day.
    • The model is built using PyTorch and consists of an LSTM layer followed by a fully connected layer.
  • Data Preprocessing:
    • The data is normalized using MinMaxScaler.
    • The dataset is split into training and testing sets, with a rolling window approach for time-series prediction.

Usage:

  1. Train the Model:
    Use the StockPredictor class to preprocess the data and train the model.
python main.py

Use Optuna to get the best hyperparameters:

python -m util.optuna_tuner.py
  1. Predict:

Install the required dependencies. Then, run the following command to generate the predictive trade signal for the next day:

python -m models.model_loder.lstm_loader

📌 Current Features

  • Data Collection

    • Historical Stock Price Analysis:
      Utilizes the Yahoo Finance API to fetch Nvidia (NVDA) stock data, while also computing key technical indicators:
      • Simple Moving Averages (SMA)
      • Exponential Moving Averages (EMA)
      • Relative Strength Index (RSI)
      • MACD (Moving Average Convergence Divergence)
      • Bollinger Bands
    • Macro-Economic Data:
      Leverages the Federal Reserve Economic Data (FRED) API via the fredapi package to obtain:
      • Interest Rates
      • Inflation Rates
      • Unemployment Rates
      • GDP Data
    • News & Sentiment Analysis:
      Scrapes Nvidia-related news from the Google News RSS feed and computes sentiment scores using VADER.
  • Stock Prediction Model (LSTM)

    • LSTM-based Stock Price Prediction:
      Implements a Long Short-Term Memory (LSTM) model to predict Nvidia's stock closing prices based on historical data.
    • Features:
      • Trains on historical stock data, incorporating sequence-based time series analysis.
      • Predicts closing prices for the next day.

🛠 Installation

Ensure you have Python 3.8+ installed. Then clone the repository and install the required dependencies:

git clone https://github.com/kongchenglc/QuantitativeTrading.git
cd QuantitativeTrading
pip install -r requirements.txt

⚠️ A FRED API key is required

Conda

  1. If you are using Conda, you can create a new environment by running conda env create -f environment.yml.
  2. This command will create a new Conda environment for you with the dependencies declared in environment.yml.
  3. Once Step 2 finishes, activate the environment: conda activate nvidia-quantitative-stock
  4. You can now run the scripts 🎉

About

Nvidia Stock Prediction

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages