This app uses a machine learning model to predict today's closing price of a given stock. The model is trained on historical data of the Microsoft stock (NYSE: MSFT), starting when the company went public in 1986 to March of 2022.
Below is a sneak peek of the dataset used to train the model:
In this dataset, Open
, High
, Low
, and Close
are the opening, highest, lowest, and
closing prices of the stock on a given day. Volume
is the number of shares traded on that
day. Adj Close
is the closing price adjusted for stock splits and dividends.
The model is a Long Short-Term Memory (LSTM) neural network. It is a type of recurrent neural network (RNN) that is able to remember information from previous time steps. LSTM is widely used to analyze time-series data, such as stock prices, because it allows the model to learn from past data to make predictions about future data.
The dataset is split 90:10 into training and testing data, respectively. The model is trained on the training data and then tested on the testing data. The graph below shows the model's predictions on the testing data. The blue line is the actual closing price of the stock, and the orange line is the predicted closing price of the stock.
This graph provides us a sense of the model's accuracy. At the moment, the model is able to predict the general trend of the stock's closing prices but overestimates the magnitude of the price changes. We will continue to fine-tune the model in the future.
Using Streamlit
, we created a dashboard interface where you can predict the closing price of select stocks in real-time.
Click here to try it out!
- Clone this repository
- Install TensorFlow and the tensorflow-metal PluggableDevice on your machine following these instructions
- In the terminal,
cd
to this project's directory - Create a new conda environment with
conda create --name myenv
(wheremyenv
is the name of your new environment) - Activate the environment with
conda activate myenv
- Run
while read requirement; do conda install --yes $requirement || pip install $requirement; done < requirements.txt
. This command will install all the packages listed inrequirements.txt
using conda if possible, otherwise it will use pip - Create a file to track packages installed with conda vs pip:
conda env export > environment.yml
- Verify that the new environment was installed correctly:
conda env list
orconda info --envs
- In VS Code, open the
model.ipynb
file and change to the kernel associated with your conda environmentmyenv
- When running the first block that imports packages, you may get a prompt that asks you to install supporting jupyter extensions. Click "Install" and restart VS Code
If you encounter ERROR: Failed building wheel for h5py
during this process, follow the top answer in this StackOverflow thread.