forecasting using ann's

80
Forecasting of Stock Market Price Using Neural Networks 8/25/2010 Mudesira Munir Managers must realize and accept the limitations of forecasting and the uncertainty associated with all forms of predictions; otherwise, unexpected results and unpleasant surprises may await them. As long as the patterns or relationships do not change, forecasting will be accurate. The selection and implementation of a proper forecasting methodology has always been a planning and control issue for most firms and agencies. This thesis will suggest and describe the application of

Upload: andaleeb-mudasira

Post on 26-Nov-2014

117 views

Category:

Documents


0 download

DESCRIPTION

Project developed using C#

TRANSCRIPT

Page 1: Forecasting Using ANN's

Forecasting of Stock Market Price Using Neural Networks

8 / 2 5 / 2 0 1 0

Mudesira MunirManagers must realize and accept the limitations of forecasting and the uncertainty associated with all forms of predictions; otherwise, unexpected results and unpleasant surprises may await them. As long as the patterns or relationships do not change, forecasting will be accurate. The selection and implementation of a proper forecasting methodology has always been a planning and control issue for most firms and agencies. This thesis will suggest and describe the application of Artificial Neural Networks for forecasting of stock market closing prices.

Page 2: Forecasting Using ANN's

Chapter #1

INTRODUCTION:

1.1 STOCK MARKET

A stock market is a public for the trading of company stock and derivatives at an

agreed price; these are securities listed on a stock exchange as well as those only traded

privately. The stock market has been one of the most popular investments owing to its

high returns.

The stocks are displayed and traded on stock exchanges which are entities of a

corporation or mutual organization specialized in the business of bringing buyers and

sellers of the organizations to a listing of stocks and securities together. The major stock

market in the America is NYSE while in Canada; it is the Toronto Stock Exchange

(TSX).

• Trading

Participants in the stock market range from small individual stock investors to

large hedge fund traders, Actual trades are based on an auction market model where a

potential buyer bids a specific price for a stock and a potential seller asks a specific price

for the stock. Buying or selling at market means you will accept any price (Bid or Ask)

for the stock, respectively. When the prices (Bid or Ask) match, a sale takes place, on a

first come first served basis if there are multiple bidders or askers at a given price.

The stock exchanges are built in order to facilitate buyers and sellers, thus

providing a marketplace. The stock exchanges provide Real Time trading system and

information for the listed securities.

• The behavior of the stock market

Positive or upward trends are referred to as bull markets; negative or downward

trends are referred to as bear markets. Over-reactions may occur so that excessive

optimism may drive prices unduly high or excessive pessimism may drive prices unduly

low. Forecasters continue to debate whether financial markets are generally efficient (EM

hypothesis).

According to one understanding of the efficient market hypothesis (EMH), only

changes in fundamental factors, such as the viewpoint for margins, profits or dividends,

ought to affect share prices beyond the short term, where random noise in the system data

Page 3: Forecasting Using ANN's

may prevail. But this viewpoint known as hard EMH also predicts that little or no trading

should take place, contrary to fact, since prices are already at or near equilibrium, having

priced in all public knowledge. The hard efficient-market hypothesis is sorely tested by

such events as the stock market crash in 1987, when the Dow Jones index plummeted

22.6 percent the largest-ever one-day fall in the United States.

1.2 STOCK MARKET INDICES

Stock market indices are classified in many ways. A global stock market index

includes typically large companies without regard for where they are traded. The

examples are MSCI World and S&P Global 100.

Each country or nation has its own stock market index representing its

performance. The most commonly quoted market indices are national indices composed

of the stocks of large companies listed on a nation's largest stock exchanges, such as the

American S&P 500, the Japanese Nikkei 225, and the Karachi KSE 100.

The idea may be extended well beyond an exchange. The Dow Jones Total Stock

Market Index represents the stocks of nearly every publicly traded company in the United

States, including all U.S. stocks traded on the New York Stock Exchange (NYSE) and

mostly traded on the NASDAQ and American Stock Exchange (AMEX). More

specialized indices exist tracking the performance of specific sectors of the market.

1.3 INDEX VERSIONS

The indexes, such as the S&P 500, have many versions. These versions can vary

based on how the index components are weighted and on how dividends are accounted

for. For example, there are three (3) versions of the S&P 500 index: price return, which

only considers the price of the components, total return, which accounts for dividend

reinvestment, and net total return, which accounts for dividend reinvestment after the

deduction of a withholding tax.

1.4 MOST POPULAR AND LARGEST STOCK MARKETS:

1.4.1 American Stock Exchange (AMEX):

Today AMEX is one of the largest options exchanges in the United States.

1.4.2 New York Stock Exchange (NYSE):

NYSE is founded in 1792, the Big Board is the where the big companies have

shares. The NYSE is where companies such as Coca cola, McDonald's, General Electric

Page 4: Forecasting Using ANN's

and Wal-Mart all trades. Whereas, America's largest companies and others, they all trade

on the NYSE.

1.4.3 NASDAQ

The most popular over-the-counter (OTC) market is the NASDAQ’s stock

exchange. This is a virtual exchange which has no central location or floor brokers as all

trading is done through a network of dealers. For many years, the largest companies

traded on the NYSE, while the second tier stocks traded on all the other exchanges.

Thanks to the dot-com boom of the late 1990's, some of America's largest firms trade on

the NASDAQ, including, Google, Microsoft, Cisco, Intel and Dell.

1.4.4 UNITED KINDOM:

The London stock exchange plays a vital role in maintaining one of the world’s

leading financial centers. The current LSE market includes not only the ordinary shares

of local and foreign companies and fixed interests securities issued by private borrowers

but also the primary and secondary markets in British government securities. At the end

of 2000, there were 2,428 domestic listed companies with the market capitalization of

1,812 billion pounds.

1.4.5 GERMANY:

There are eight technically independent stock exchanges in Frankfurt. However

they actually cooperate closely. Most recently the stock exchanges of Frankfurt,

Dusseldorf and Munich extended their cooperation in order to establish uniform pricing

mechanism for the DAX 100securities.

Recently the stock exchanges of Frankfurt, Dusseeeld offer the DAX 100securities .There

were 1088 domestic companies listed on the German stock exchange at the end of 2000.

1.4.6 CHINA:

