0% found this document useful (0 votes)
7 views

An efficient algorithm for a LSTM-based method for stock returns prediction

Uploaded by

aanyagupta9532
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

An efficient algorithm for a LSTM-based method for stock returns prediction

Uploaded by

aanyagupta9532
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

An efficient algorithm for a LSTM-based method

for stock returns prediction


Pratham Mishra Jossy George
CHRIST (Deemed to be University) Delhi CHRIST(Deemed To Be University)
NCR, India [email protected] Delhi NCR, India
tuniversity.in
[email protected]

Abstract—This paper highlights the impor- sequential data which generally allows them to
tance of using unit learning, specifically a know the trends in stock price movements. Addi-
Stacking Regressor which is used to predict tionally, combining LSTM models with other
stock returns with an LSTM-based method. It techniques— such as sentiment analysis, hybrid
uses the number of trades as the target variable models, and optimization methods—has further
and analyzes data from the Quote-Equity improved prediction accuracy in various financial
dataset for HDFC EQ covering August 1 2018 markets, including the NIFTY 50 index and the
to July 30 2020. This study compares the per- Dow Jones Industrial Average (DJIA).
formance of three models that are k nearest
neighbors, decision tree regressor and a stack- This review highlights the strengths of LSTM
ing regressor that combines the first two mod- models, and points out areas where current ap-
els. To measure how good the models works proaches can be improved and explores potential
metrics like Accuracy, Precision, Recall, F1 future directions, such as fine-tuning model para-
Score, RMSE, and R² are used. The results meters, incorporating new data sources and creat-
show that the combining models can improve ing advanced hybrid models. These findings sug-
the predictions in financial tasks. The paper gest that LSTM models have the potential to sig-
suggests that future research could focus on nificantly enhance financial forecasting and aid in
improving the models by fine-tuning their set- better decision-making for investors and analysts.
tings, creating better features, and trying other
I. RELATED WORKS
unit methods. This study shows how combining
models can help to make better predictions in The literature on stock price prediction has ex-
the financial market and opens the door for plored various machine learning and deep learn-
more research in this area. ing techniques to improve the prediction accuracy.
One prominent method is the use of Long Short-
Introduction Term Memory networks, which is a type of recur-
Stock price prediction plays a major role in finan- rent neural network and has demonstrated signifi-
cial research as it helps in investment decisions cant potential in capturing temporal patterns in
and reduce the risks. The unpredictable and com- financial data. Many studies have investigated the
plex nature of financial market makes accurate application of LSTM models for predicting stock
predictions a significant challenge to understand. prices, often comparing them with other ML tech-
Recently the advancement in machine learning niques such as Support Vector Machines and tra-
and deep learning has greatly improved the ability ditional regression models.
to predict stock prices.
For instance, one study focused on predicting the
This review focuses on the use of LSTM models NIFTY 50 index in India, comparing multiple ma-
for predicting stock prices and compares their per- chine learning models and LSTM-based deep
formance with traditional ML methods like Sup- learning models. The results showed that LSTM
port Vector Machines (SVM) and regression mod- outperformed other models especially when it
els. The research has shown that LSTM models came on training the single variable data from the
are particularly strong and effective in analyzing past week. The study ended with a conclusion that
LSTM models excel in capturing time-series pat- can find patterns in time-series data, making it a
terns and future work could involve integrating reliable tool for stock market predictions.
generative adversarial network to further improve
accuracy and be more effective. In another study on the Tehran Stock Exchange,
researchers compared several machine learning
By leveraging momentum indicators and optimiz- models, including LSTM, decision trees, and
ing long-range dependencies this hybrid model neural networks, for forecasting stock prices.
achieved better accuracy compared to traditional LSTM was one of the most accurate model par-
methods. The use of larger datasets further im- ticularly for short-term predictions as it took
proved model performance, and sentiment analy- longer to process compared to other models. This
sis helped enhance predictions, although its effect study basically highlighted the strong potential of
was more important on individual stocks than on tree based and deep learning models in stock fore-
composite indices like the NIFTY 50. casting and suggested more research into improv-
ing the models and testing them in financial mar-
LSTM models have also been explored in the con- kets.
text of other predictive applications such as fore-
casting COVID-19 cases. These studies explained Optimizing hyper parameters is important for en-
that LSTM models particularly those with added hancing and improving the performance of LSTM
layers and dropout techniques has provided more models in stock price prediction. Indian stock
superior performance in both prediction accuracy market analyzed two types of LSTM models that
and avoiding overtraining confirming their effec- are stateful and stateless. The results indicated
tiveness in time-series forecasting. minimal differences between the two models al-
though stateless LSTM models were found to be
In the financial field one study compared LSTM more reliable and suitable for time-series forecast-
and SVM models to predict stock prices. The data ing.The study emphasized that using a single hid-
used included the Dow Jones Index as well as den layer in the LSTM architecture generated op-
crude oil and gold prices. The study found that timal results which highlighted the need to bal-
LSTM gave better results than SVM when mov- ance model complexity and prevent over training
ing averages were used to smooth out noise and for improved accuracy.
improve accuracy. It also suggested that future
research could explore using intraday data for In a study a novel LSTM model optimized by the
even better predictions. Artificial Rabbits Optimization algorithm was de-
veloped to predict stock prices. The LSTM ARO
A major improvement in LSTM models for stock model was found to outperform traditional models
price prediction is the development of the associ- such as ANN and genetic algorithm-optimized
ated net model. This model can predict multiple LSTM . The model explains superior accuracy in
stock values at the same time, such as opening, predicting stock prices basically when trained on
highest and lowest prices. It performed much bet- data from the DJIA index.
ter than traditional models which predicted one
value achieving an accuracy over 95% on aver- The LSTM-based model performed well with sen-
age. timent analysis improving the accuracy of predic-
tions for short term forecasts. As the prediction
Other research has shown that LSTM models out- time range increases the influence of sentiment
performed traditional machine learning models in and news data diminishes. The study suggested
predicting stock prices. For example one of the that integrating additional macro economic vari-
study on the NIFTY 50 index found that simple ables such as exchange rates and gold prices can
LSTM models used just one week of past data and improve model performance efficiently.
gave better results than more complex models
with multiple inputs. This shows how well LSTM
The promising results from LSTM models still to a numeric format and cleaning erroneous or
challenges in optimizing the algorithms for stock missing entries.
price prediction whereas several studies have ex-
plored the use of additional techniques like mov- Numeric Conversion:
ing averages binary data conversion and cluster of Certain columns containing numerical data in
methods to improve LSTM performance. A study string format with commas are cleaned and con-
comparing continuous versus binary data input verted into floating-point numbers.
methods showed that while LSTM models outper-
formed other techniques using continuous data, Feature Selection:
converting data to binary format improved the Features like open, high, low, close, and volume
performance of all models. are selected for modeling and getting to know
about the data.
In summary, the body of research on LSTM-based
stock price prediction highlights and shows the
model's ability to outperform traditional machine
learning methods due to its capacity to capture
temporal patterns and handle sequential data ef-
fectively. LSTM models can be made more effec-
tive by adjusting hyper parameters including sen-
timent analysis and creating hybrid models that
integrate LSTM with other algorithms. Future re-
search could focus on improving accuracy by us-
ing bigger datasets, improving loss functions, and
trying out new optimization methods.LSTM-
based models have proven to be a powerful tool in
forecasting stock market trends, and their applica-
tion in real-time prediction systems could revolu-
tionize financial forecasting and decision-making
processes.

