This is an attempt to forecast the closing price of a stock given its previous closing prices.
This repository contains:
- The python code
- The generated prediction graph
- The sample dataset
- ReadMe file itself
The dataset used in this repo is the historical data of Tata Consultancy Services (a company listed in National Stock Exchange, India) from August 12, 2002 to November 26, 2021. The dataset was scraped from Yahoo Finance using Selenium. The data from Selenium is parsed using BeautifulSoup and converted to their respective datatypes before storing it in the Pandas dataframe.
A stacked 2 layered-LSTM model followed by a Dense layer is employed. The inputs from the training dataset are concatenated with their true values whereas the inputs from the test dataset is concatenated with all zeroes. The model is expected to predict the true values of the test dataset. Shown below is a stacked LSTM model.
The hyper-parameters can be changed in the python file.
Forecasted price vs Actual price
Make sure you have the following libraries installed to run the code.
numpy
pandas
matplotlib
bs4
selenium
scikit-learn
plotly
keras
Download the following files in the same directory.
Code.py
Run Code.py
cd directory-where-the-files-are-saved
python3 Code.py