8
Image Processing & Communication, vol. 17, no. 4, pp. 275-282 DOI: 10.2478/v10248-012-0056-5 275 PREDICTION OF CLOSING PRICES ON THE STOCK EXCHANGE WITH THE USE OF ARTIFICIAL NEURAL NETWORKS MICHAL PALUCH,LIDIA JACKOWSKA-STRUMILLO Computer Engineering Department, Technical University of Lodz, Lodz, Poland [email protected] Abstract. Article describes, the use of Arti- ficial Neural Networks (ANN) for predicting values of Stock Exchange shares. Rules of Stock Exchange functioning, principles of tech- nical analysis and the most important stock market indices are described, which support in- vestors, who plan to make transactions. ANN of Multi-Layer Perceptron (MLP) type, and a moving window method are applied. A hybrid method is also proposed, in which time series of CLOSE values as a function of the follow- ing trading days are used to stock market in- dices calculation, such as moving averages and oscillators, which are applied to ANN inputs. Research was conducted for 80 companies, se- lected from the 1218 companies functioning on Stock Exchange. The achieved maximum er- ror in one day ahead CLOSE value prediction is 1,31%. 1 Introduction Nowadays, when economics is supported by IT (Informa- tion Technology) the modern trading systems can meet the most demanding customer needs. With the increase of trading systems’ complexity there is also a grow- ing interest in combining them with artificial neural net- works [2, 4, 7, 10, 11], with an objective of maximiz- ing profits. The financial market, which uses the most advanced IT solutions, provides a variety of products to meet this goal. From all of them, the most popular are fi- nancial instruments offered by the Stock Exchange, which may be the most profitable but there is also a risk of los- ing all assets [3]. This is why the Stock Exchange as a nonlinear dynamic system [10] is a challenge for the de- veloped modelling schemes in which artificial neural net- work (ANN) are gaining in importance. The relation be- tween risk and profit is presented in Fig. 1. Examples of possible use of ANN on the Stock Ex- change are prediction of future stock market indices [2, 7, 10], exchange rates [11], share prices, etc. The most commonly used artificial neural networks to pre- dict the trading signals are the feedforward neural net- works (FNN) [4, 7, 11] and probabilistic neural networks (PNN) [10], but also new approaches and ANN structures, like for e.g. State Space Wavelet Network (SSWN) [2] are still the subject of scientific studies. However, analyzing the market state and examples from literature [3, 4], it was found that it is risky to make investment decisions based solely on ANN prediction and Unauthenticated | 85.86.26.162 Download Date | 3/17/14 3:52 PM

Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

  • Upload
    tetazas

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

Image Processing & Communication, vol. 17, no. 4, pp. 275-282DOI: 10.2478/v10248-012-0056-5 275

PREDICTION OF CLOSING PRICES ON THE STOCK EXCHANGE WITHTHE USE OF ARTIFICIAL NEURAL NETWORKS

MICHAŁ PALUCH, LIDIA JACKOWSKA-STRUMIŁŁO

Computer Engineering Department, Technical University of Lodz, Lodz, Poland

[email protected]

Abstract. Article describes, the use of Arti-

ficial Neural Networks (ANN) for predicting

values of Stock Exchange shares. Rules of

Stock Exchange functioning, principles of tech-

nical analysis and the most important stock

market indices are described, which support in-

vestors, who plan to make transactions. ANN

of Multi-Layer Perceptron (MLP) type, and a

moving window method are applied. A hybrid

method is also proposed, in which time series

of CLOSE values as a function of the follow-

ing trading days are used to stock market in-

dices calculation, such as moving averages and

oscillators, which are applied to ANN inputs.

Research was conducted for 80 companies, se-

lected from the 1218 companies functioning on

Stock Exchange. The achieved maximum er-

ror in one day ahead CLOSE value prediction is

1,31%.

1 Introduction

Nowadays, when economics is supported by IT (Informa-

tion Technology) the modern trading systems can meet

the most demanding customer needs. With the increase

of trading systems’ complexity there is also a grow-

ing interest in combining them with artificial neural net-

works [2, 4, 7, 10, 11], with an objective of maximiz-

ing profits. The financial market, which uses the most

advanced IT solutions, provides a variety of products to