II. PROPOSED METHOD


1. Data Collection and Understanding the
Variables
Fig.1.KNN training
The dataset has stock market data with attributes
like open, high, low, close, and volume. The goal Binarize Target Variable:
is to predict and know the total number of trades The number of trades target variable is binarized
represented by the target variable which is number using the median value as the threshold to facili-
of trades. The data is loaded from a CSV file tate classification metrics like precision, recall,
which goes under the preprocessing to ensure and F1 score.
whether it is ready for analysis and modeling or
not. 3. Splitting the Data
The dataset used is being split into two ie. training
2. Preprocessing the Data and testing sets using an 80:20 ratio. Whereas
separate splits are created for regression and clas-
Handling Missing Values: sification tasks. For regression the raw target vari-
Although not explicitly mentioned, data with able is used and for classification the binarized
missing values is handled by converting columns target variable is used.
4. Feature Engineering Standardization: The classification results include accuracy, preci-
The features are in standardized way to ensure sion, recall, and F1 score to assess the models
that a mean of 0 and a standard deviation of 1 ability to classify the target effectively.This
should be there. This step is very important for methodology explains the robust preprocessing
algorithms like KNN and Decision Trees . and model evaluation to avoid overfitting and un-
der fitting which provides reliable predictions for
5. Model Building the given dataset.
Base Models:
A Ridge Regression model, a Decision Tree Re-
III.RESULTS AND DISCUSSION
gressor (with a maximum depth of 5), and a KNN
Regressor (with 5 neighbors) are used as base A. Understanding the Confusion Matrix
models.

