Skip to content

A Deep RL model for stock prediction with reward mechanisms.

License

Notifications You must be signed in to change notification settings

sunnycqcn/Stock-Predictor-V4

 
 

Repository files navigation

Stock-Predictor-V4

stockpredictor ai logo


Content Table


1a. Installation

git clone https://github.com/Qerim-iseni09/Stock-Predictor-V4.git
cd Stock-Predictor-V4
python SPV4.py --install

1b. Installation with Virtual Environment (venv) in Python

git clone https://github.com/Qerim-iseni09/Stock-Predictor-V4.git
pip install venv
python -m venv Stock-Predictor-V4
cd Stock-Predictor-V4
source bin/activate # Execute before using any script
python SPV4.py --install
deactivate # Execute this command to deactivate the virtual environment

1c. Updating the Repository

python SPV4.py --update
python SPV4.py --install

2. Data Preparation

To prepare the data for stock prediction, you can follow either of the following options:

Option 1:

  1. Visit Yahoo Finance and choose a stock of your preference.
  2. Access the Historical Data tab and download the corresponding CSV file. Save it in the designated data folder. For example, you can use Bitcoin as an illustration (To avoid encountering an error, it is important to make sure that the data includes a timeframe of at least two years. Otherwise, the training process may fail, similar to the problem described in Issue #3.).
  3. Run the SPV4.py script by executing python SPV4.py --prepare_data and select the downloaded CSV file.

Option 2:

  1. Utilize the SPV4.py --generate_stock script to generate fabricated stock data for training your model, irrespective of the option you choose.
  2. Run the SPV4.py script by executing python SPV4.py --prepare_data and select the generated CSV file.

Upon completion of these steps, your downloaded/generated stock data will contain indicators that enhance the reliability of predictions.


3. Training the LSTM RL Model

To train the LSTM RL Model with the data.csv file that was generated by the 2. Step, execute the following:

python SPV4.py --train

After running this command, the LSTM RL model will start training with the data in the data.csv file.


4. Evaluating the Model

To evaluate the trained model, execute the following:

python SPV4.py --eval

After running this command, the root mean squared error (RMSE), the MAPE and Total Rewards will be plotted.


5. Fine Tuning the LSTM RL Model

To fine tune the model, execute the following:

python SPV4.py --fine_tune

Before starting the fine-tuning process for the LSTM RL model, the script will now ask you to specify your desired reward threshold. It is recommended to set the threshold at 0.9.

It is recommended to maintain hydration by drinking water while waiting for the fine-tuning process to complete, as this may take a while. Once the fine-tuning is done, attempt to run the script with a single loop. If the script doesn't loop once initially, keep rerunning it until it completes at least one loop. If the script consistently produces the same result without any improvement, please interrupt it by pressing CTRL + C, answer "yes" to the prompt, and rerun the script.

After the fine-tuning process is fully complete, it is highly recommended to re-evaluate the model's performance.


6. Utilizing the Model for Stock Market Prediction

Once the previous steps have been completed, the model can be utilized to forecast the stock market for the next 30 days beyond the latest date in the data. The predictions will be shown in the command line and saved as a CSV file.

To use the model for prediction, run the following command:

python SPV4.py --predict

And Happy Trading! However, please note that any losses incurred by utilizing the model's predictions are not the responsibility of the developer.


7. Comparing the predicted values with the actual values after the 30-day period.

If you've reached the end of the 30-day predicted period and you're curious about the accuracy of the model, then the script can help you. To compare the data, you need to update the CSV file you selected in Step 2.

After that, run the following command in your terminal:

python SPV4.py --compare

This will compare the predicted data with the actual data. You may regret some of the decisions you made and wonder why you didn't trust the model (just kidding, don't take it too seriously!).

About

A Deep RL model for stock prediction with reward mechanisms.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%