China is the most populous country in the world and while its stock market is

currently rudimentary, given the recent growth and the potential growth of the Chinese

economy china’s stock market will inevitably be an important world stock market.

The Chinese stock market was divided into two types A-shares a, which are

restricted to Chinese investors and B-shares which were restricted to non-Chinese

investors. The A-share market was dominated in chines Yuan and was much larger than

Page 5: Forecasting Using ANN's

the B-share The B-share market was started in 1991 to give private companies and

entrepreneurs access to foreign capital and give foreigners with hard currency

Shanghai B-shares are quoted in U.S dollars and Shenzhen B-shares are quoted in

Hong Kong dollars although these two currencies are linked.

1.4.7 JAPAN:

The Japanese stock market has a history of more than 120 years, beginning with

the establishment of the Tokyo stock exchange (TSE) in 1878. During the 1980 the

Japanese securities market changed substantially. Since March 2000, when the Hiroshima

and Niigata exchanges were merged with the TSE there have been six stock exchanges in

Japan.

OPERATIONS:

The TSE market is a continuous market where buy and sell orders directly

interact with one another. The trading of shares is carried out under the zebra method

which is similar to an open outcry method. Prices are first established at the beginning of

the trading session based on orders placed by regular members before the start of the

trading. The central book is kept by satori members who function solely as intermediaries

between the regular members. They are not allowed to trade any listed stock for their own

account or to accept orders from the investing public. After the opening price is

established satori members match.

1.5 FORECASTING STOCK MARKET:

Recently forecasting stock market return is gaining more attention, maybe

because of the fact that if the direction of the market is successfully predicted the

investors may be better guided and also monetary rewards will be substantial. If any

system which can consistently predict the trends of the dynamic stock market be

developed, would make the owner of the system wealthy. Another motivation for

research in this field is that it possesses many theoretical and experimental challenges.

The most important of these is the efficient market hypothesis (EMH) which proposes

that profit from price movement is very difficult and unlikely. In an efficient market,

stock market prices fully reflect available information about the market and its

constituents and thus any opportunity of earning excess profit ceases to exist any longer.

Page 6: Forecasting Using ANN's

So it is ascertain that no system is expected to outperform the market predictably and

consistently.

In the approach used in this paper, the ANN will be the signal generator, and its

output will be used to either initiate or exit trades. Rules to enter and exit trades are based

on the strength of the ANN output signal.

1.5.1 Application of Neural Networks to Market Prediction

Neural networks are very effective when lots of examples must be analyzed, or

when a structure in these data must be analyzed but a single algorithmic solution is

impossible to formulate. When these conditions are present, neural networks are use as

computational tools for examining data and developing models that help to identify

interesting patterns or structures in the data. The data used to develop these models is

known as training data. Once a neural network has been trained, and has learned the

patterns that exist in that data, it can be applied to new data thereby achieving a variety of

outcomes.

The ability of neural networks to discover nonlinear relationships in input data

makes them ideal for modeling nonlinear dynamic systems such as the stock market.

Various neural network configurations have been developed to model the stock market.

Commonly, these systems are created in order to determine the validity of the EMH or to

compare them with statistical methods such as regression. Often these networks use raw

data and derived data from technical and fundamental analysis discussed previously. This

thesis wills overview the use of neural networks in financial markets including a

discussion of their inputs, outputs, and network organization. Also, any interesting

applications of theoretical techniques will be examined. For example, many networks

prune redundant nodes to enhance their performance. The networks are examined in three

main areas:

1. Network environment and training data

2. Network organization

3. Network performance

1.5.2 Training a Neural Network

Page 7: Forecasting Using ANN's

A neural network must be trained on some input data. The two major problems in

implementing this training discussed in the following sections are:

1. Defining the set of input to be used (the learning environment)

2. Deciding on an algorithm to train the network

1.5.3 The Learning Environment

One of the most important factors in constructing a neural network is deciding on

what the network will learn. The goal of most of these networks is to decide when to buy

or sell securities based on previous market indicators. The challenge is determining

which indicators and input data will be used, and gathering enough training data to train

the system appropriately.

The input data may be raw data on volume, price, or daily change, but it may also include

derived data such as technical indicators (moving average, trend-line indicators, etc.) or

fundamental indicators (intrinsic share value, economic environment, etc.). The input

data should allow the neural network to generalize market behavior while containing

limited redundant data.

Determining the proper input data is the first step in training the network. The second step

is presenting the input data in a way that allows the network to learn properly without

overtraining. Various training procedures have been developed to train these networks.

1.5.4 Network Training

Training a network involves storing input patterns in a way so that the system

minimizes its error and improves its performance. The training algorithm may vary

depending on the network architecture, but Back Propagation algorithm is the most

common training algorithm used when designing financial neural networks. This section

describes some of the training techniques and their associated challenges in some

implemented systems.

The most common network architecture for financial neural networks is a

multilayer feed forward network trained using Back Propagation. Back Propagation is the

process of backpropagating errors through the system from the output layer towards the

input layer during training. Back Propagation is an important algorithm because hidden

units have no Training Target value that can be used, so they must be trained based on

Page 8: Forecasting Using ANN's

errors from previous layers. The Output layer op back Propagation algorithm is the only

layer which has a Target value for which to compare.

As the errors terms are BackPropagated through the nodes, the connection

weights are changed. Training Procedure occurs until the errors in the weights are small

enough to be accepted. It is interesting to note that the type of activation function (such as

threshold, sigmoid) used in the neural network nodes can be a factor on what data is

being learned.

The major area of consideration in training a neural network is deciding when to

stop training. Since the ability to generalize is elementary for these networks to predict

future stock prices, overtraining is a serious problem.

Overtraining occurs when the system memorizes patterns and thus loses the ability to

generalize. It is an important factor in these prediction systems as their primary use is to

predict or generalize on input data that it patteronized. Overtraining can occur by having

too many hidden nodes or training for too many time periods (epochs). However,

overtraining can be prevented by performing test and train procedures or cross-validation.

The test and train procedure involves training the network on most of the patterns

(usually around 90%) and then testing the network on the remaining patterns. The

network’s performance on the test set is a good indication of its ability to generalize and

handle data it has not been trained on. If the performance on the test set is poor, the

network configuration or learning parameters can be changed. The network is then