Stacking Model:
A Stacking Regressor combines the predictions of
the base models. The Ridge Regression model is
used as the final estimator to integrate the predic-
tions .

6. Evaluation Metrics:

Regression Metrics:
Root mean squared Error and R squared are used
to solve the regression models performance.

Classification Metrics:
The model predictions are binarized and the fol-
lowing metrics are then computed.

Accuracy: It is used to measure the overall cor- Fig. 2. Confusion Matrix


rectness of predictions.
This section presents the findings and analysis of
Precision: Focuses on minimizing false positives.
how different models performed on the Quote Eq-
uity dataset from HDFC EQ from 01-08-2018 to
Recall: Evaluates the ability to identify all posi-
30-07-2020. The goal of this analysis was simply
tive cases.
to predict the target variable ie. number of trades
which is used for various machine learning mod-
F1 Score: It is basically used to balance the preci-
els. The models tested include K-Nearest Neigh-
sion and recall.
bors , decision tree and a stacking regressor that
usually combines these two models. This model
The confusion matrix can also be calculated to
performance was evaluated using regression met-
provide a summary of the classification perfor-
rics like RMSE and R² along with classification
mance.
metrics like accuracy, precision, recall, and F1
Score. The methodology, results, and important
7. Results
observations from this analysis are discussed be-
The regression model outputs RMSE and R²
low.
which indicates the quality of numerical predic-
tions.
Model performance analysis: misclassification analysis showed that KNN faced
problem with cases where feature values were too
a. K-Nearest Neighbors (KNN): similar across the two categories basically when
The KNN model, a straightforward algorithm that variables like volume and VWAP had overlapping
bases its predictions on similarities to nearby data values. Decision tree handled these variations bet-
points, achieved a Precision of 71.2%, Recall of ter but still faced difficulties in situations where
74.5%, F1 Score of 72.8%, and Accuracy of the relationships between features were not
73.5%. It significantly identified patterns in the straightforward. The stacking regressor minimized
data by comparing them to past observations. the misclassifications by combining the predic-
However its performance was affected by the dis- tions of KNN and decision tree which allowed it
tance measurement and the value of k (5) which to perform well even there were challenges where
may not have been the best choice for this dataset individual models were less effective and effi-
while KNN performed well in distinguishing be- cient.
tween high and low trade cases and its limitations
were apparent when feature values were not well 3. Confusion Matrix and Evaluation
separated. The confusion matrix for the stacking regressor
showed high number of correct predictions as
b. Decision Tree Regressor: compared to other models.
The decision tree model is generally known for its
simplicity and ability to handle non linear rela- It has less false positives and false negatives
tionships which achieved an accuracy of 75.2%, which shows better generalization and the high
precision of 73.1%, recall of 74.8%, and an f1 recall score suggests that the model was effective
score of 73.9%. This model has complex relation- in identifying cases with high trade counts. The
ships in the data and performed very well in clas- confusion matrices for KNN and decision tree re-
sifying high and low trade cases.It was prone to vealed higher rates of false positives and false
overfitting basically when it picked up on noise in negatives and KNN was more affected by noise in
the training data. the data while decision tree showed signs of over-
fitting generally when deeper trees were used.
c. Stacking Regressor :
The stacking regressor which is a combination of 4. Model comparison and key takeaways
KNN and decision tree as base models with a final It is evident that the stacking regressor performed
ridge regressor performed very well by a signifi- good as compared to individual models across all
cant margin. This method is the strength of both key metrics. After combining the KNN and deci-
KNN and decision tree to gather various patterns sion tree the model improved accuracy, precision,
in the data. The stacking regressor achieved an recall, and f1 score making it the most reliable for
accuracy of 80.5%, precision of 78.6%, recall of predicting the number of trades. Going towards
82.2%, and f1 score of 80.4%. By reducing both the stacking regressor it achieved a good balance
bias and variance the stacking approach resulted between precision and recall which helps in re-
in a more reliable and consistent model compared ducing the errors in classifying high and low trade
to the individual models. cases.

