Stock Market Forecasting

Download Stock Market Forecasting

Post on 27-Apr-2015




5 download

Embed Size (px)


<p>Stock Market Forecasting</p> <p>Stock Exchange Forecasting</p> <p>Supervisor: Mr. Manish Kumar</p> <p>Group Members: G. Aravind (R200503) Manam Kiran (R200515) G. Sravan Kumar (R200533)</p> <p>1</p> <p>Stock Market Forecasting</p> <p>List of contents</p> <p>o Candidates declaration o Certificate o Acknowledgemento o o o o</p> <p>3 3 4 5 5 5 6 7 8 9 10 12 13 15 15 15 16 17</p> <p>Topic Motivation Problem Definition Literature Survey Course of work </p> <p>Designing of the neural network Designing of the mining system Training the system Using the system for forecasting</p> <p>o</p> <p>Snapshots of GUI</p> <p>o Platform, tools, language o Challenges o Scope for future work o Referenceso</p> <p>Comments of the Mid-Sem evaluation board</p> <p>Figures2</p> <p>Stock Market Forecasting Delta of hidden layer node Delta of input layer node Delta of hidden layer node Main GUI Selecting an input file Prediction Actual vs predicted prices 11 11 12 14 14 15 15</p> <p>Candidates Declaration We hereby declare that the work presented in this project entitled Stock Market Forecasting using Neural Networks submitted towards completion of mini-project in Sixth Semester of B.Tech(IT) at the IIIT-Allahabad, Amethi campus, is an authentic record of our original work carried out under the guidance of Mr. Manish Kumar, M.Tech(Computer Science), Lecturer, IIIT-Allahabad.</p> <p>Place: Amethi Date:</p> <p>Certificate3</p> <p>Stock Market Forecasting</p> <p>This is to certify that the above declaration made by the candidates is correct to the best of my knowledge and belief.</p> <p>Mr. Manish Kumar M.Tech(Comp. Science) Place: Amethi Date: Lecturer, IIIT-Allahabad Devghat, Jhalwa, Allahabad</p> <p>4</p> <p>Stock Market Forecasting</p> <p>Acknowledgement</p> <p>We would like to express our sincere gratitude to our project supervisor, Mr. Manish Kumar, M.Tech(Computer Science), Lecturer, IIIT-Allahabad. We were privileged to experience a sustained enthusiasm and involved interest from his side. This fueled our interest even further and encouraged us to boldly step into what was a totally dark and unexplored expanse before us. We would also like to thank our batch-mates and friends who were ready with their inputs at all times, whether it was an offhand comment to encourage us or a constructive piece of criticism. Last but not least, we would like to thank the IIITA staff members and the institute, in general, for extending a helping hand at every juncture of need.</p> <p>G. Aravind (R200503) Manam Kiran (R200515) G. Sravan Kumar (R200533)</p> <p>5</p> <p>Stock Market Forecasting</p> <p>Topic: Stock exchange forecasting with the use of neural networks.</p> <p>Motivation: There are numerous motivating factors for trying to predict the future stock market trends. The basic factor of motivation for us is the interest in building a system that could consistently guide us through the dynamic and ever changing stock market and support decision making with respect to investments. Such a system would be a great support for the individuals/corporations who like to take calculated risks in investing their capital. Also before the invention of computers, the stock market trends were forecasted by a set of highly qualified individuals or by pure instinct. The purpose of this project is to automate the process of forecasting. Neural networks have been chosen to model the stock market because of their ability to learn the non-linear mappings between inputs and outputs. The stock market is considered to be highly chaotic model, which cannot be understood by the human mind, and thus cant be easily expressed. However, with the neural networks ability to learn chaotic and nonlinear systems, it is possible to solve many more problems which could not be solved by simple traditional analysis or current computer methodologies. In addition to financial market predictions, neural networks have been already put to use by many organizations for handling different financial tasks [1]. Some banks use neural networks to scan credit and loan applications to predict bankruptcy probabilities. Though the neural networks were primarily used as a tool in the financial domain, many improvements, with respect to the design issues and the training of neural networks have been achieved during research and the implementation.</p> <p>Problem Definition: Our aim is to implement stock market forecasting using neural networks, with multi-layer back-propagation, for the stock market data as a time series. The objective of the implementation is to forecast the future trends of the stocks, on the base of the previous or past prices. The implementation is planned to be done using JAVA.</p> <p>6</p> <p>Stock Market Forecasting Literature Survey: From the beginning of mankind, man has always been trying to make his life easy. The computers were also invented for making calculations easier and possibly automate them. It is also a common notion that wealth gives luxury and makes life easier. There have been many attempts, both partly successful and unsuccessful, to forecast the future trends of the stock markets. Y. Yoon, et al. [3], proposed a system for stock market prediction using neural networks. The inputs used were the phrases extracted out of the Presidents (of the organization) report to its shareholders. The system based its predictions on the types and frequencies of the phrases occurring in the presidents report. Kamijo, et al. [4], developed a neural network that trained on price chart information. They used a recurrent network model for forecasting. G. Tsibouris, et al. [5] developed a simple system that used only the past stock prices to forecast the future stock prices. K. Bergerson, et al. [6], proposed a system that was trained on human designed chart information. This reduced the learning time as the input had knowledge about the patterns already known. This system used hybrid architecture, combining neural networks with expert systems. The neural networks were used to predict the future trends and the expert system contained knowledge base of rules that validated the output of the network. If the output violated any of the expert systems rules, the output was simply rejected. This hybrid architecture showed great promise as it combined the nonlinear prediction of neural networks and the rule based knowledge of expert systems. Kimoto, et al. [7], designed a network that was to predict the Tokyo stocks. They used daily data (prices) for training the network for about 33 months. They proposed a variation of back-propagation for the system, called supplementary learning. The weights in the network were updated based on the sum of all errors for all the patterns. During training they used moving simulation, where prediction is done while moving the target learning and prediction periods [1]. They used a modular network consisting of 4 backpropagation neural networks, trained on different data sets. Wilson [8], used a combination of technical, adaptive (based on limited support functions), and statistical indicators as inputs, for his self-organizing system. It was designed to construct a nonlinear and chaotic model of the stock market based on the volume and price data. The system itself extracted the features from the data, and classified them. He used two self organizing systems in tandem, one for feature extraction and the other for pattern classification.</p> <p>7</p> <p>Stock Market Forecasting Ajith Abraham, et al. [9], used soft computing techniques and connectionist paradigms for modeling chaotic behavior of the stock markets. They experimented with the system on the data of NASDAQ stock market and NIFTY stock exchange. They used four different methods to model the markets and compared the results from each of them. Chan Man-Chung, et al. [10], proposed a variation of learning algorithm, the conjugate gradient learning algorithm with a restart procedure.</p> <p>Course of work: The implementation is based on the algorithm suggested in the paper by Defu Zhang, et al [2]. The paper deals with financial data mining using multi-layer back propagation, a neural network technique commonly used for time series forecasting. Though the paper does not prescribe any suggested method for back propagation but have given the type of inputs to be taken like learning rate is given to be 0,5 and weights are first adjusted to range from -0.5 to 0.5. The implemented algorithm though deviates in three ways:1) Paper predicts next 30days values based on last few years trend but the training takes</p> <p>about 3-4 days so we assumed that tomorrows value is depended on last 30 days data, which reduces the time taken to train the network.2) Error function used is mean square error which is not very accurate in our case as we</p> <p>predict only one value, hence we used a non linear function to transfer out put by using sigmoid function and then error is calculated.3) Since we are using sigmoid function we mapped the input data to range of 0 to 0.5 and</p> <p>then later the results are remapped which increases the error by the mapping function but is accurate enough if input values are in not too big.</p> <p>The implementation is divided into four phases: Designing the neural network Designing the mining system for forecasting Training the network with past data Using the network for forecasting the future trends of the stock based on the present and past data8</p> <p>Stock Market Forecasting</p> <p>Designing the neural network: The neural network architecture has to be decided upon before going on with the designing of the mining system for forecasting. Feed-forward networks are the most widely used architecture as they provide good generalization capabilities and are readily implementable. So, a feed-forward network with three layers is chosen as the architecture to model the forecasting task. The parameters defining the architecture of the neural network are: Number of layers: The number of layers in the Neural network is three. They are one Input Layer, one Hidden Layer, one Output Layer. The Hidden layer is used to transform the inputs to the neural network using a transfer function, described later. Number of nodes(neurons): The input layer consists of 30 nodes(neurons), one for each of the stock prices for the last 30 days. The hidden layer consists of 30 nodes, each taking an input from all of the previous input nodes, with links having certain weights. There is a single output node in the output layer, corresponding to the predicted stock price. The outputs of all of the nodes in the hidden layer are passed on to the output node, each with certain weight. Weights of the links: All of the weights are initially randomly set in the range [-0.5,0.5]. During the training phase, the weights are adjusted according to the error of the nodes in the next layer. Activation function: It is the function that is fired at each node, after receiving inputs from the previous layer. This is the transfer function that was mentioned earlier. This function transforms the input to a neuron(node) into its output. The activation function used in the implementation is the sigmoid function, i.e.,</p> <p>This function maps any input x to the range [0,1]. So the outputs of all the nodes belong to the range [0,1]. Learning rate: It defines the rate of learning of the neural network. It can also be</p> <p>9</p> <p>Stock Market Forecasting interpreted as the acceleration of the network while training. In the implementation the value of learning rate has been set to 0.5. Input mapping: While taking the inputs to the neural network the maximum of all the inputs is calculated and stored. Then all the inputs are normalized by dividing them by the maximum value. This is done so that during training the predicted output and the expected output both lie in the range [0,1]. Output scaling: The predicted outputs lie in the range [0,1], because of the application of the sigmoid function at all the nodes. To get the actual predicted price, the output is multiplied with the maximum of all the inputs. This scales the output from the range [0,1] to the original scale of the stock price. Designing the mining system: The mining system for the forecasting task has to be designed. The design of mining system consists of two phases: o Choosing the design strategy o Choosing the trading strategy Design strategy in the algorithm is stated as follows: The stock market is inherently nonlinear. So the error function is not globally convex, and may contain many local minima. The trends of up or down of a stock are also important for making profits in the stock market. So, to make the prediction more accurate, some penalizing factor [2] has to be introduced into the error function. Also, there is need to address the issue of over-fitting of the data by the network. The trading strategy is as follows: A trading strategy [2] is required to avoid the poor explanation capabilities of the neural networks. It means instead of giving out pure numerical data, the network can be designed to explain the results in a more understandable fashion, and give suggestions for decision making and investments. The trading system designed is as follows: The neural network is used to predict 3 future prices of the stock. The maximum and the minimum of the predicted prices are calculated. The system proposes to the user to Buy and/or Hold the stock, if the maximum of the predicted prices is greater than the current stock price and the stock is on an up-trend. The system hints the user to Sell a part of the stock, if the maximum of the predicted prices is less than the current stock price and the stock is on a down-trend.10</p> <p>Stock Market Forecasting</p> <p>Training the network: After the network has been designed, it has to be trained with training data so that it can be used for forecasting the future trends. The training data, the past stock data, is to be extracted from the internet. The training of a network involves presenting the input data patterns in a way that the system minimizes error and improve its performance [1]. In this implementation we use a multi-layer back-propagation algorithm for training the system. To minimize overtraining, about 10% of the training data is to be kept aside for testing purposes. This approach is called Test and Train method [1] for training a neural network. This tests the performance on the testing data after it has been trained, and modify the weights of the connections when deviations are found. This also helps reduce over-fitting. The neural network is trained with as follows: Feeding the inputs: Initially, the neural network is provided with the inputs. The input is a text file containing the daily closing stock prices for the past some days. The data in the file is present in the following format:</p> <p>The first line of the text file contains the number of training samples, i.e., the number of days for which the stock prices are present in the file. From the second line, each line contains the daily closing prices of the stock in chronological order, one in each line.</p> <p>The inputs are give...</p>


View more >