retrained until its performance is satisfactory. The quantity of training data is also

important. Ideally, it is desirable to have as much training data as the system can be

feasibly trained with.

1.6 Research Purpose:

Testing and training of neural networks will be performed over the stock market

data in order to specify a neural network’s ability to predict future trends of Stock Market

Indices. It will then analyze the use of neural network as a forecasting tool. Finally, the

probability of the model’s forecast being correct will be calculated using conditional

probabilities. While only briefly discussing neural network theory, this research will

determine the feasibility and practicality of using neural networks as a forecasting tool

for the individual investor.

Page 9: Forecasting Using ANN's

The research describes the methodology required to build, train, and test a neural network

using software. In this research, an S&P500, NASDAQ, DOW Jones etc. network model

was validated using available data. Finally, and potentially most importantly for the

investor, model accuracy probabilities were generated. This was done by combining

historical market movement probabilities with the model accuracy probability. This

conditional probability could prove to be a vital tool for investment decision making. The

entrance of the neural network as an investment tool for the individual investor was one

of the many things brought about by the explosive growth personal computers. .

It was concluded that neural networks do have the capability to forecast financial markets

and, if properly trained, the individual investor could benefit from using this forecasting

tool.

Page 10: Forecasting Using ANN's

CHAPTER # 2

LITERATURE REVIEW

Forecasting of stock market returns is an important issue in finance. Nowadays

artificial neural networks (ANNs) have been popularly applied to finance problems such

as stock exchange index prediction, bankruptcy prediction and corporate bond

classification. An Artificial Neural Network model is a computer model whose

architecture essentially mimics the learning capability of the human brain.

The elements of an Artificial Neural Network resemble the biological structure of

neurons and the internal operation of a human brain. Many simple interconnected

elements that may use threshold or sigmoid function are operating in parallel processing

at multiple layers. In some applications it has been specified that ANNs have limitations

for learning the data patterns. They may perform inconsistently and unpredictable

because of the complex financial data used. Sometimes data is so voluminous that

learning patterns may not work. Continuous and large volume of data needs to be

checked for redundancy and the data size should be decreased for the

algorithm to work in a shorter time and give more generalized solutions

There are several motivations for trying to forecast stock market prices. The most

basic of these is financial return. Any software system that can constantly pick winners

and losers in the dynamic market place would make the owner of the system very

wealthy. Thus, many individuals including researchers, investment professionals, and

average investors are continually looking for a software system which will yield them

high returns. There is another motivation in the research and financial communities. The

Efficient Market Hypothesis effectively states that no system can continually beat the

market because if this system becomes public, everyone will use it, thus negating its

potential gain. There has been an ongoing debate about the validity of the Efficient

Market Hypothesis, and some researchers attempted to use neural networks to validate

their claims. There has been no consensus on the Efficient Market Hypothesis validity,

but many market observers tend to believe in its weaker forms, and thus are often

unwilling to share proprietary investment systems. [16]

Page 11: Forecasting Using ANN's

Neural networks (ANN’s) are used to predict stock market prices because they are able to

learn nonlinear mappings between inputs and outputs. Contrary to the Efficient Market

Hypothesis, several researchers claim the stock market and other complex systems

exhibit chaos. Chaos is a nonlinear deterministic process which only appears random

because it cannot be easily expressed. With the artificial neural networks (ANN) ability

to learn nonlinear, chaotic systems, it may be possible to outperform traditional analysis

and other computer-based methods. [16]

Neural networks can be used to learn to predict future events based on the

patterns that have been observed in the historical training data; learn to classify unseen

data into pre-defined groups based on characteristics observed in the training data;

learn to cluster the training data into natural groups based on the similarity of

characteristics in the training data.

2.1 PROCESS OF A BACKPROPAGATION

Back propagation algorithm

The Back propagation algorithm seeks to minimize the error term between the

outputs of the neural net and the actual desired output value. The error term is

calculated by comparing the net output to the desired output and is then fed back

through the network causing the synaptic weights to be changed in an effort to

minimize error. The process is repeated until the error reaches a minimum value. [6]

In a forward pass the outputs are calculated and the error term at the output units

calculated. And in a backward pass, the output unit error is used to alter weights on

the output units. Then the error term at the hidden nodes is calculated by back-

propagating the error at the output units through the weights, and the weights on the

hidden nodes altered using these values.

2.2 BACK PROPAGATION LEARNING ALGORITHM

Page 12: Forecasting Using ANN's

The major steps of the back propagation learning algorithm are given below:

1. Input data to be train.

2. Hidden nodes calculate their outputs.

3. Output nodes calculate their outputs on the basis of Step 2.

4. Calculate the differences between the results of Step 3 and targets.

5. Apply the first part of the training rule using the results of Step 4.

6. For each hidden node in a hidden layer, n, calculate d(n). (derivative)

7. Apply the second part of the training rule using the results of Step 6.

Steps 1 through 3 are often called the forward pass, and steps 4 through 7 are often

called the backward pass.

For each pair of data to be learned a forward pass and backwards pass is performed.

This is repeated over and over again until the prediction error is at a low enough level.

Page 13: Forecasting Using ANN's

Figure 2.1: Flow Graph for the Neural Network

2.3 Calculations and Transfer Function:

Page 14: Forecasting Using ANN's

The behavior of a NN (Neural Network) depends on both the weights and the

input/output function or transfer function that is specified for the units. This function

typically falls into one of three categories:

Linear

For linear units, the output activity is proportional to the total weighted Wij output.

Threshold

For threshold units, the output are set at one of two levels, depending on whether the

total input is greater than or less than some threshold value.

Sigmoid

For sigmoid units, the output varies linearly but not continually as the input changes.

Sigmoid units accept a greater resemblance to real neurons than do linear or threshold

units, but all three must be considered rough approximations.

The network uses Equation 1 to update the weight Wij from a given node i N to the

current node j N ; where t refers to the number of times the network has been updated

and ‘l’ refers to the learning parameter. The learning parameter, or learning rate,

controls the rate the weight is changed as learning takes place. The sensitivity of

node j N to a change in weight Wij is represented by W ije and will be defined more

fully below.

Ii = ∑WijOi + θ

Oi = 1 / 1 + e-i

OUTPUT LAYER:

Errj = Oj (1-Oj)(Ij – Oj)

HIDDEN LAYER:

Errj = Oj (1-Oj)∑ ErrWij

Also , Bias and weight changes are as follows

∆θ = L Errj

∆Wij = L Errj Oi

Page 15: Forecasting Using ANN's

Figure 2 .2: Back Propagation

2.4 REVIEW

CHAN Man-Chung, WONG Chi-Cheong, LAM Chi-Chung [8] collect daily

trading data of eleven companies in 1994-1996 from Shanghai Stock Exchange for

technical analysis of stock price. The first 500 entries were used as training data. The

remaining 150 were testing data. The raw data is preprocessed into various technical

indicators to gain insight into the direction that the stock market may be going. Ten

technical indicators were selected as inputs of the neural network. [8]

The training phase of a back propagation network is an unconstrained nonlinear

optimization problem. The goal of the training is to search an optimal set of connection

weights in the manner that the errors of the network output can be minimized. [8]

Besides popular steepest descent algorithm, conjugate gradient algorithm is

another search method that can be used to minimize network output error in conjugate

directions. [8]

Backpropagation is a difficult technique. It runs the risk of being trapped in local

optimum. The starting node of the connection weights becomes an important issue to

reduce the possibility of being trapped in local optimum. Random weight initialization

does not guarantee to generate a good starting point. It can be enhanced by multiple linear

regressions. In this method, weights between input layer and hidden layer are still

Page 16: Forecasting Using ANN's

initialized randomly but weights between hidden layer and output layer are obtained by

multiple linear regression. [8]

EMA is a trend-following tool that gives an average value of data with greater

weight to the latest data. Difference of EMA can be considered as momentum. RSI is an

oscillator which measures the strength of up versus down over a certain time interval.

High value of RSI indicates a strong market and low value indicates weak markets.

MACD, a trend-following momentum indicator, is the difference between two moving

average of price.

In order to avoid difficulty in getting network outputs very close to the two

endpoints, the indicators were normalized to the range of [0,1], before being input to the

network. [8].

Empirical results have shown that Neural Networks outperform linear regression.

Since stock markets are complex, nonlinear, dynamic and chaotic. Neural networks are

reliable for modeling nonlinear, dynamic market signals. [8]

Birgul Egeli, Meltem Ozturan, and Bertan Badur [9] performed research on

Turkish stock market. Network architecture is chosen is Multi-Layer Perceptron and

Generalized Feed Forward networks. Testing and training is performed using these two

network architectures. The results are then compared with the results of moving

averages (MA) for 5 and 10-day time periods, which showed that artificial neural

networks (ANN) have better performances than moving averages. [9]

2.5 MODELING OF STOCK MARKET INDEX VALUE

The ANNs can effectively be used to predict the Stock Exchange using index

values S&P 500 Index. Supervised learning models have been utilized in which certain

output nodes were trained to respond to certain input patterns and the changes in

connection weights due to learning caused those same nodes to respond to more general

classes of patterns.

2.5.1 DATA SETS

Page 17: Forecasting Using ANN's

Experimental data were gathered by using commercial software for USA starting

from March 10, 2010 to April 20, 2010. From this data set, the first 7 cases (about 90%)

were taken as training and remaining as testing examples.

2.5.1 NETWORK PARAMETERS

For the system model described before, Artificial Neural Network model is

applied with random number of hidden layers (For e.g. HL = 1, 2, 4) for Learning rate

input by the investor /user for the data set.

2.5.1.1 Momentum

The momentum parameter controls how much of the previous weight adjustment

is applied to the current weight adjustment. As larger values are used for momentum, the

greater the influence of the current correction term, relative to previous correction terms.

Momentum can also be used to provide a smoothing effect for weight adjustments [15].

2.5.1.2 Training Rate

Training rate also known as Learning Rate determines the amount of the

correction term applied to adjust neuron weights. A small value for training rate tends to

increase learning time and decrease the probability of overshooting an optimal solution.

A small value also increases the likelihood of being stuck in local minima. Large values

for training rate increase the chance of no learning occurring at all. [15]

2.6 TRAINING RESULTS

In this study, ANN models were applied to the system model, using an ANN

software package. ANN models’ performances can be measured by the coefficient of

determination (R2) or the mean relative percentage error. This coefficient of

determination is a measure of the accuracy of prediction of the trained network models.

Higher R2 values indicate better prediction. The mean relative percentage error may also

be used to measure the accuracy of prediction through representing the degree of scatter.

[9]

2.7 SELECTION OF TECHNICAL VARIABLES

Page 18: Forecasting Using ANN's

The selection of technical variables for input to the technical neural network is

influenced by the technical variables discovered during the formal literature review Stock

market indicators such as moving averages, stochastic oscillators, RSI etc are used By

Nikhil Bakshi Stock [12].

The ANN performances can be compared with Moving Averages (MA) approach

for example. The moving average is the average of lagged index values over a specified

past period ------------- (25 and 50 days in this study). The mean relative percentage errors

were calculated as -----------days.

2.8 SYSTEM MODEL

Using historical data, a neural network can be learned that describes how trading

signals are related to subsequent price movements. The trained neural network can then

be applied to new data to predict future price movements and make investments. [12]

2.8.1 Hidden Layer

One hidden layer is used with a configurable number of neurons. A regular sigmoid

function is used as a transfer function.

2.8.2 Output

The output is the expected price change in a window of days. The value is in the

continuous [0,1] range with 1.0 representing a 10% rise, 0.5 representing no price change

and 0.0 representing a 10% price drop.

2.8.3 Training

The neural network's weights are learned using the backpropagation algorithm with a

configurable learning rate and number of epochs. [12]

The input variables were the highest and lowest prices paid during the day, the

closing price. The output variable used in this study was prepared according to the

direction of the index on the following day. The closing price is first normalized by the

investor using Min-Max Normalization using the scale [0, 1]. Then data is loaded for the

input of Neural Network.

For the purposes of this study, all data relating to an index (the highest and lowest

prices paid during the day and the closing price) was obtained from using the

commercially available software the NEURO Stock master. [10]

Page 19: Forecasting Using ANN's

CHAPTER # 3

RESEARCH METHODOS / DESIGN

3.1 The Research Questions

Page 20: Forecasting Using ANN's