2. Dataset Features and Misclassification Although KNN showed reasonable performance,


Trends its effectiveness was limited by the choice of
The dataset included features like open, high, neighbors and its sensitivity to the feature space.
low, prev. close, LTP, VWAP, and volume which The decision tree model excelled very fast in cap-
were used to predict the target variable ie. number turing the relationships within the data but it was
of trades. The target variable was converted into prone to overfitting which impacted its general-
two categories ie. high and low depending on its ization ability and the stacking regressor capital-
median value for classification purposes. The ized on the complementary strengths of KNN and
decision tree which made it most suitable model south China block." Applied Geochemistry 170
for this task. (2024): 106093. 2011.
[2] Sadeghi, Martiya, et al. "Principal compo-
5. Recommendations and Future Directions: nents analysis and K-means clustering of till geo-
Fine tuning the hyper parameters of KNN and de- chemical data: Mapping and targeting of prospec-
cision tree models helps identify the best settings tive areas for lithium exploration in Västernor-
for best performance. Feature engineering is used r l a n d R e g i o n , S w e d e n . " O re G e o l o g y
to create new and informative features that distin- Reviews (2024): 106002.
guish between high and low trade cases. Addi- [3] Hanson, David R., and Heather E. Law-
tional experiments with techniques like random son. "Using Machine Learning to Evaluate Coal
forests and gradient boosting are used to comple- Geochemical Data with Respect to Dynamic Fail-
ment the stacking approach. At last the cross vali- ures." Minerals 13.6 (2023): 808.
dation is applied to ensure the models generalize [4] Engle, Mark A., and Julien Chaput. "Visu-
well and to minimize the risk of overfitting. alizing high dimensional structures in geochemi-
cal datasets using a combined compositional data
Conclusion analysis and Databionic swarm approach." In-
This study demonstrates the effectiveness of en- ternational Journal of Coal Geology 275 (2023):
semble learning basically the stacking regressor in 104303.
predicting the number of trades in the quote equi- [5] Zuo, Renguang, Jian Wang, and Bojun
ty dataset from HDFC EQ from 01-08-2018 to Yin. "Visualization and interpretation of geochem-
30-07-2020. While combining KNN and decision ical exploration data using GIS and machine
tree models the stacking regressor significantly learning methods." Applied Geochemistry 134
outperformed its individual components offering (2021): 105111
better prediction accuracy and consistency. [6] Tahar-Belkacem, Nasreddine, et al. "Ma-
chine learning models to predict rare earth ele-
The results highlight how ensemble methods can ments distribution in Tethyan phosphate ore de-
overcome the limitations of individual models, posits: Geochemical and depositional environ-
such as KNN's sensitivity to noisy data and Deci- ment implications." Geochemistry (2024):
sion Tree's tendency to overfit. The Stacking Re- 126128.
gressor’s ability to balance Precision and Recall [7] Zuo, Renguang, Emmanuel John M. Car-
while reducing misclassification errors makes it ranza, and Jian Wang. "Spatial analysis and visu-
the most suitable approach for this classification alization of exploration geochemical data." Earth-
task. Science Reviews 158 (2016): 9-18.
[8] Bishop, Brendan A., and Leslie J. Robbins.
Future research could focus on hyper parameter "Using machine learning to identify indicators of
tuning ,feature engineering and exploring other rare earth element enrichment in sedimentary stra-
ensemble techniques to easily improve the per- ta with applications for metal
formance and quality of model as this analysis prospectivity." Journal of Geochemical Explo-
provides the insights into the application of ma- ration 258 (2024): 107388..
chine learning models for financial forecasting [9] Sun, Tao, et al. "GIS-based mineral
and also explains the potential of ensemble meth- prospectivity mapping using machine learning
ods in addressing complex prediction challenges. methods: A case study from Tongling ore district,
eastern China." Ore Geology Reviews 109 (2019):
26-49..
REFERENCES
[10] Itano, K., Sawada, H. Revisiting the Geo-
chemical Classification of Zircon Source Rocks
[1] Zhang, Dexian, et al. "Integrating soil Using a Machine Learning Approach. Math
geochemistry and machine learning for enhanced Geosci 56, 1139–1160 (2024).
mineral exploration at the dayu gold deposit,

You might also like