meet this goal. From all of them, the most popular are fi-

nancial instruments offered by the Stock Exchange, which

may be the most profitable but there is also a risk of los-

ing all assets [3]. This is why the Stock Exchange as a

nonlinear dynamic system [10] is a challenge for the de-

veloped modelling schemes in which artificial neural net-

work (ANN) are gaining in importance. The relation be-

tween risk and profit is presented in Fig. 1.

Examples of possible use of ANN on the Stock Ex-

change are prediction of future stock market indices [2,

7, 10], exchange rates [11], share prices, etc. The

most commonly used artificial neural networks to pre-

dict the trading signals are the feedforward neural net-

works (FNN) [4, 7, 11] and probabilistic neural networks

(PNN) [10], but also new approaches and ANN structures,

like for e.g. State Space Wavelet Network (SSWN) [2] are

still the subject of scientific studies.

However, analyzing the market state and examples

from literature [3, 4], it was found that it is risky to make

investment decisions based solely on ANN prediction and

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 2: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

276 M. Paluch, L. Jackowska-Strumiłło

Fig. 1: Relation between profit and risk in the most popular financial instruments [14]

without the use of risk models. Analysis of the market

situation should be approached on many levels. Techni-

cal analysis provides many tools that can accomplish this

goal. Therefore, in this work a hybrid approach combin-

ing technical analysis and ANN is proposed.

2 The functioning of the stock ex-change and an introduction totechnical analysis

Stock Exchange is a place where buyers and sellers ex-

change the goods after establishing jointly accepted price.

Trading is immaterial meaning that all securities are

stored in the form of electronic records in the system of

National Depository for Securities and on customers’ in-

vestment accounts in brokerage houses.

Each order of buying and selling must contain specific

information such as the name of the security, type of order,

the date, value, number, etc. Stock Exchange is a place in

which, within a short time, much can be gained and much

can be lost. Still, it is difficult to talk about long-term

income without having a strategy. In this aspect, investors

can be divided into two groups [12]:

• long-term investors, who, on the basis of a de-

tailed fundamental analysis of companies, buy a

large amount of shares and sell after a few months

or sometimes even years,

• short-term investors, who, in order to minimize the

risk, close the positions every day, and their invest-

ment decisions are based on technical analysis.

Fundamental analysis means detailed immersion in the

activity of the company in which one is going to invest,

its sector and related sectors. Technical analysis is a type

of market research, mainly with the help of charts and in-

dicators. The study is based on three premises [12]:

• The market discounts everything.

• Prices are subject to trends.

• History repeats itself.

According to the above principles, technical analysis can

serve as a starting point for creating a transaction system,

which, on the basis of the decisions of an artificial neural

network, provides the user with a set of companies that

achieve the highest profit and the highest loss. As a conse-

quence, the user obtains information on when and which

securities should be sold or bought.

3 Application of ANN for predictionof closing prices

Closing price of the asset for the next day is the most im-

portant parameter for investors, who plan to make trans-

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 3: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

Image Processing & Communication, vol. 17, no. 4, pp. 275-282 277

actions at the Stock Exchange. In this work a hybrid

approach combining technical analysis and ANN is pro-

posed, which can support them in making correct deci-

sions. The main idea of the proposed method is shown

in Fig. 2. Technical analysis methods are used to calcu-

late moving averages and oscillators, which are important

market indicators. These are the inputs of ANN, which

predicts the CLOSE value for the next day. The aim of

this work was to investigate, if the proposed data prepro-

cessing and market indicators calculation would improve

the ANN effectiveness in the CLOSE value prediction.

Feedforward networks of Multi-Layer Perceptron

(MLP) type trained with the backpropagation algo-

rithm [8] were used for the CLOSE value prediction. For

the comparison purposes the CLOSE value signal was

predicted by the use of MLP and so called moving win-

dow method [6], in which the network is exposed to cur-

rent and a number of past samples of the signal.

For research purposes, quotations of 1218 companies

appearing on the stock market were downloaded and lim-

ited to the data since 3.01.2000 until 27.01.2012. The

programming application was designed and implemented

for the data collecting and preprocessing. The calculated

moving averages and oscillators were used for neural net-

work training and testing. Finally, the results obtained

