Stock Prices prediction using Artificial Neural Networks Ajay Kamat Flat 2, Jaysagar 2, Navy Colony Liberty Garden, Malad west, Mumbai – 400064 +919833796261 ajay1185@gmail. com
ABSTRACT The aim of this research paper is to use Artificial Neural Networks for predicting the closing price of a specific stock on a given day. This study extensively analyzed existing models and techniques for forecasting the behavior of the stock market. Notable models that were examined include the Efficient Market Hypothesis and its competitor, the Chaos Theory. The research concluded that the Chaos Theory provides the most accurate framework for modeling stock market behavior.
The concept of chaos involves a nonlinear and seemingly random process, where there is a relationship between order and disorder in the factors influencing the process. Chaos theory aims to illustrate that even in apparent randomness, there is an underlying order that can be represented through mathematical expressions. In order to address the challenges posed by uncertain, fuzzy, or fluctuating data that rapidly change within brief intervals, a model based on Artificial Intelligence was chosen. This model can effectively adapt to dynamic systems such as the stock market.
The learning-from-examples approach necessitated the systematic use of hints by the model. Artificial Neural Networks, a broad category of non-linear models, have shown success in solving different problems, particularly in time series prediction. The ability of Neural Networks to analyze non-linear relationships in input data has been advantageous. Consequently, there was an endeavor to explore similar systems that have achieved successful implementation elsewhere, albeit on a larger magnitude.
Two stock exchanges, the Tokyo Stock Exchange and the Johannesburg Stock Exchange, were analyzed using different models. For the Tokyo Stock Exchange, a clustering approach based on the Kohonen Model was utilized, specifically employing Self-Organizing Maps. On the contrary, the Johannesburg Stock Exchange employed a Multi-Layer Feedforward Network with the Error-Backpropagation training algorithm. The system implemented a Multi-Layer Perceptron that utilized gradient descent for training. An effective way to validate the Chaos Theory is by assessing if the Neural Network consistently surpasses market performance in predicting stock prices.
Thus, two tasks were achieved simultaneously: validating the Chaos theory and establishing the potential for building advanced large-scale implementations that would be highly beneficial for investors in the long term.
1. INTRODUCTION
Since ancient times, it has been mankind’s shared aspiration to simplify life. The prevailing belief in society is that wealth brings comfort and luxury. Therefore, it is not surprising that significant efforts have been made to find ways to predict financial markets. Different technical, fundamental, and statistical indicators have been suggested and utilized, yielding different outcomes.
Despite numerous attempts, no single technique or combination of techniques has proven consistently successful in outperforming the market. The emergence of neural networks has sparked hope among researchers and investors that these mysteries can finally be unraveled. By accurately forecasting asset values, not only can one identify profit opportunities, but also compute other valuable quantities such as the price of derivatives (complex financial products) or the probability of an adverse mode. This essential information is crucial for assessing and managing risk in a portfolio investment.
Forecasting the price of a particular asset based on historical data is a well-known problem in science and engineering, specifically in time series prediction. Financial time series present significant challenges for analysis and prediction.
The basics of the stock market
Stocks represent ownership shares in a company, giving shareholders a claim on the company’s assets and earnings. When you own stock in a company, you are one of its many owners and have a proportional claim to everything it possesses. A company’s value is determined by its market capitalization, which is calculated by multiplying the stock price by the number of outstanding shares. For example, let’s consider a company with a stock trading at Rs. 100 per share and 1,000,000 shares outstanding. This company would have lower value compared to another company trading at Rs. 50 per share but with 5,000,000 shares outstanding (Rs. 100 x 1,000,
000 = Rs. 100,
000,
000 compared to Rs.
50 x
5,
000,
000 = Rs.
250,
000,
00). The stock market exists to facilitate the trading of securities between buyers and sellers while minimizing investment risks.
Stock prices are determined by market mechanisms, which in turn are influenced by supply and demand. If the demand for a stock exceeds its supply, the price will rise, while if there is an oversupply compared to demand, the price will fall. Understanding this concept is relatively simple, but grasping the factors that shape people’s preferences for certain stocks and their aversion toward others can be difficult. This involves assessing whether news about a company is positive or negative.
The price of a stock not only reflects a company’s current value but also predicts its future growth. The main factor that determines a company’s value is its net earnings, which represent its profits. Net earnings are vital for the long-term survival of any company as consistently failing to generate profits can lead to bankruptcy.
Publicly traded companies must report their earnings four times per year, once each quarter. These specific periods, referred to as earnings seasons, receive significant attention from Wall Street.
When evaluating a company’s future value, analysts consider the projection of its earnings, which affects its stock price. If a company exceeds expectations, the price increases; if it falls short, the price decreases. However, there are additional factors beyond earnings that can affect sentiment towards a stock and its price. For example, during the dot-com bubble era, many Internet companies had high market capitalizations despite not being profitable.
Even though Internet company valuations have significantly decreased, it is clear that factors other than current earnings affect stock prices. Consequently, any news regarding a stock, whether positive or negative, impacts its price. Therefore, it is important to assess the impact of news on the price of a specific stock. Analyzing the movements in stock prices is essential for understanding the reasons behind their fluctuations.
There is ongoing debate about the feasibility of predicting changes in stock prices. While some believe studying charts and past price movements can be useful for determining ideal times to buy or sell stocks, others hold a different viewpoint. Nonetheless, it is widely acknowledged that stocks are highly volatile and their prices can fluctuate rapidly. Financial experts propose that the stock price is influenced by the current value of the company’s future earnings projections divided by the number of shares it has. Essentially, a company’s earning potential plays a crucial role in determining its stock price.
Despite a company’s current loss, its share price can still remain high due to the expectation of future earnings. People are willing to pay a certain amount for the company’s shares as long as there is potential for future revenue. The market evaluates a company’s earnings potential by considering factors like its future earnings, growth potential, and the time it takes to achieve goals. Information plays a crucial role in determining stock prices as it justifies how the market values the stock at a specific level. Market adjustments occur based on newly revealed information that may impact the company’s ability to earn in the future. Measuring the impact of information on stock prices is important to prevent excessive fluctuations.
Investor sentiment, driven by human characteristics, has a significant impact on the trading activity of the stock market. This power often pulls the amplifier causing the stock to move back to its rightful position based on known information about the company. Emotions such as fear and greed can lead to inaccurate valuations in the market, persisting for a short period but offering opportunities for smart investors. Hence, market emotions act as an amplifier for new information.
In addition, stock prices are also influenced by supply and demand.
The movement of a stock’s price depends on its supply and demand dynamics. The supply represents the available shares for sale, while the demand represents the number of shares investors want to buy. Investors buy stocks with the expectation of value increase and sell them in anticipation of either a decrease or no further increase. When there is high demand for a stock, it indicates belief in its future value rise, creating buying pressure and shortage of stock at a specific price. Speculation focuses on future outcomes rather than current or past circumstances. Without belief in future value increase, there is no motivation to hold onto the stock, resulting in selling pressure and excess supply at a given price point.
The market price adjusts continuously to eliminate shortages or surpluses of specific stocks. An increase in demand driven by speculation about future value will cause an expected rise in price.
The movement of a stock price can be seen as self-fulfilling. If an investor is confident in the potential growth of a company’s stock and decides to purchase it, other investors are likely to do the same for the same reason. This results in higher demand and consequently an increase in price. It is important to note that speculative investors, not the company’s underlying fundamentals, play a role in driving up stock values. Thus, we can conclude that ultimately market supply and demand determine stock prices.
The value of a company is determined by multiplying the price by the number of shares outstanding, which is also known as market capitalization. Comparing the share price of two companies without considering other factors is not meaningful. The earnings of a company theoretically influence how investors perceive its worth, but investors also rely on other indicators to predict stock prices. Ultimately, it is the sentiments, attitudes, and expectations of investors that impact stock prices. There are many theories attempting to explain the movement of stock prices, but no single theory can provide a comprehensive explanation.
Scientists in stock markets use various methods including econometrics and other disciplines. Currently, they are utilizing Artificial Neural Networks as non-parametric regression techniques rather than kernel regression. Neural Networks have an advantage because they effectively approximate non-linear functions, especially when there is limited mathematical understanding or challenges in rationalizing the underlying stochastic process in the time series.
The research and financial communities have a second motivation: supporting the Efficient Market Hypothesis (EMH). According to EMH, markets are efficient as profit opportunities are quickly identified and disappear. This hypothesis asserts that no system can consistently outperform the market because once it becomes widely known, everyone will utilize it, eliminating any potential gain. The validity of EMH has been subject to debate, with researchers employing neural networks to bolster their claims.
The Efficient Market Hypothesis (EMH) validity is a topic of debate, but many market observers tend to favor its weaker forms and therefore refrain from sharing their investment systems. Neural networks are used to predict stock market prices because they can learn nonlinear mappings between inputs and outputs. On the other hand, some researchers argue that the stock market and other complex systems exhibit chaotic behavior, which is a nonlinear deterministic process that appears random due to its expressive difficulty.
Neural networks have the potential to surpass traditional analysis and other computer-based methods in various fields, including finance, due to their ability to learn nonlinear and chaotic systems. The focus of this discussion will primarily be on their application in stock market prediction.
In this section, we will review the literature on artificial neural networks (ANNs), which are mathematical models that simulate the processes of our mind or brain.
The neural network, comprised of interconnected neurons, acts as the brain for complex animals. Neurons receive, accumulate, and evaluate electrical signals to assess their transmission strength. Various network architectures like backpropagation, genetic algorithms, recurrent networks, and modular networks have been utilized in stock market prediction networks. This section explores different network architectures and how they impact performance.
Backpropagation networks are widely used due to their strong generalization abilities and relatively simple implementation. While determining the optimal network configuration and parameters may be challenging, these networks exhibit excellent performance when trained properly. Genetic algorithms are particularly beneficial in scenarios with high input dimensionality, as they enable network developers to automate configuration without relying on heuristics or trial-and-error. Recurrent network architectures are the second most prevalent implementation.
The reason for using recurrence is because pricing patterns can repeat over time. A network that remembers past inputs or previous outputs can be more successful in identifying these time-dependent patterns. There are different types of networks that have recurrent connections between layers, or can remember previous outputs and use them as new inputs to increase the dimensionality of the input space. These networks perform well. A self-organizing system can also be utilized in predicting stock prices.
The self-organizing network utilizes volume and price data to create a nonlinear chaotic model of stock prices. The system automatically extracts and classifies features in the data. The advantage of using a self-organizing neural network is that it decreases the number of required features for pattern classification (hidden nodes), and the network organization is built automatically during training. One possible method is to employ two self-organizing neural networks simultaneously, with one focusing on selecting and detecting data features, while the other handles pattern classification.
Despite being a concern, overfitting and training difficulties persisted in this organization. The neuron, which serves as the fundamental unit of the neural network, acts as a communication conduit that receives input and generates output. Input can come from other neurons or the user program, while output can be sent to other neurons or the user program. Figure 1 showcases the neuron as a crucial constituent of the neural network. Activation or firing of a neuron occurs when its output fulfills the activation function criteria.
Figure 2. The activation function of a neuron is noteworthy as it can influence the type of data that is learned by the neural network nodes. The sigmoid function is ideal for learning about average behavior, whereas the hyperbolic tangent (tanh) function is more effective when learning deviations from the average. Figure 3 showcases both the sigmoid and tanh activation functions.
2.1.3 Neural Layers
Neurons are commonly organized into layers, where each layer consists of neurons that carry out similar functions. There are three types of layers.
The input and output layers have more than just interface functionality. Each neuron in a neural network can impact processing, which can take place in any layer of the network. While the hidden layer is optional, the input and output layers are necessary, and one layer can serve as both an input and output layer. Figure 3 depicts the layers of neurons. The most commonly used method for training neural networks is the feed forward backpropagation architecture, which is highly favored due to its applicability to various tasks.
The neural network processes patterns and recalls patterns using the term “feed-forward”. Neurons in a feed-forward neural network are only connected forward. Each layer of the neural network has connections to the next layer, but there are no connections back. The term “back-propagation” describes the training of this type of neural network. Back propagation is a form of supervised training. In supervised training, the network must be given sample inputs and anticipated outputs. These anticipated outputs will be compared to the output of the neural network.
The process involves using the expected results to calculate errors and adjust the weights of layers in reverse order, starting from the output layer and going back to the input layer. The Error Backpropagation Algorithm (EBPTA) is used for this purpose. Figure 4 illustrates the steps of the Error Backpropagation Algorithm. Variables are created for the weights (W and w), net input to each hidden and output node (neti), activation of each hidden and output node (yi = f(neti)), and error at each node (ei). For each input pattern k, the following steps are performed:
1. Forward Propagation: Calculate neti and yi for each hidden node i=1,…,h. Calculate netj and yj for each output node j=1,…,m.
2. Backward Propagation: Adjust the weights in reverse order.
Computing the ? 2’s for each output node, j=1,… ,m, and computing the ? 1’s for each hidden node, i=1,… ,h is the first step. The second step is to accumulate gradients over the input patterns (batch). After completing steps 1 to 3 for all patterns, the weights can now be updated. Before the age of computers, people relied on intuition to trade stocks and commodities. However, as investing and trading became more popular, people started looking for tools and methods to increase their gains and minimize risk. Tools such as statistics, technical analysis, fundamental analysis, and linear regression are used to predict and benefit from the market’s direction.
Despite the lack of a consistently accurate prediction tool, various techniques are commonly used and considered a standard for neural networks to surpass. Critics argue about the usefulness of these approaches, but they are still prevalent in practice. Moreover, many of these techniques are employed to preprocess raw data inputs before feeding them into neural networks. One such technique is technical analysis, which operates on the premise that share prices follow trends influenced by the ever-changing attitudes of investors in response to various factors.
The technical analyst utilizes charts to forecast future stock movements by using price, volume, and open interest statistics. Technical analysis is based on the belief that history repeats itself and that examining past prices can determine future market direction. Consequently, technical analysis is a contentious practice that contradicts the Efficient Market Hypothesis. Nevertheless, it is utilized by about 90% of significant stock traders. The Moving average is a commonly used technical indicator for stocks. While a moving average series can be computed for any time series, it is commonly employed for stock prices, returns, or trading volumes.
Moving averages are utilized to reduce the impact of short-term fluctuations, effectively emphasizing longer-term patterns or cycles. A basic moving average is generated by averaging the prices of a security over a specified number of periods. Although moving averages can be computed using Open, High, and Low data points, the closing price is commonly used. To illustrate, a 5-day simple moving average is determined by summing up the closing prices of the previous 5 days and dividing the total by 5. This calculation is repeated for every price bar on the chart.
The moving average line is formed by combining the averages to create a smooth curving line. In the given example, if the next closing price in the average is 15, this new period would be added while the oldest day, which is 10, would be removed. The calculation for the new 5-day simple moving average in this scenario would be: As the SMA moved from 12 to 13 over the last 2 days. Over time, as new days are added and old ones are subtracted, the moving average will continue to change. Figure 5 illustrates an example of a 50-day and 200-day moving average.
The Simple Moving Average (SMA) has several drawbacks, as highlighted in the graph above. Firstly, instead of predicting the stock price, the SMA merely tracks or mirrors the movement of the stock price, meaning it can only project trends in hindsight rather than predict them. Additionally, the accuracy of the SMA decreases as the graph becomes smoother, such as in the case of the 200-day SMA. This is because it fails to capture most of the shorter- to medium-term fluctuations. Moreover, the interpretation of the graphical curves plays a significant role in determining the indicators provided by the SMA. Consequently, since it is a subjective tool, the SMA does not yield quantified results.
Neural Networks surpass technical analysis in terms of scoring, specifically in the area of fundamental analysis. Fundamental analysis entails conducting a thorough examination of a company’s performance and profitability to ascertain its share price. Through the study of overall economic conditions, the company’s competition, and various other factors, one can estimate expected returns and the intrinsic value of shares. This form of analysis assumes that the present (and future) price of a share is influenced by its intrinsic value and expected return on investment.
When new information regarding the company’s status is released, it impacts the expected return on the company’s shares, leading to changes in the stock price. Fundamental analysis offers advantages such as a systematic approach and the ability to anticipate changes before they become visible on charts. It involves comparing companies and assessing their growth potential based on the current economic conditions, enabling investors to gain familiarity with the company. However, formalizing this knowledge for automation, such as with a neural network, becomes more challenging, and its interpretation can be subjective.
It is difficult to time the market using fundamental analysis because even if the information suggests a stock should move, its actual movement may be delayed due to unknown factors or until the market as a whole interprets the information similarly. However, fundamental analysis is superior for long-term stability and growth. Essentially, fundamental analysis operates under the assumption that investors are primarily logical, carefully examining their investments, while technical analysis assumes investors are primarily emotional, reacting predictably to changes in the market.
One of the most widely used fundamental indicators is the price to earning ratio, which compares the current price with earnings to determine if a stock is over or under valued. The price-to-earning ratio can be calculated by dividing the market value per share by the earnings per share. Generally, a high P/E ratio indicates that investors are anticipating higher growth in the future. The P/E ratio can also use estimated earnings to obtain the forward-looking P/E ratio. It is important to note that companies that are losing money do not have a P/E ratio. Furthermore, the Efficient Market Hypothesis is another concept related to this topic.
The Efficient Market Hypothesis (EMH) argues that the price of a share at any given time reflects all known information about that share. This is because market participants use all available information effectively, resulting in random price movements as new information emerges. Consequently, share prices follow a “random walk,” making it impossible for an investor to outperform the market. Despite its apparently inaccurate practical implications, there is inconclusive evidence regarding the rejection of the EMH, with various studies reaching different conclusions.
Many studies utilized neural networks to support their assertions. However, the effectiveness of a neural network relies on its training, making it difficult to solely rely on its performance to justify acceptance or rejection of a hypothesis. In reality, market crashes like the October 1987 crash challenge the Efficient Market Hypothesis (EMH) as they are not driven by random information but instead occur during periods of significant investor apprehension. The EMH holds significance as it contradicts all other analytical approaches.
If it is impossible to beat the market, then technical, fundamental or time series analysis would be no better than random guessing. The fact that some market participants consistently outperform the market suggests that the Efficient Market Hypothesis (EMH) may not hold true in practice. While the EMH may be applicable in an ideal world with equal information distribution, today’s markets involve privileged players who can achieve better results through insider knowledge or other methods. 2. 2. 4Chaos Theory is a recent approach for modeling nonlinear dynamic systems such as the stock market.
Chaos theory examines a process with the assumption that it consists of both deterministic and random components. Chaos is a nonlinear process that appears to be random, reflecting an order-disorder relationship among the different parameters influencing the process. Various theoretical tests have been developed to determine if a system exhibits chaos in its time series. Chaos theory aims to demonstrate that there is order amid apparent randomness. This concept challenges the Efficient Market Hypothesis (EMH) by suggesting that the stock market is chaotic rather than purely random.
Essentially, a chaotic system combines deterministic and random processes. The deterministic aspect can be characterized through regression fitting, while statistical parameters of a distribution function describe the random aspect. Hence, solely relying on deterministic or statistical techniques falls short in fully understanding the nature of a chaotic system. Neural networks possess the capability to capture both deterministic and random features, which makes them well-suited for modeling chaotic systems. Additionally, there are other computer techniques available for this purpose.
There are several computer techniques used for stock market forecasting, including charting programs, sophisticated expert systems, and fuzzy logic. Expert systems process knowledge in a sequential manner and convert it into rules. They are capable of formulating trading rules using technical indicators. Expert systems can work alongside neural networks to predict the market. In this collaboration, the neural network makes the prediction while the expert system verifies it using its established trading rules.
In the stock market, which is a highly chaotic and partially understood environment, it is difficult to gather information from experts and transform it into a format that can be utilized by expert systems. Expert systems are effective only within their particular domain of knowledge and are not adept at dealing with missing or incomplete information. On the other hand, neural networks perform better with dynamic data and have the ability to make educated guesses by generalizing. Therefore, neural networks are better suited for the stock market environment compared to expert systems. [10] 3. DESIGN 3. 1Target and time frame
When constructing a neural network, one important factor to consider is determining what the network will learn. Most networks aim to make decisions on buying or selling securities based on past market indicators. In our case, the neural network’s goal is to predict stock prices. Another decision to make is the time frame size. Implementing a neural network model for a shorter time frame is more challenging compared to a longer time frame due to significant market noise. Conversely, macroeconomic forces take place over longer periods. However, we have chosen to utilize a short time frame.
In order to build an effective predictive model of the stock market, it is essential to possess domain expertise and thoroughly investigate the factors that influence the market before training the network and gathering data.
The challenge lies in determining which indicators and input data should be used and collecting enough training data to properly train the system. The input data can consist of raw data on volume, price, and daily changes. It should enable the neural network to generalize market behavior while avoiding excessive redundant data.
During the Data Collection Phase, indicators are gathered to be interpreted by the Neural Network in order to uncover hidden regularity in the seemingly chaotic price trend of a specific stock. Collecting the high and low prices of the stock for a particular day provides insight into its volatility. The closing price of the day reflects the current evaluation of the stock, while the market closing price offers an indication of the overall market’s current situation. 3. 4Network Training
Training a network involves presenting input patterns in a way that the system minimizes its error and improves its performance. The training algorithm used when designing financial neural networks is typically the backpropagation algorithm. This algorithm is utilized in the case of multilayer feedforward networks commonly used for financial neural networks. During training, backpropagation involves backpropagating errors through the system from the output layer towards the input layer.
The necessity of backpropagation arises from the lack of training target values for hidden units. Thus, these units are trained using errors from previous layers. In contrast, the output layer has a target value to compare with. During the propagation of errors through the nodes, connection weights are adjusted. Training continues until the weight errors reach an acceptable level. Determining when to stop training is a significant challenge in neural network training due to the crucial requirement of generalization for predicting future stock prices. Consequently, overtraining poses a serious issue.