You are on page 1of 7

STOCK PRICE PREDICTION USING FUNDAMENTAL ANALYSIS WITH LSTM

Akshat Uniyal, Rahul Goel

Dept. of Computer Science and Engineering, SRM, Chennai, India

---------------------------------------------------------------------***---------------------------------------------------------------------
also plays an significant role in the growth of
the country's industry and commerce, and
ultimately affects the country's economy. Investors
Abstract – and the industry are both involved in the stock
market and want to know if certain stocks will
fluctuate over a certain period of time. The stock
Stock market forecasts have always attracted the market is the main source for any company to
attention of many analysts and researchers. raise capital to expand its business. It is based on
Popular theories hold that the stock market the concept of supply and demand. If the demand
is essentially a random walk and  that for the company's stock is higher, the company's
it's  a stupid game to try to predict them. stock price goes up, and if the demand
Predicting stock prices is in itself a difficult for the company's stock is low, the company's
problem due to the number of variables involved. stock price goes down.
In the short term, the market acts like a
voting  machine, but in the long term it acts like a The National Stock Exchange of India
weighing machine and thus can predict  market ( abbreviated as NSE) is the main stock exchange
movements over a longer time frame. Stock Price of India, located in Mumbai. NSE was founded in
prediction’s integration with modern technology – 1992 as the nation's first language-
particularly Machine Learning Algorithm (Quant free electronic exchange. NSE is the first exchange
models as they are referred to in the financial in the country to offer a modern, fully automated
world) is recently becoming a growing topic. screen-based electronic trading system,
Research has shown that Machine Learning providing easy trading facilities for investors
Models particularly with the use of Recursive across the country.
Neural Networks (RNN) and Long-Term Short
Memory (LSTM) when applied to historical data of The main motive to correctly predict stock values
stocks can be used to predict short-term stock and prices in the short and long term is to
prices. Our model applies companies’ projections maximise your potential earnings rather than
as well as sector performances and how the given relying on tips. A great amount of research has
company fares accordingly to correctly predict gone into developing Machine Learning models
stock prices for both short- and long-term goals. that are capable of correctly predicting stock prices
and have been used by hedge funds and investment
Keywords – Stock Price Prediction, Machine banks for quite some time now. However these
Learning, Recursive Neural Networks, Long Short- models are mainly used to predict short term prices
term Memory, Company Projections so that they can be utilised in intraday trading and
most long term models generally focus on indices
and option chains. 
1.INTRODUCTION
The efficiency of various prediction models can be
debated as many can’t predict long term
Stock market forecasting and analysis involves fluctuations and compare the current stock value as
attempting to determine the future value of compared to it’s current trading price 
a company's stock or other exchange- which takes into account the sector
traded financial instrument. The stock market is a performance(For Eg: The existing share of a stock
very significant part of the country's economy, it let suppose Reliance declines in the Oil Sector as
compared to its projections signalling a down Soheila Abrishami, et al., Economic Time Series
quarter but it’s price value doesn’t fluctuate much Prediction is a sizable task, collected
leading to the assumption that a correction is in attracts the attention of many researchers and is
order which will result in large volumes of shares extremely important to investors.
being sold and the stock price taking a hit).  This article focuses on introducing a deep
learning system that uses a series of data about a
Fundamental Analysis refers to concept of using portion of a stock on the NASDAQ stock exchange
underlying financial records published by the to predict a stock's value. This model is trained on
company and taking other competitors’ data and the smallest data for a particular stock and
comparing them to correctly predict the short- and accurately estimates the final value of that stock in
long-term prices. multiple steps. It includes an autoencoder to
remove noise and uses time series data engineering
Due to the involvement of a great number of to provide enhanced features with the original
industries and companies, it contains very features. These new features are fed to the
large datasets from which it is difficult to extract stacked LSTM autoencoder for multi-step estimati
information and analyze their working on of final stock
trends manually. The application developed in this value. Furthermore, this estimate is used under
project, not only helps in prediction the future the profit maximization method to provide support
movement of the stock in the market, but also at the right time to buy and sell a particular stock.
automates the data retrieval, trend analysis, The results indicate that
predictive analysis and insights generation of a the proposed framework outperforms modern time
stock, just at the click of a button.  series forecasting methods in terms of analytical
accuracy and efficiency.
Stock market analysis and forecasts will reveal
market trends and predict when to buy stocks. [3] LSTM Method for Bitcoin Price Prediction: A
Successfully predicting the future price of a stock Case Study Stock Market Yahoo Finance, IEEE
can generate substantial profits. This is done using 2019- Ferdiansyah et al., Bit-coin is
large 12-month historical market data in this a cryptocurrency and is currently one of the first.
project, to represent various conditions invest in the stock market. The stock market is very
and confirm that time series models have risky
significant predictive power over Statistical And bitcoin is a cryptocurrency that has been
side for high probability trading and high return for steadily rising in price in recent years,
competitive business investment. sometimes dropping suddenly without knowing if
it had any effect on the stock
market. Automated tools are required to
2. LITERATURE SURVEY predict bitcoin on the stock market due
to its volatility. This study investigates how
[1] Research on Legitimate Neural Network to generate bitcoin stock market prediction mode
Based Stock Price Prediction Method, IEEE 2019 predictions using LSTM. Before confirming
- Sayavong Lounnapha et al. This paper aims the results, the paper tries to measure the results
at a stock price prediction model that focuses on using RMSE (square root squared error). RMSE
complex neural networks with outstanding self- will always be greater than or equal to MAE. The
learning ability. The dataset is taught and RMSE metric evaluates how well the model
tested regarding the behaviors of both the can compute continuous values. The method
cumulative neural network and the Thai stock applied in this study to predict bitcoin on the yahoo
market price predictions. The accuracy financial stock market can
of predictions is high and it can also be promoted forecast results above 12600
in the financial sector. USD in the next two days after the prediction.