The following research questions allow the research to meet the objectives proposed:

What is the mathematical theory behind the Back propagation neural network?

Can neural networks accurately forecast a stock market index?

Can neural networks be used as a practical forecasting tool by individual

investors?

Conduct a literature review of books magazines and World Wide Web on the topic of

neural networks Identify the mathematical theory of the back propagation neural

networks. . Select a Stock Index to make forecasts upon. Determine what to forecast

and the future point for the forecast variable Days. Determine the inputs to the neural

network assemble the historical input data and preprocesses it using MS Excel.

3.1 DATA FLOW DIAGRAM OF SOFTWARE:

Page 21: Forecasting Using ANN's

Figure 3.1 Data Flow Diagram

3.2 ER_DIAGRAM OF DATABASE USED TO STORE INPUTS:

Page 22: Forecasting Using ANN's

Figure 3.2 Database Design

3.3 CLASS DIAGRAM OF SOFTWARE:

Page 23: Forecasting Using ANN's

Neuron

+ThresholdValue+LastInputValue

+SigmoidFunction()+SigmoidfunctionPrime()+GetSumOfInputWeigths()+Output()

Connection

-Weight-PreviousWeight

NeuralNetwork

+MaxIterations+LearningRate+Momentum+RandomMin+RandomMax

+Learn()+Output()+Randomize()-CalculateErrors()-UpdateWeights()

Layer

-LastOutputValues+Output

1

*

1

*

*

*

Figure 3.3 Class diagram of the system

Neuron class represents the artificial neuron, the basic structure of a neural

network. It carries a threshold value, has input values, uses a sigmoid function and

combination of those properties are used to calculate the overall output. Neurons are

connected to each other with connection lines which carry weights, represented by the

Connection association class. Neurons reside in layers, so the Layer class represents the

artificial layer where a layer contains one to many neurons and a neuron can only reside

in one layer. Therefore, the relationship between a neuron and a layer is one-to-many.

The neural network, which is represented by the Neural Network class, has parameters

Page 24: Forecasting Using ANN's

like Max Iterations, Learning Rate, and Momentum and consists of several layers.

Therefore, the relationship between Neural Network and Layer classes is one-to-many.

The training algorithm is backpropagation and the threshold function used in artificial

neurons is the sigmoid function. The program is developed as a library package so that it

can easily be used.

3.4 USE CASE DIAGRAM

Page 25: Forecasting Using ANN's

Figure 3.4 Use Case Modeling of software designed

In addition to stock market prediction, neural networks have been trained to

perform a variety of financial related tasks. There are experimental and commercial

systems used for tracking commodity markets and futures, foreign exchange trading,

financial planning, company stability, and bankruptcy prediction. As the application of

neural networks in the financial area is so vast, this paper will focus on stock market

Page 26: Forecasting Using ANN's

prediction.  In stock trading, there are typically two methods used to determine whether

to buy or sell a stock fundamental analysis and technical analysis.

Fundamental analysis in forecasting stock market prices is used to evaluate the

intrinsic value of the underlying asset of the stock by examining related economic and

company-specific information. Technical analysis is used to forecast and identify patterns

in stock prices from historical prices and the traded volume of the stock. Due to the

widely available dataset of accurate historical prices (open, high, low and close) and the

volume traded, this project will focus on these as inputs to the Neural Network. The

following indicators, which are derived from historical prices and commonly used in

technical trading, are also included as inputs to the NN: simple moving average,

exponential moving average, moving average convergence divergence, relative strength

index, and stochastic oscillator. Finally, although neural networks are used primarily as

an application tool in the financial environment, several research improvements have

been made during their implementation. Notable improvements in network design and

training and the application of theoretical techniques are demonstrated by the

examination of several example systems.

3.6. ANALYTICAL METHODS

Before the advent of computer, traded stocks and commodities primarily on

intuition. As the level of investing and trading grew, people searched for tools and

methods that would increase their gains while minimizing their risk. Statistics, technical

analysis, fundamental analysis, linear regression is all used to attempt to predict and

benefit from the market’s direction. None of these techniques has proven to be the

consistently correct prediction tool that is desired, and many analysts argue about the

usefulness of many of the approaches. However, these methods are presented as they are

commonly used in practice and represent a base-level standard for which neural networks

should outperform. Also, many of these techniques are used to preprocess input data, and

their results are fed into neural networks as input. [11]

3.6.1 FUNDAMENTAL ANALYSIS

Page 27: Forecasting Using ANN's

Fundamental analysis involves the in-depth analysis of a stock company’s

performance and portability to determine its share price. A method of evaluating a

security level that entails attempting to measure its intrinsic value by examining related

economic, financial and other qualitative and quantitative factors. Fundamental analysts

attempt to study that can affect the security's value, including macroeconomic factors

(like the overall economy and industry conditions) and company-specific factors (like

financial condition and management). 

The  goal of performing fundamental analysis is to produce a value that an investor can

compare with the security's current price, with the aim of figuring out what sort of

position to take with that security value (underpriced = buy, overpriced = sell or short

notpriced =hold).

This Fundamental analysis is considered to be the opposite of technical analysis. 

The advantages of fundamental analysis are its systematic approach and its ability

to predict changes before they show up on the charts. Companies are compared with one

another, and their growth prospects are related to the current economic environment. This

allows the investor to become more familiar with the company. Also, it is hard to time the

market using fundamental analysis. Although the outstanding information may warrant

stock movement, the actual movement may be delayed due to unknown factors or until

the rest of the market interprets the information in the same way. However, fundamental

analysis is a superior method for long-term stability and growth. Basically, fundamental

analysis assumes investors are 90% logical, examining their investments in detail,

whereas technical analysis assumes investors are 90% psychological, reacting to changes

in the market environment in predictable ways. [11]

3.6.2 TECHNICAL ANALYSIS

The idea behind technical analysis is that share prices move in trends dictated by

the constantly changing attitudes of investors in response to different forces. Using price,

volume, and open interest statistics, the technical analyst uses charts to predict future

Page 28: Forecasting Using ANN's

stock movements. Technical analysis rests on the assumption that history repeats itself

and that future market direction can be determined by examining past prices. Thus,

technical analysis is controversial and contradicts the Efficient Market Hypothesis.