with the hybrid and with the purely ANN-based approach

were compared.

4 Averages and indicators used fornetworks training

Technical analysis provides many tools that support in-

vestors in making decisions. The most commonly used

are moving averages and oscillators, which were selected

for the proposed approach [5]. These include the follow-

ing:

• Moving averages:

a. Arithmetical (5-, 10-, 20-days) - SMA (Simple Mov-

ing Average)

SMAN (k) =1

N[C(k) + C(k − 1) + . . .

+C(k −N + 1)] (1)

where: N - number of days, N = 5, 10, 20 C(k) - closing

price in the k-th day

b. Weighted (5-, 10-, 20-days) - LWMA (Linearly

Weighted Moving Average)

LWMAN,C(k) =NC(k) + (N − 1)C(k − 1) + . . .

N + (N − 1) + . . .+ 1

+C(k −N + 1)

N + (N − 1) + . . .+ 1(2)

c. Expotential (5-, 10-, 20-days) - EMA (Expotential

Moving Average)

EMAN,C(k) =C(k) + aC(k − 1) + a2C(k − 2) + ...

1 + a+ a2 + ...+ aN−1

+aN−1C(k −N + 1)

1 + a+ a2 + ...+ aN−1(3)

where: a - coefficient,

d. Envelopes (3% error with 20-days average)

e. Bollinger Bands These tools are used to study the al-

ready existing trend. Their task is to signal the

launch of a new trend or a reversal of the current

trend. They follow the trend and not precede it, so

they do not predict market behavior. They are used

primarily to mitigate deviations of prices. Addition-

ally, the Bollinger band and envelopes are used to

determine when the market is overbought.

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 4: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

278 M. Paluch, L. Jackowska-Strumiłło

Fig. 2: Processing scheme for predicting course of a CLOSE value for the next day

• Oscillators

a. ROC - Rate of Change (5-, 10-, 20-days) - determines

the rate of price changes in a given period (usually

10 days)

ROCN (k) = C(k)/C(k −N) (4)

b. RSI - Relative Strength Index - i.e. the measure of

overbought / oversold market. It assumes values in

the range of 0-100. For values greater than 70 it is

considered that the market is buyout. When oscilla-

tor values are below 30, it means that market is sold

out. In the case of periods of strong trends it is as-

sumed that the market is buyout when RSI > 80 (at

the time of a bull market) and sold out for RSI < 20

(during a bear market).

For:

C(k) > C(k − 1), U(k) = C(k)− C(k − 1)

C(k) < C(k − 1), D(k) = |C(k)− C(k − 1)|

RSI(k) = 100−

100

1 +EMAN,U (k)EMAN,D(k)

(5)

where U(k) - average increase in the k-th day, D(k) -

average decrease in the k-th day

c. Stochastic oscillator (K%D) - determines the relation

between the last closing price and the range of price

fluctuations in the given period. The result belongs

to the range of 0-100. K%D > 70 is interpreted

as the closing price near the top of the range of its

fluctuations, and K%D < 30 points to the fact that

prices are shaping near the lower limit of that range.

%K = 100[C(k)− L(14)/(H(14)− L(14))] (6)

where: L(14) - the lowest price from last fourteen days,

H(14) - the highest price from last fourteen days

d. Moving Average Convergence/Divergence (MACD)

is the difference between two moving averages. On

the graphs, it usually occurs with 10- day, exponen-

tial moving average (called the signal line). The in-

tersection of the signal line (SL) with the MACD

line coming from the bottom is a buying signal, while

with the line from the top selling signal.

MACD(k) = EMA12,C(k)− EMA26,C(k) (7)

SL(k) = EMA9,MACD(k) (8)

5 Experimental research

Research was conducted for 80 companies appearing on

the stock market in Warsaw since 3.01.2000 until now, se-

lected from the all 1218 companies functioning on stock

market since 1991. The aim of the research was to test

different ANN architectures and to choose the best one

for predicting the CLOSE value of the asset for the next

day. The research was performed with the use of Java and

Neuroph 2.6. library, creating ANN of Multi-Layer Per-

ceptron (MLP) type. Each network consists of an input,

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 5: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

Image Processing & Communication, vol. 17, no. 4, pp. 275-282 279