[2] Enhancing returns by predicting stock [4] Stock Price Prediction Using Machine


prices using Deep Neural Networks, IEEE 2019- Learning Techniques, IEEE 2019-Jeevan B et
al., Recently, stock market has anonymous facts. The performance of the
been in the news with more and more academics model was analyzed by comparing the actual data
and companies interested to it. This article mainly and the predicted data using an RNN graph.
discusses stock price prediction approach using Machine learning to predict stock prices
RNN (Regenerating Neural Network) and LSTM because the model can predict stock prices very
(Long Term Short Term Memory) on National close to the actual price, where the model captures
Stock Exchange using multiple factors. detailed feature and uses different strategies to
factors such as current market prices as well as make predictions. The model trains for all
anonymous events. Recommendation system as NSE Internet data and recognizes the input
well as models built on RNN and LSTM and groups it and provides the input based on the
methods used to select companies are also user configuration. This RNN-
mentioned in this article. based architecture has been shown to
be very effective in predicting
[5] Stock Market Prediction Using Machine performance by modifying the
Learning Techniques, IEEE 2020- Naadun configuration accordingly, which also uses back-
Sirimevan et al., Stock prices play an propagation during the acquisition. and group data
important role in today's economy. The researchers to avoid data mixing.
found that social media platforms such
as Twitter and web news tend to influence [8] Stock Market Forecasting Using
the decision-making process of any individual. In Machine Learning, IEEE 2016 - Mehak Usmani,
this study, behavioral reflexes to web Syed Hasan Adil, Kamran Raza, Syed Saad Azhar
news are taken into account to reduce the gap and Ali. The main objective of this study was [6] to
make predictions much more accurate. forecast the market performance of the Karachi
Accurate predictions were made one day, one Stock Exchange (KSE) at the end of the day using
week, and two weeks later. machine learning algorithms. A variety of
attributes such as market entry and positive and
[6] Stock Market Forecasting by Machine negative forecasts are predicted using predictive
Learning, IEEE 2018 - Ishita Parmar, Ridam modeling. Features used in the template
Arora, Lokesh Chouhan, Navanshu Agarwal, include Oil Rates, Gold and Silver Rates, Interest R
Shikhin Gupta, Sheirsh Saxena, Himanshu ates, Exchange Rates (FEX), NEWS and Social
Dhiman. In this article, we study the Media Feeds.
use of [3] regression and LSTM-based Machine learning algorithms including One Layer
machine learning for stock price prediction. Perceptron (SLP), Multi-Layer Perceptron (MLP),
The measured elements are open, close, Radial Basis Function (RBF), and Support Vector
low, high, and volume. This paper is an attempt to Machine (SVM) were compared.
determine the future stock price of a company with The MLP algorithm is a multilayer
improved accuracy and reliability using machine perceptron that obtains the best results compared to
learning techniques. The LSTM algorithm gave a different methods. The most
positive result with more accuracy in predicting useful feature for predicting the market is the oil
stock prices. rate property. The final results of
this study confirm that machine learning
[7] Stock Price techniques are capable of predicting stock market
Prediction Using Machine Learning, IEEE 2018 - performance. The multi-layer Perceptron machine
Jeevan B, Naresh E, Vijaya kumar BP, Prashanth learning algorithm correctly predicted 70% of
Kambli. This paper is mainly [5] based on the market performance.
the action course prediction approach using long-
term short-term memory (LSTM) and recurrent [9] Predictive Model Development for Stock
neural network (RNN) to predict the value of the Analysis, IEEE 2017 - R. Yamini Nivetha, Dr. C.
action. on NSE data using various factors such as Dhaya. The relative study of three algorithms
market price currents, price-to- namely - Multi-Linear Regression (MLR), Support
earnings ratio, fundamental value and other Vector Machine (SVM) and Artificial Neural
Network (ANN) is the main goal of Fig 1: Graph of the closing price of Microsoft
this research. To predict the market price plotted
for the next day, the forecast will be determined
by the monthly forecast and the daily forecast. Sent For analysing the true value of the stock – two
iment analysis with best prediction measures are taken – The Price/Earnings ratio (P/E
algorithm predicts stock prices. The least ratio) Price/earnings ratio - also often called
developed algorithm is the multilinear the price to earnings ratio or the P/E ratio - is a
regression algorithm to calculate the correlation finance indicator that measures a company's stock
between volume and stock price. The results of the price concerning earnings per share. In simple
study show that words, it shows the balance between price and
earnings from the stocks. Thanks to this ratio, we
deep learning algorithms [10] are can see how profitable it is to buy shares of a
more advanced than MLR algorithms and SVM specific company.
algorithms. Also, we can use the P/E ratio to determine if
shares are over- or undervalued. For example, if
[11] Stock Price Prediction Based on Information you consider two companies in the same industry,
Entropy and Artificial Neural Networks, IEEE but with entirely different values of the P/E ratio, it
2019 - Zang Yeze, Wang Yiying might mean that the valuation of one of them is not
believable. 

