Stock Prices Prediction Using Long Short-Term Memory (LSTM) Model in Python

Bee Guan Teo
The Handbook of Coding in Finance
7 min readOct 26, 2021

--

Photo by Alesia Kozik from Pexels

Long Short-Term Memory (LSTM) is one type of recurrent neural network which is used to learn order dependence in sequence prediction problems. Due to its capability of storing past information, LSTM is very useful in predicting stock prices. This is because the prediction of a future stock price is dependent on the previous prices.

In this article, we will go through the steps to build a LSTM model to predict the stock prices in Python.

Disclaimer: The writing of this article is only aimed at demonstrating the steps to build a LSTM model to predict stock prices in Python. It doesn’t serve any purpose of promoting any stock or giving any specific investment advice.

Prerequisite Python Packages

  1. yFinancehttps://pypi.org/project/yfinance/
  2. Numpy https://numpy.org/
  3. Matplotlibhttps://matplotlib.org/
  4. Pandashttps://pandas.pydata.org/
  5. Scikit-Learn https://scikit-learn.org/stable/
  6. Tensorflow https://www.tensorflow.org/

Github

The original full source codes presented in this article are available on my Github Repo. Feel free to download it…

--

--