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
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 🏎️.
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.
- 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.
- Input: Historical closing prices (last
- 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.
- Train the Model:
Use theStockPredictor
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
- 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
-
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 thefredapi
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.
- Historical Stock Price Analysis:
-
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.
- LSTM-based Stock Price Prediction:
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
- Head over to https://fred.stlouisfed.org/docs/api/api_key.html to generate an API key
- Once you generate a key, create an
.env
file in the root directory of the repo - Add your API key here as
FRED_API_KEY=<your key>
- If you are using Conda, you can create a new environment by running
conda env create -f environment.yml
. - This command will create a new Conda environment for you with the dependencies declared in
environment.yml
. - Once Step 2 finishes, activate the environment:
conda activate nvidia-quantitative-stock
- You can now run the scripts 🎉