3. METHODOLOGY
The model was implemented on Jupiter
Notebooks using python libraries like pandas,
matplotlib, NumPy and yahoo finance. The
objective was to predict stock prices using
numerical, fundamental and sentiment analysis of
companies. The data was first imported from the The P/E ratio can be calculated from the basic
yahoo finance library of share prices which EPS (earnings per share) by taking the current
records all the changes in the stock prices on an price of the stock and dividing it by
interval of 5 minutes as provided by the share’s the earnings received per share. The other measure
stock exchange – NASDAQ, DOW JONES, NIFTY is the price-to-sales ratio, also known as the ratio.
etc. In this particular testing model, we have used Since sales are often referred to as earnings, the
the Microsoft share and we have created the data P/S ratio is also very often referred to as price-to-
frame based on the closing prices of the share earnings or price-to-earnings ratios. . It is mainly
daily and plotted them using matplotlib. A used to measure how much the current market
minmax scaler was then applied onto it for the values that particular stock.
purpose of rescaling all the values in the scale
[0,1] and the reshaped model was then trained This ratio is often used with the well-known P/E
using Long Short-Term Memory and the model ratio to gauge how attractive a company
was then successfully compiled. is compared to its peers. The lower the price-to-
sales ratio, seemingly the more undervalued the
company is, and the more "buy" the
stock qualifies. For example, if company Y has
a price-to-sales ratio of 1.5 times, it can be
argued that company Y is undervalued compared
to company X. Therefore, it makes sense to buy
company Y and sell company X.

