- Stock-Predictor-V4
- 1a. Installation
- 1b. Installation with Virtual Environment (venv) in Python
- 1c. Updating the Repository
- 2. Data Preparation
- 3. Training the LSTM RL Model
- 4. Evaluating the Model
- 5. Fine Tuning the LSTM RL Model
- 6. Utilizing the Model for Stock Market Prediction
- 7. Comparing the predicted values with the actual values after the 30-day period.
git clone https://github.com/Qerim-iseni09/Stock-Predictor-V4.git
cd Stock-Predictor-V4
python SPV4.py --install
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
python SPV4.py --update
python SPV4.py --install
To prepare the data for stock prediction, you can follow either of the following options:
Option 1:
- Visit Yahoo Finance and choose a stock of your preference.
- 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.).
- Run the
SPV4.py
script by executingpython SPV4.py --prepare_data
and select the downloaded CSV file.
Option 2:
- Utilize the
SPV4.py --generate_stock
script to generate fabricated stock data for training your model, irrespective of the option you choose. - Run the
SPV4.py
script by executingpython 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.
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.
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.
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.
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.
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!).