Tab. 1: Combinations of the tested MLP architecturesInput layer Hidden layer Output

n+ 1n 1, 5n 1

2n− 12n+ 1

where n - number of neurons (n = 4, 5, 6 neurons)

hidden and output layer. A common feature of all of the

tested network architectures is a small number of the input

nodes and neurons in the hidden layer, and only one neu-

ron in the output layer. Too many neurons would increase

the network training error and could cause learning time

extension [4]. The relations between the number of input

nodes and the number of neurons in the hidden layer were

tested for the combinations shown in Tab. 1.

Market indicators for the input data were selected as

described in literature [1, 4, 5, 13] or randomly. ANN

training was performed according to the following rules:

1. All entered data were normalized using the following

formula:

(V alue/V aluemax) ∗ 0, 8 + 0, 1 (9)

2. The results of each company were divided into two

groups: learning data and testing data in the propor-

tion 80:20 [9].

3. Weights for each input were set randomly.

4. Neural networks were taught with the back propaga-

tion algorithm with momentum factor [7, 8].

5. For each ANN architecture and each set of input

data, eight neural networks were trained, and the

ANN with the smallest error has been selected as the

best one.

As a result of these studies six best ANN architectures

with the smallest training and testing errors have been se-

lected. The results for these ANN architectures obtained

for one exemplary company Asseco Poland SA are pre-

sented in Tab. 2. An example of MLP (5-9-1) structure,

which is listed in position 1 is shown in Fig. 3.

Fig. 3: An example of Multi-Layer Perceptron MLP (5-9-1) - position 1 in Tab. 2

The neural network of MLP (5-9-1) structure shown in

Fig. 3 is composed of an input layer which consists of five

input nodes and a hidden layer with nine neurons. The

result is derived in a single output. The above architecture

represents one of the tested relations between the number

of neurons in the input layer and their number in the hid-

den layer. The results of short-term forecast of CLOSE

value of Asseco Poland SA shares in August 2011 pre-

dicted with the use of MLP (5-9-1) network are presented

in Fig. 4 and in Tab. 3.

6 Summary and conclusions

The presented studies on application of neural networks

for predicting the closing prices on the stock exchange

have shown that the relatively low rates of errors were

achieved (less than 1,5%). Hence, the studied neural

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 6: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

280 M. Paluch, L. Jackowska-Strumiłło

Tab. 2: Architectures of the selected networks, which achieved the best resultsNo. Input MLP Transfer Periods Training Testing

function error error(MSE) (MSE)

SMA10

SMA20

1. Bollinger Band 5-9-1 sigmoidal 1000 0,026 0,0017RSI

MACDSMA10

2. MACD 4-5-1 sigmoidal 4000 0,031 0,0024Bollinger Band

RSILWMA5

3. LWMA20 4-7-1 sigmoidal 1000 0,027 0,0021Envelope

RSIEMA5

EMA10

4. Bollinger Band 6-9-1 sigmoidal 4000 0,034 0,0028ROC

MACDRSI

EMA5

EMA20

5. Envelope 6-9-1 sigmoidal 700 0,032 0,0023K%D

MACDRSI

CLOSE values6. from last 5-6-1 sigmoidal 2500a 0,0018 0,0011a

five days

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 7: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

Image Processing & Communication, vol. 17, no. 4, pp. 275-282 281

Fig. 4: Short-term forecast of MLP (5-9-1) network, with real CLOSE value of Asseco Poland SA shares in August2011

Tab. 3: Comparison of real quotes and network forecastfor Asseco Poland SA

Data CLOSE CLOSE Relativereal network error in

quotes forecast prediction[PLN] [PLN] [%]

1-08-2011 47,67 47,21 0,972-08-2011 47,8 47,28 1,083-08-2011 46,9 46,45 0,974-08-2011 45,17 44,71 1,025-08-2011 43,85 43,46 0,888-08-2011 40,95 40,67 0,689-08-2011 39,81 39,73 0,19

