Research Paper by Rahul Sharma
Research Paper by Rahul Sharma
1. Introduction
Predicting the future of the Indian stock market using machine learning has been a topic of
increasing interest. "Return prediction by machine learning" involves using advanced
algorithms to forecast stock price movements based on historical data. This helps investors
make more informed decisions regarding buying and selling stocks.
The Indian stock market is known for its volatility, and having a reliable tool to forecast
these fluctuations can be highly beneficial. Machine learning models, such as those based
on historical stock prices and other influential factors, attempt to predict the market's
direction. Understanding and leveraging machine learning can provide investors with a
competitive edge. This paper explores the application of machine learning to stock market
predictions, focusing on specific techniques like ARIMA, LSTM, and CNN.
Fama (2024) introduced the Efficient Market Hypothesis, asserting that current stock prices
fully reflect all available information. Additionally, the Random Walk Hypothesis posits that
stock prices change independently of their history, making accurate predictions theoretically
impossible. However, contrary to these ideas, other researchers argue that stock prices can
be predicted to some extent, utilizing various disciplines like economics, statistics, and
computer science (Lo & McKinlay, 1999).
2. Methodology
This section explains the methodology used for stock price prediction using Python libraries
and machine learning techniques.
Several Python libraries are employed for data analysis and model
implementation:
Techniques
The goal variable for forecasting is a time series dataset called y. We use a nested loop
technique to get the ideal p and q parameters. Predefined lists of potential values for p and
q are called p_params and q_params, respectively. The ARIMA function is used to fit an
ARIMA model with the order (p, 0, q) to the data for each combination of p and q.
LSTM Layer
To capture long-term dependencies and sequential patterns, an LSTM layer with 50 units is
added to the model. The rectified linear unit (ReLU) activation function is employed within
the LSTM layer to introduce non-linearities. This layer processes the sequential data from
the previous Time Distributed layers and extracts relevant features.
Dense Layer
Following the LSTM layer, a single-node dense layer is included in the model to produce the
desired output. This layer uses a linear activation function, which ensures that the output
can span a wide range of values.
Compilation
To configure the model for training, it is compiled using the Adam optimizer. The mean
squared error (MSE) loss function is selected, which measures the discrepancy between the
predicted and true values. The Adam optimizer is known for its efficiency in training deep
neural networks and is widely used in various domains.
3. Results
In this section, we present the results of the machine learning models, including ARIMA,
LSTM, and CNN. Each model's accuracy, represented by the Mean Absolute Error (MAE), is
calculated and compared. ARIMA's effectiveness in capturing time series patterns and
LSTM's ability to retain long-term dependencies are highlighted.
Training
The model is trained using the `fit` function, which applies the backpropagation algorithm to
update the model's weights iteratively. The training data, denoted as `trainX` and `trainY`,
represent the input sequences and their corresponding target values, respectively. The
training process consists of 50 epochs, indicating that the entire training dataset is
traversed 50 times. A batch size of 1 is used, meaning that a single sample is processed in
each iteration. This choice allows for fine-grained updates of the model's parameters and
can be beneficial when dealing with sequential data.
By following this model architecture and training procedure, the model learns to capture
temporal patterns and make accurate predictions on sequential data. The utilization of
convolutional and recurrent layers enables the model to extract local features and capture
long-term dependencies, respectively, resulting in an effective framework for sequential
data analysis.
The Google training data has information from 3 Jan 2012 to 30 Dec 2016. There are five
columns. The Open column tells the price at which a stock started trading when the market
opened on a particular day. The Close column refers to the price of an individual stock when
the stock exchange closed the market for the day. The High column depicts the highest
price at which a stock traded during a period. The Low column tells the lowest price of the
period. Volume is the total amount of trading activity during a period of time
.
3. Use the Open Stock Price Column to Train Your Mode4.
Normalizing the Dataset.
As you can see above, the model can predict the trend of the actual stock prices very
closely. The accuracy of the model can be enhanced by training with more data and
increasing the LSTM layers.
4. Discussion
The results show that the choice of parameters, particularly for ARIMA models, has a
significant impact on forecasting accuracy. Larger values of p and q can cause overfitting,
while smaller values may lead to underfitting. Moreover, the LSTM model's performance
improves with additional layers and longer training times, capturing the temporal
dependencies more effectively.
Model Initialization
A sequential model is initialized using the Keras framework's `Sequential` class. This model
allows for the construction of a linear stack of layers, facilitating the definition of deep
learning architecture.
Dense Layer
Following the bidirectional LSTM layer, a dense layer with a single node is added to the
model. This layer is responsible for producing the output of the model. The use of a single-
node dense layer suggests that the regression task aims to predict a single continuous value
as the output.
Compilation
To prepare the model for training, it is compiled using the Adam optimizer. The Adam
optimizer is a popular choice for deep learning tasks due to its adaptive learning rate and
efficient optimization capabilities. The mean squared error (MSE) loss function is employed,
which measures the discrepancy between the predicted and true values. By minimizing this
loss function, the model aims to learn to accurately predict the target values.
Training
The model is trained using the `fit` function, which applies the backpropagation algorithm to
update the model's weights iteratively. The training dataset, denoted as `trainX` and
`trainY`, represents the input sequences and their corresponding target values, respectively.
The training process consists of 50 epochs, indicating that the entire training dataset is
traversed 50 times during training. A batch size of 1 is chosen, meaning that each sample is
processed individually, allowing for fine-grained updates of the model's parameters.
By utilizing a bidirectional LSTM layer and a single-node dense layer, the model learns to
capture and understand the temporal dependencies within the input data, ultimately
predicting a continuous value for the given regression task. The training process, consisting
of multiple epochs and fine-grained updates with a batch size of 1, enables the model to
optimize its parameters and improve its predictive performance.
ARIMA Model
This research also explores the process of building and optimizing ARIMA (Auto Regressive
Integrated Moving Average) model parameters for time series forecasting. The study
involves experimenting with different combinations of p and q parameters to identify the
most accurate model. The Mean Absolute Error (MAE) is employed as a performance metric
to evaluate the accuracy of each model. The results highlight the significance of selecting
appropriate parameters for achieving better forecasting accuracy in time series analysis.
5. Conclusion
This paper demonstrates that while predicting stock prices is inherently challenging,
machine learning models such as ARIMA and LSTM show promise in achieving reasonable
accuracy. By further tuning these models and using more extensive datasets, prediction
accuracy can be enhanced.
REFERENCES:
Machine learning approaches in stock market prediction: A systematic literature
review - ScienceDirect
Electronics | Free Full-Text | Stock Market Prediction Using Machine Learning
Techniques: A Decade Survey on Methodologies, Recent Developments, and Future
Directions (mdpi.com)
Pooling and Winsorizing Machine Learning Forecasts to Predict Stock Returns with
High-Dimensional Data - ScienceDirect
(PDF) Stock Prediction Using Machine Learning (researchgate.net)
Fama, E. (2024). Efficient Market Hypothesis. [Publisher details].
Lo, A.W., & McKinlay, A.C. (1999). A Non-Random Walk Down Wall Street. Princeton
University Press.