While the price-to-sales ratio is a strong investment
metric, it is advisable to only compare it with
similar companies. It makes no sense to compare Fig2 : Closing prices LSTM Model
the price-to-revenue ratio of an oil and gas
company, like Shell, with a technology company,
like Google, because the two
operate in radically different ways. 4. CONCLUSION
The trained model was able to predict closing
prices for the dataset to within 0.93 points of the
closing price and did well in the long-term
predictions as well. The main area where the
prediction was off by a margin was the Covid
crash of 2020 which could not possibly have been
predicted by company values and historical data.
Using the above metrics the data was scaled with
However, to solve this issue – sentiment analysis
the help of a MinMax Scaler and prepped for
can be used on news headlines pertaining to the
testing and the LSTM principles were applied on
stock in question and call/put options can be
the data. The Long-Term Short-Term Memory
provided accordingly.
Network is an advanced form of Recurrent Neural
Network , a sequential network, that allows
information to persist. It can handle the vanishing
gradient problem faced by RNNs. A cyclic neural
network is also known as RNN and is used for
persistent memory. Note for the LSTM
layer, units is the number of LSTM neurons in the
layer. 50 neurons will give the model high
dimensionality, enough to capture the upwards and
downward trends. return_sequences is True as we
need to add another LSTM layer after the current
one. input_shape corresponds to the number of
time stamps and the number of indicators. For
dropout, 20% of 50 neurons will be ignored
randomly during each iteration of training.
Following the above same method, added 2nd, 3rd,
and 4th LSTM layer. The data was then scaled
back to the initial format and the model’s Fig 3: Trained results v actual comparison
predictions were compared with the actual closing
price.  5. REFERENCES
[1] Chiu, D.Y., & Chen, P.J. (2009). Dynamic
exploration of the internal mechanism of the stock
market using fuzzy-based support vector machines
with high-dimensional input spaces and genetic
algorithms. Expert System with App, 36 (2), 1240-
1248.

[2] Chong, E., Han, C. and Park, F.C. (2017). Deep


learning networks for stock market analysis
and forecasting: Methodology, Data
Presentation, and Case
Study. Expert System with Application, 83, 187-
205.
[3] Dai, W
, Wu, J.Y., & Lu, C.J. (2012). Combination of [12] Kim, K. J., & Han, I. (2000).
nonlinear independent component analysis and Genetic algorithm approach for feature
neural network to predict Asian improvement in artificial neural network for stock
stock indices. Expert System with Application, 39 index prediction
(4), Expert System with App, 19 (2), 125-132.
-4452. [13] Kim, K.J., & Lee, W.B. (2004). Stock
market forecasting using artificial
[4] Das, S.P., & Padhy, S. (2012). Support neural network with optimal feature conversion.
vector machine to predict Indian stock market Computers and Neural Applications, 13 (3), 255-
futures price. International Journal of Computer 260.
Applications, 41 (3).
[5] Dash, R. & Dash, P
K. (2016). A stock trading framework that
combines technical analysis with machine learning
techniques. Journal of Finance and Data Science, 2
(1), 42-57.

[6] Enke, D., & Thawornwong, S.


(2005). Using data mining and neural networks to
forecast stock market returns. Expert Systems
with Applications, 29 (4), 927-940,444 

[7] Goodhue, D. L., & Thompson, R. L.


(1995). Adapting to the technology
of individual tasks and performance
Quarterly MIS, 213-236.

[8] Guresen, E., Kayakutlu, G., &


Daim, T.U. (2011). Using artificial
neural network model in predicting stock indices. E
xpert System with Application, 38 (8), 10389-
10397.

[9] Holland, J.H. (1992). Adaptation in natural and


artificial systems: an introductory analysis with
applications to biology, control and artificial
intelligence. You press MIT.

[10] Jasic, T., & Wood, D


(2004). Daily stock index trading returns based on
neural network predictions: a case study for the
S&P 500, DAX, TOPIX and FTSE 1965-
1999. Applied Financial Economics, 14 (4), 285-
297.

[11] Kim, H.J., & Shin, K. S. (2007). A combined


method based on neural networks and genetic
algorithms for detecting timed patterns
in the stock market. Application soft calculator, 7
(2), 569-576.

You might also like