However, it is used by approximately 90% of the major stock traders. Despite its

widespread use, technical analysis is criticized because it is highly subjective. Different

individuals can interpret charts in different manners.

Price charts are used to analyze trends. Trends are assumed to be based on supply

and demand issues which often have cyclical or wave patterns. There are a variety of

technical indicators derived from chart analysis which can be formalized into trading

rules or used as inputs to neural networks. Some technical indicator categories include

filter indicators, momentum indicators, trend line analysis, cycle theory, volume

indicators, wave analysis, and pattern analysis. Indicators may provide short or long term

information, help identify trends or cycles in the market, or indicate the strength of the

stock price using support and resistance levels.

An example of a technical indicator is the moving average. The moving average

averages stock prices over a given length of time allowing trends to be more visible.

Several trading rules have been developed which pertain to the moving average. For

example, "when a closing price moves above a moving average a buy signal is

generated."[11]. unfortunately, these indicators often give false signals and lag the

market. That is, since a moving average is a past estimate, a technical trader often misses

a lot of the potential in the stock movement before the appropriate trading signal is

generated. Thus, although technical analysis may yield insights into the market, its highly

subjective nature and inherent time delay does not make it ideal for the fast, dynamic

trading markets of today.

3.7 Classification of Indicators

Indicators are mathematical/statistical functions that are applied over stock properties

such as close, high, low and volume. These Indicators are broadly classified into the

following important categories:

Market Momentum Indicators

Page 29: Forecasting Using ANN's

Market Volatility Indicators

Market Trend Indicators

Broad Market Indicators

General Momentum Indicators

The following are some of the basic indicators that are used for creating the baseline

model. These indicators are known to provide useful information for forecasting using

neural networks.

3.7.1 Relative Strength Index

Relative Strength Index is a measure of the strength that is intrinsic in a field and is

calculated using the amount of upward and downward price changes over a given period

of a time. It has arrange of 0 to 100 with values typically remaining b/w 30 and 70 .The

formula for computing Relative strength Index is as follows

RSI=100-[100/ (1+RS)]

Where RSI=Relative strength Index

RS=Average of x days up closes average of x days closes.

In addition, the value is defined 100 when no downward price changes occur during the

period of calculation.

Relative Strength Index usually leads by the price by forming peaks and valleys

before the price data, especially around the values 30 and 70.

When the RSI diverges from the price, the price eventually follows a corrective

trend towards the direction of the Index.

3.7.2 Money Flow Index

Money Flow Index is a measure of the strength of the monetary investment flowing into

or out of a stock traded in the open market. It is principally derived by comparing the

volume of upward and downward price changes over a given period of time. The money

flow Index is based on the quantity of Money Ratio, which is the ratio of positive money

flow to negative money flow over the given period of time.

Money Flow=Typical Price * Volume

Money Ratio= Positive Money Flow Negative Money FlowMFI=100 - 100 1+Money Ratio

Page 30: Forecasting Using ANN's

Positive Money Flow is defined as sum of prices multiplied by the volume on

days when the price increases. Negative Money flow is defined similarly, except that it

includes only days when the prices decreases. The Money Flow Index typically has the

range of 0 to 100 with values rarely exceeding the bounds 20 and 80.

3.7.3 Stochastic Oscillator

The stochastic Oscillator may be defined as a measure of the difference between the

current closing price of a security and its lowest low price, relative to its highest high

price for a given period of a time.

The value is a percent rating for the closing price, relative to the trading range b/w

its recent highest and lowest prices. A value of zero indicates that the security had a

closing price at its lowest recent low. A value of 100 indicates it that the security had a

closing price at its highest recent high. The value is often smoothed using a slowing

period to eliminate noise in the trend graph. It is used in technical analysis.

3.7.3.1 Interpretation

The idea behind to use this indicator is that prices tend to close near their past highs in

bull markets, and near their lows in bear markets. Transaction signals can be spotted

when the stochastic oscillator crosses its moving average.

Two stochastic oscillator indicators are typically calculated to assess future variations in

prices, a fast (%K) and slow (%D). Comparisons of these statistics are a good indicator of

speed at which prices are changing or the Impulse of Price.  %K is the same as Williams

%R, though on a scale 0 to 100 instead of -100 to 0, but the terminology for the two are

kept separate.

The fast stochastic oscillator or Stoch %K calculates the ratio of two closing price

statistics: the difference between the latest closing price and the lowest price in the last N

days over the difference between the highest and lowest prices in the last N days:

Where:

CP is closing price

Page 31: Forecasting Using ANN's

LOW is low price

HIGH is high price

3.7.4 Moving average Convergence /divergence (MACD)

The MACD is the difference b/w the short and long term moving averages for a

field .The MACD is generally a specific instance of a value Oscillator and is mostly used

on the closing price of a security to detect price trends .When the MACD is on an

increasing trend, prices are trending higher. If the MACD is on decreasing trend, prices

are trending lower.

3.7.5 Moving Averages:

Moving Average is calculated by averaging together the previous values over the given

period, including the current value.

MA = Σ Closing Price n

Moving averages are useful for eliminating noise in raw data. Analysis of the moving

average of the price yields a more general picture of the underlying trends.

3.7.6 Simple moving average

A simple moving average (SMA) is the un weighted mean of the previous n data

points. For example, a 10-day simple moving average of closing price is the mean of the

previous 10 days' closing prices. If those prices are then the

formula is

When calculating successive values, a new value comes into the sum and an old

value drops out, meaning a full summation each time is unnecessary,

Page 32: Forecasting Using ANN's

Perhaps the simplest of all Time series forecasting techniques is a moving aver-

age. To use this method, we calculate the average of, say, three periods of actual demand

and use that to forecast the next period's demand. If this three-period average is to be

used as a forecast, it would have to forecast demand in a future period. [14]

Because each average moves ahead one period each time, dropping the oldest

value and adding the most recent, this procedure is called a moving average. The number

of periods to use in computing the average may be anything from 2 to 12 or more, with 3

or 4 periods being common. If the time series is such that there is no upward or

downward trend, then the moving average is a satisfactory technique. If, how-ever, there

is any trend or any seasonal effect, then the moving average will not work very well.

Moving averages lag behind any trends.

3.8 BASIC FORECASTING TECHNIQUES