10-08-2011 37,5 37,82 0,8411-08-2011 37,15 37,51 0,9812-08-2011 39,47 39,45 0,0616-08-2011 39,88 39,78 0,2617-08-2011 39,38 39,36 0,0518-08-2011 36,99 37,37 1,0419-08-2011 36,39 36,87 1,3122-08-2011 37,25 37,6 0,9323-08-2011 37,2 37,55 0,9324-08-2011 36,9 37,29 1,0625-08-2011 38,74 38,84 0,2526-08-2011 38,21 38,28 0,1929-08-2011 39,45 39,19 0,6630-08-2011 39,8 39,45 0,8731-08-2011 42,5 42,23 0,63

network based model can be used to make good invest-

ment decisions and reduce the risk of loss. The results

presented in Tab. 2, allow to conclude that for all stud-

ied networks, the best results were obtained by the net-

work architecture no. 6 in Tab. 2, for which, in the in-

put, CLOSE values for last five days were forwarded.

In this approach, the ANN was able to predict with the

low error rate, CLOSE value for next day. Nevertheless

this approach has disadvantages. ANN is exposed to re-

ceive false signals from the market, which may ultimately

lead to increase network errors. This explains the differ-

ences between the current and predicted by the network,

CLOSE values in a number of periods. Taking this into

consideration, the safer solution would be to use a neu-

ral network architecture no. 1 in Tab. 2. This network

features a larger error, but is not so vulnerable to false

signals from the market because economic models are in-

corporated into the proposed hybrid modeling scheme.

However, because the Stock Exchange market, often

occurs uncontrollable, there is a need to protect invest-

ments by additional mechanisms and risk models, miti-

gating the impact of similar situations on the "investor’s

wallet." Still, regardless of the number of the developed

neural networks and economic models, it should be the

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM

Page 8: Prediction of Closing Prices on the Stock Exchange With the Use of Artificial Neural Networks

282 M. Paluch, L. Jackowska-Strumiłło

stock broker who makes the final decision to purchase or

sell securities.

References

[1] R. Bensignor, New Concepts in Technical Analysis,

Wig-Press, (in Polish) Warsaw 2004

[2] M.A. Brdys, A. Borowa, P. Idzkowiak, M.T. Brdys,

Adaptive Prediction of Stock Exchange Indices by

State Space Wavelet Networks, Int. J. Appl. Math.

Comput. Sci., Vol. 19 , No. 2, pp. 337-348, 2009

[3] W. Debski, Financial Market and it mechanisms,

(in Polish), PWN, Warsaw 2010

[4] Ed. Gately, Neural Networks - Financial forecasting

and transactional systems design, (in Polish), Wig-

Press, Warsaw 1999

[5] J.J. Murphy, Technical Analysis of Financial Mar-

kets, (in Polish), Wig-Press, Warsaw, 2008

[6] K.S. Narendra, K. Parthasarathy, Identification and

control of dynamics systems using neural networks,

IEEE Transactions on Neural Networks, Vol. 1, No.

1, pp. 4-27, 1990

[7] P. Sutheebanjard, W. Premchaiswadi, Stock Ex-

change of Thailand Index Prediction Using Back

Propagation Neural Networks, In Proc. of the Sec-

ond International Conference on Computer and Net-

work Technology (ICCNT), Bangkok, pp. 377-380,

2010

[8] R. Tadeusiewicz, Artificial Neural Networks, (in

Polish), Warsaw 1993

[9] R. Tadeusiewicz, Discovering Neural Networks, (in

Polish), Cracow 2007

[10] C.D. Tilakaratne, S.A. Morris, M.A. Mammadov,

C.P. Hurst, Predicting Stock Market Index Trading

Signals Using Neural Networks, In Proc. of the 14th

Annual Global Finance Conference (GFC 2007),

Melbourne, Australia, pp. 171-179, Sep. 2007

[11] D. Witkowska, Artificial Neural Networks and sta-

tistical methods, Selected financial issues, (in Pol-

ish), C. H. Beck, Warsaw 2002

[12] A. Zaremba, Stock Exachange, (in Polish), 2010

[13] J. Zielinski, Intelligent management systems - the-

ory and practice, (in Polish), Warsaw 2000

[14] http://www.mbank.pl/inwestycje/centrum-

inwestora/fundusze/narzedzia/ryzyko-

inwestycyjne.html

Unauthenticated | 85.86.26.162Download Date | 3/17/14 3:52 PM