Forecasting techniques (APPLIED IN THIS THESIS) can be divided into two

categories: qualitative and quantitative. The former, which involve numbers, uses

methodology that is not mathematical. Qualitative techniques rely on judgment, intuition,

and subjective evaluation. Among the major techniques within this category are market

research (surveys), Delphi (panel consensus), historical analogy, and management

estimation (guess).

3.8.1Qualitative Techniques

Commercial packages are also a reference for comparison of the results of the

software developed. Several commercial neural network packages are widely used in

Artificial Neural Network studies, one of which is Neuro Stock master1.3, for USA.

This section discusses the techniques used to develop the neural network and

multiple regression financial forecasting models. The combination of these models, with

historical and conditional probabilities, will allow the investor to make decisions based

on probabilities of success. The presentation first discusses the development of the

Page 33: Forecasting Using ANN's

models, followed by the historical probability calculations and concludes with the

conditional probability calculation. The information to be forecast was first identified.

Three separate indexes were chosen, the first was the S&P 500 and predicted on last 15

bars. Accurate forecast is possible when predicting the percent change versus the actual

closing value of a stock or index. For example, if the S&P500 index is calculated from

date 22-07-08 to 04-05 10(chart #1) Open value in 25-01-10 was 1092.4 and closing

value 1096.78.

In moving simulation, prediction is done while moving the target learning and

prediction periods. For example, initially the system is trained on data from January,

tested on data for February, and then used to predict data for March. In the next iteration,

the system trains on the February data, tests on the actual March data, and then predicts

data for April. In this way, the system is continually updated based on the most recent

data and its performance is improved.

Page 34: Forecasting Using ANN's

The first neural network model, named S&P 500 Index *SPX the inputs to the model

where developed by first downloading the following raw data from Dial Data using Data

Downloader software:

S&P 500 Index

NASDAQ

Dow Jones Industrial Index

The data set encompassed the different trading days. The data was charted using

stock charting software called STOCK NEUROMASTER 1.33. This established date

integrity within each index. Using Microsoft Excel, each index text file was combined

into one spreadsheet. The resulting file was formatted such that each index and its date

were in a separate column with each row representing a trading day.

An example of a partial data set can be found in Appendix B. Date integrity is

extremely important to the neural network. To ensure integrity was maintained, each

index’s date column was checked for integrity against the S&P500 date using a simple “if

then” rule in Excel. If the dates were equal, it placed a zero in a row. If the dates were

not equal, Excel placed a 1 in a row. This function was copied down the entire data set

and then summed at the bottom. A sum of zero represented no date integrity

discrepancies.

Prediction statistics for buy, sell and hold are also tabulated separately

[APPENDIX A]

S&P 500 Index

NASDAQ

Dow Jones Industrial Index

This (CHART) represents the future closing price of the S&P500 Index and was the

actual value the network used to compare against its prediction during training. This

future information was created by simply copying the S&P 500 closing price into the last

column of the spreadsheet deleting the first 10 days of data and moving the remaining

data up 10 rows. Once this was complete, all date columns were deleted with the

Page 35: Forecasting Using ANN's

exception of the one associated with the S&P 500 data. The file was saved as an Excel 4

worksheet so it could be imported into NEUROSTOCK MASTER. .

The following data was imported into the neural network software package as a

pattern file:

S&P500 O NASDAQ O DOW Jones O

S&P500 H NASDAQ H DOW Jones H

S&P500 L NASDAQ L DOW Jones L

S&P500 V NASDAQ V DOW Jones V

S&P500 C NASDAQ C DOW Jones C

3.8.2 Quantitative Technique:

When attempting to forecast demand for a new item, one faces a shortage of

historical data. If the there is no special event data is very similar, quantitative techniques

may be used. But if the relationship is vague, it may be more appropriate to relate the

products only qualitatively in order to get an impression of demand patterns or aggregate

demand. [1]

Page 36: Forecasting Using ANN's

Chapter # 4

COLLECTION OF DATA AND IMPLEMENTAION

Software Tools:

Software Tools required for the implementation of the software:

1. Microsoft Visual C # 2005 Express Edition

2. AForge.net Framework 2.1.2 version

3. Microsoft Access 2003-2007

4. Microsoft Windows XP 2007

Include Libraries:

AFoge.Neuro.dll

AForge.Controls.dll

AForge.dll

Include Sources:

Core

Page 37: Forecasting Using ANN's

Control

Neuro

Algorithm:

BackPropagation

Time series

Figure 4.1 Input variables to ANN

Page 38: Forecasting Using ANN's

Figure 4.2 Stock Quotes Database View

Page 39: Forecasting Using ANN's

Figure 2.3 Normalization

Page 40: Forecasting Using ANN's

Figure 2.4 Money Flow Index

Page 41: Forecasting Using ANN's

Figure 2.5 Stochastic Oscillator

Page 42: Forecasting Using ANN's

Figure 2.6 Relative strength indexes

The data collected by using an available software as a sample for S&P

500, Nasdaq’s and Dow Jones for open, high, low, close and volume .Buy sell is also

indicated in separate tables .The bar graphs are also plotted in order to analyze time series

forecasting using the software designed in order to validate the ability of Neural

Networks ability to forecast the stock Market Prices.

Page 43: Forecasting Using ANN's

S &P 500:

Table 4.1

NASDAQ:

Page 44: Forecasting Using ANN's

Table 4.2

Page 45: Forecasting Using ANN's

Table 4.3

Page 46: Forecasting Using ANN's

DOW

Table 4.4

Page 47: Forecasting Using ANN's

Table 4.5

Page 48: Forecasting Using ANN's

Graph 4.1

Page 49: Forecasting Using ANN's

Graph 4.2

Page 50: Forecasting Using ANN's

Graph 4.3

Page 51: Forecasting Using ANN's

Chapter # 5

Analysis

The learning rate (training rate) was set to ---0.1&0.2---and the momentum was

set to ---0 or 0.1----. Within the Training Criteria module, pattern selection was set to

random, calibration interval was set to every random patterns and stopping criteria was

set to stop training at --1000--events since minimum average error within the test set.

Within the training module, the network was set to automatically save the weights for the

best test set. The network was then trained within the Training module. The trained

network was then applied to the ----2----sample test patterns.

A testing period to find a suitable model for the problem area is observable due to

the lack of methodologies for use in the development of an Artificial Neuron Network

Model. An intuitive Approach is needed for the architecture in order to develop a suitable

model and develop parameters relating to the training statute. Backpropagation seems fit

for the time series Analysis and is an effective model in the prediction of Stock Exchange

Market S&P 100 Index. Training was not realized in some of the ineffective models, with

a resulting failure to decrease the percentage of the error in the network. In some cases,

the network memorized the data, resulting in an observable tendency to decrease the

percentage of error in the training data, while increasing the percentage of error in the test

data. All ineffective models were eliminated, and as a result, the model, parameters given

above, found the training data to be----80 to 88----% in 2 Or 3 iterations.

No of testing Data Points 25

Page 52: Forecasting Using ANN's

No of correct change predictions 22

No of incorrect change predictions 3

Percentage Accuracy 88%

Learning Rate & Momentum 0.1 & 0

Table 5.1

No of testing Data Points 45

No of correct change predictions 38

No of incorrect change predictions 7

Percentage Accuracy 84 %

Learning Rate & Momentum 0.2 & 0.1

Learning Error 0.268

Table 5.2

Page 53: Forecasting Using ANN's
Page 54: Forecasting Using ANN's
Page 55: Forecasting Using ANN's
Page 56: Forecasting Using ANN's

Chapter #6

CONCLUSION & DISCUSSIONS

Everybody wants to know whether the stock market will be up or down

tomorrow. Marketing analyst want to predict future sales. Economists want to predict

economic cycles. Banks can use neural networks to scan credit and loan applications to

estimate bankruptcy probabilities, while money managers can use neural networks to plan

and construct profitable portfolios in real-time.

It is to expect that ‘Time series Forecaster” can be improved to make

predictions with greater accuracy in the following ways:

Including more selective fundamental factors, technical indicators, and broader

market indices into the input data set.

Fine tuning and proper training the network topology and learning parameters.

This thesis has attempted to analyze the Artificial Neural Networks

ability to forecasts stock market prices. In doing so, it has laid down a structured

approach to creating trading systems using neural networks, and has defined the key

characteristics necessary to benchmark these trading systems tested on out-of-sample

data. Backpropagation neural network is employed during this thesis, focusing on

different sets of input variables, and they were trained and tested over different portions

of the market. The purpose of this section of the thesis is to provide a discussion on why

the neural networks achieved the results they did, and then to formally draw conclusions

about the research question and thesis hypotheses from the results. Another possible

explanation is that the neural network did not perform poorly, and that it gave good

signals, however, these signals were not focused enough to allow a trading system to

profit. This implies that when the market is rising, many stocks tend to benefit and

participate in this rise. By implication, when the overall market is listless for a prolonged

period, any strategy which relies on exploiting abnormal returns has limited its scope for

success.

Function profiles are excellent tools to visually inspect the profile of any mathematical

function. They allow a deep and visual understanding of functions characteristics, and

provide the ability to visually assess the function profile in varying timeframes

Page 57: Forecasting Using ANN's

simultaneously. Their main limitation becomes apparent when considering the function

profile for the poorly performing Artificial Neural Networks. This limitation is that the

function profile is not contextual. In other words, for a given output strength forecast by

the Artificial Neural Networks, the average return displayed in the function profile is the

average return of all the observations for that output strength.

This thesis has effectively attempted to document and explain the

forecasting stock market return anomalies by using separate Artificial Neural Networks

trained with fundamental and technical data.

It was noted in the literature review that there is a growing trend towards

using the ensemble approach to analysis amongst soft-computing researchers.

REFERENCES

Page 58: Forecasting Using ANN's

[1]. Spyros Makridakis & Steven C. Wheelwright, Forecasting Methods for Management,

Fifth Edition,. John Wiley & Sons

[2]. Satish Kumar, NEURAL NETWORKS A classroom approach, International Edition

by McGraw Hill.

[3].Application of Back-Propagation neural network in data forecasting.ppt searched

from http//:www.google.com.

[4]. Thesis by Jason E.Kutsuralis, Forecasting financial Market using Neural Network,

September 1998.

[5]. An Empirical Methodology for Developing Stockmarket Trading Systems using

Arti_cial Neural Networks By Bruce J. Vanstone_ Gavin Finniey

[6]. Haykin, Simon, Neural Networks: A Comprehensive Foundation, Macmillan

College Publishing Company, New York, New York, 1994.

[7]. http://en.wikipedia.org/wiki/Elliott_wave_principle

[8]. CHAN Man-Chung, WONG Chi-Cheong, LAM Chi-Chung, Financial Time

Series Forecasting by Neural Network Using Conjugate Gradient Learning Algorithm

and Multiple Linear Regression Weight Initialization

[9]. Birgul Egeli, Meltem Ozturan, Bertan Badur Stock Market Prediction Using

Artificial Neural Networks

[10].By BirolYildiz, Abdullah Yalama, and MetinCoskun Forecasting the Istanbul Stock

Exchange National 100 Index Using an Artificial Neural Network

[11].Robert J. Van Eyden. The Application of Neural Networks in the Forecasting of

Share Prices. Finance and Technology Publishing, 1996.

[12].By Nikhil Bakshi Stock Market Prediction Using Online Data: Fundamental and

Technical Approaches ETH Zurich, August 2008

[13].http://en.wikipedia.org/wiki/Stock_market

[14].http://www.fxnonstop.com/index.php/component/content/article/35-indicators/55-

moving-average

[15] By Bruce James Vanstone Trading in the Australian Stock market using Artificial

Neural Networks

[16] Using Neural Networks to Forecast Stock Market Prices , By Ramon Lawrence

Page 59: Forecasting Using ANN's

[17].Design and implementation of NN5 for Hong Kong stock price forecasting By

Philip M. Tsanga,_, Paul Kwoka, S.O. Choya, Reggie Kwanb, S.C. Nga, Jacky Maka,

Jonathan Tsangc, Kai Koongd, Tak-Lam Wonge.

[18]. http://www.complexity.org.au/ci/vol02/cmxhk/cmxhk.html

[19] By Akinwale Adio T, Arogundade O.T. and Adekoya Adebayo F. “Translated

Nigeria Stock Market Prices Using ANN for effective Prediction “