0% found this document useful (0 votes)
8 views5 pages

Financial

This paper presents a method for optimizing moving average-based stock trading rules using particle swarm optimization (PSO) to enhance profitability. It discusses the effectiveness of trading signals generated by the golden cross strategy and evaluates the performance of the proposed method on real-world stock market indices over three years. The results indicate that the PSO algorithm successfully determines optimal long/short durations for moving averages, leading to improved trading outcomes.

Uploaded by

sabbar.thijeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Financial

This paper presents a method for optimizing moving average-based stock trading rules using particle swarm optimization (PSO) to enhance profitability. It discusses the effectiveness of trading signals generated by the golden cross strategy and evaluates the performance of the proposed method on real-world stock market indices over three years. The results indicate that the PSO algorithm successfully determines optimal long/short durations for moving averages, leading to improved trading outcomes.

Uploaded by

sabbar.thijeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2009 International Conference on Artificial Intelligence and Computational Intelligence

Moving Average-based Stock Trading Rules from Particle Swarm Optimization

N.M. Kwok G. Fang Q.P. Ha


School of Mechanical and School of Engineering School of Electrical, Mechanical and
Manufacturing Engineering University of Western Sydney Mechatronic Systems
The University of New South Wales Penrith, NSW 1797, Australia University of Technology Sydney
Sydney, NSW 2052, Australia Broadway, NSW 2007, Australia

Abstract—Trading rules derived from technical analysis are Investors have also considered various computations and
valuable tools in making profits from the financial market. modellings of market trends [5] in order to obtain profitable
Among those trading rules, the moving average-based rule buy/sell signals. Among those techniques, an evolutionary
has been the most widely adopted choice by a large number
of investors. Buy/sell signals are identified when curves of approach was adopted to segment price series to derive
long/short averages cross each other. With an attempt to trading indicators [6]. The use of a genetic algorithm was
optimize the rule and maximize the trading profit, this paper employed to generate a trading rule [7] which may adapt
propose the use of the particle swarm optimization algorithm rapidly to changes in market sentiments. Within the domain
to determine the appropriate long/short durations when calcu- of evolutionary computing, the genetic programming method
lating the averages. Trading signals are subsequently generated
by the golden cross strategy. The best combination of long/short was also used to derive trading rules, see [8].
durations is determined by comparing the profits that can There are various outcomes of technical analysis including
be made among alternative durations. Real-world indices, the moving average (MA) and relative strength index (RSI)
covering three years approximately, from several established which have been well studied and successfully applied in
and emerging stock markets are used to verify the effectiveness stock trading [9]. Their relative performance was evaluated
of the proposed method.
in [10] that considers the effect of interventions in the
foreign exchange market. A comparison between MA and
I. I NTRODUCTION the Bollinger Bands was conducted in [11] and concludes
that the latter does not outperform the MA.
The making of profits is an ultimate goal of investors par- The trading rules within the family of technical analysis
ticipating in the financial market. Traditional investment op- have been mostly designed with parameters adopted from
portunities include trading bonds, shares, foreign exchanges general trader practices such as the choice of durations in the
and precious metals. Among these alternatives, trading in the MA methods. In this regard, researches have began to focus
stock market has been the most popular channel of financial their attentions towards optimizing the trading rules. In [12],
investments. the genetic algorithm was employed to determine the rule
In order to make profits, investors have found that intu- coefficients. Moreover, it was investigated in [13] whether
itions and sentiments are insufficient to guarantee positive adaptive rules would make the investment more profitable.
returns. However, it is also challenging to have positive In summary, the MA trading rule is a popular rule
gains when the market involves a huge number of investors employed in the financial sector to guide buy/sell decisions.
trading against each other. The efficient market hypothesis On the other hand, optimizing and tuning of the rule are
[1] confirms that advantages gained by an investor are foreshadowed to enhance trading profitabilities. Attempts
vulnerable to be neutralized by others when they also have have also been made to use intelligent computation methods
access to the same kind of market information. Investors to derive high performing rules. In this work, a particle
then considered that historical data may provide indications swarm optimization (PSO) algorithm is proposed to tune
of future price movements. To this end, trading rules deriving the parameters of the MA trading rule, namely, the durations
from technical analysis [2] have become a major focus of used in calculating the long/short averages. The PSO is cho-
most investors. sen because of its implementation simplicity, as compared
The history of technical analysis can be traced back to the to the GA, and its performance endorsed in a wide domain
use of candlesticks developed in the seventeenth century [3]. of engineering design and optimization applications.
This technique considers the relationships between the high, The rest of the paper is organized as follows. In Section
low, open and closing prices on a trading day. An alternative II, the MA trading rule is reviewed. The proposal for the
approach in technical analysis may focus on using past price PSO-based tuning method is presented in Section III. Per-
fluctuation patterns as templates [4] to identify changes in formances determined from experimental results are given
price trends. in Section IV. Section V contains the conclusion.

978-0-7695-3816-7/09 $26.00 © 2009 IEEE 149


DOI 10.1109/AICI.2009.418
II. M OVING AVERAGE - BASED T RADING RULE is limited to 5 lots. Moreover, due to the delay in the
The moving average trading rule can be considered as availability of market information and commissions to be
a delayed indicator of price or index variations. The MA paid, the actual profit made by the investor is a weighted
rules are able to filter out fluctuations that could reduce risks function of the index values.
incurred from trading with market sentiments. Rules are When a buy signal is observed, from day τ and provided
derived by averaging past price records over some durations. the buying power is not exceeded, then the investor buys
Crossing of the traces of two averages with short and long one lot at the price on day τ + δ and pays a commission.
durations are then used to generate buy or sell signals. The investor’s profit is given by

A. Moving Average and Trading Signals Pτ +δ = Pτ − Iτ +δ × α, (3)


Consider the N-day moving average [9] given by where δ = 2 is the delay in obtaining market information,
t
 Iτ +δ is the stock index when the buy transaction is executed,
1
Mt,N = Pi , (1) α = 1.01 denotes the additional commission paid.
N Similarly, when a sell signal is generated on day κ and
i=t−N +1

where the subscript t denotes the current trading day, Pi is provided the investor has already held stocks, he or she sells
the closing price of a trading day. The closing prices for one lot and pays a commission to the broker. The investor’s
the previous N days are averaged. With shifts in the current profit becomes
trading day, t, a series of average is obtained and is used to Pκ+δ = Pκ + Iκ+δ × β, (4)
generate trading signals.
The so-called moving is reflected by the change of the where β = 0.99 illustrates the reduction of profit due to
current day t that also results in a different starting day. the commission paid. The investor’s profit may be derived
The most popularly chosen durations (N ) are 5, 10, 50, 250 from equations 3 or 4 depending on the latest transaction
days. Their choices may be due to the fact of five trading executed.
days per week and the longest 250 days corresponds to an III. I NTELLIGENT T UNING OF T RADING RULE
approximate duration of one year. The other choices may be
Trading transactions and profits made by the investor are
interpreted as trading in two and ten weeks.
results of decisions based on the MA rule described in
As a common practice among investors, two averaged
Section II. As the investor’s objective is to make a profit, it
series of different durations are used. Consider averages
is important that the rule is tuned in order to maximize his or
Mt,N1 and Mt,N2 . The first series is called the short average
her return. In this regard, the determination of the durations
while the other is called the long if N1 < N2 . The former
(N1 , N2 ) used in the calculation of MA is accomplished by
follows more closely to the price fluctuation while the latter
a particle swarm optimization algorithm described below.
average indicates a longer term market trend.
Consider a trading day τ , one has the short and long A. Particle Swarm Optimization
averages Mτ,N1 , Mτ,N2 . A trading signal may be generated An recursive optimization algorithm, the particle swarm
by invoking the golden cross strategy [2]. The principle may optimization (PSO) [14], has been developed from the
be stated as: buy when the short average is rising and crosses inspiration of natural behavior of animals in forming into
the long average from below. A sell signal is determined as: swarms. The PSO is an attractive candidate for its flexibility
sell when the short average is falling and crosses the long in tackling challenging problems such as the optimization of
average from above. multi-modal functions. The algorithm has also been success-

⎪ Buy, if Mτ,N1 > Mτ −1,N1 fully adopted in a number of engineering applications, for

and Mτ,N1 > Mτ,N2 instance, model parameter identification [15].
T rading = . (2)

⎩ Sell, if Mτ,N1 < Mτ −1,N1 In the function optimization domain, the PSO algorithm
and Mτ,N1 < Mτ,N2
encodes potential solutions in a so-called particle xki , where
B. Profit Generation i = 1, · · · , n is the index of the particle, k is the iteration
The investor’s profit, denoted as P , is generated from a count. After the particles are initialized randomly across
combination of buy and sell transactions. Furthermore, the the solution space, they are set into motion in search for
investor is trading the stock market index (as a simplified an optimal solution by emulated social interaction and self-
case which is in fact possible to do so through fund houses, experiences. The velocity vik+1 used to move a particle to
hence, price and index are used interchangeably in the rest its subsequent location is given by
of the paper). It is assumed that at the beginning of the vik+1 = wik ⊗ vik + ckg ⊗ (xkg − xki ) + ckp ⊗ (xpi − xki ), (5)
investment period, the investor processed zero profit. The
buying power of the investor is also limited below a certain where wik is the motion inertia factor, ckg and ckp are
number of lots. In a typical scenario, the buying power gain coefficients responsible for determining the influences

150
between the so-far best performing particle xtg and the best A. Test Data
instance of individual particles xpi . The elements of the Closing stock indices of established and emerging mar-
gain coefficients are confined within limits such as ctg ∈ kets that are used in the tests with different degrees of
[cg,min , cg,max ] and ctp ∈ [cp,min , cp,max ] sampled from volatility. These markets are chosen as typical scenarios with
some probability distributions, e.g., uniform or Gaussian. independent historical trends and fluctuation characteristics
Note that the multiplications are componentwise and are reflecting high and low volatilities. For each index, the
denoted as ⊗ in equation 5. closing prices over 750 trading days for approximately 3
The best performing particle xkg is determined by a years are collected and the MAs are calculated accordingly.
problem dependent fitness function, e.g., f (xki=1,··· ,n ) such
that g = argmaxi f (xki=1,··· ,n ) for a maximization problem. B. Test Results
Similarly, the instance of best performance of an individual
particle xpi is given by p = argmaxτ f (xτi =1,··· ,k ). The next In the plot of indices and averages, the indices are
position of a particle is then obtained from depicted in black while the short and long MAs are drawn
in red and green respectively. The buy signals are indicated
xk+1
i = xki + vik+1 , (6) by a blue upward triangle and sell signals are inverted
red triangles. An annotation is also given illustrating the
assuming a time step of unity. It is evident from equation profit made as a ratio to the latest price, the short and long
6 that the future location of a particle or its behavior durations, and the number of lots currently holding.
is influenced by its motion inertia, the interaction among 1) Bombay Stock Exchange Security Index: The Bombay
others and its own past experience given by the three terms stock market is considered as an emerging market. Figure
expressed in equation 5. 1(a) shows the rising trend until a severe correction started
from beyond the 450th trading day. The MA durations are
B. Tuning of Trading Rule
11 and 29 illustrating that a short/medium term buy-hold
With regard to obtaining the MA traces that generate trad- strategy is profitable.
ing signals, the durations are encoded as particles in the PSO 2) Dow Jones Industrial Average: The Dow Jones In-
algorithm. That is xki = [N1,i N2,i ]T , where for n particles, dustrial Average (DJI) may be regarded as one of the most
there are n pairs of durations (N1,i , N2,i ), i = 1, · · · , n. established market index. It is characterized by small and
Furthermore, setting in-line with common practices, the slow fluctuations, Fig. 1(b). The MA durations are 14 and 32,
durations are bounded by N1,i , N2,i ∈ [5, 50]. indicating approximately an average for three to six weeks
For a pair of durations (forming a particle in PSO), MA is most profitable. Note that the market is showing a recent
traces are calculated and trading signals obtained. The profit rebound, with a buy signal generated.
at the current day is used as the fitness of the particle. The 3) Financial Times Stock Exchange Index: The London
pair of durations that gives a largest profit is treated as the stock exchange (FTSE) is also one of the longest established
best performing particle. In the next PSO iteration, other markets. The index has experienced several medium-term
particles are steered to investigate the solution space in the fluctuations, see Fig. 1(c). The best performing pair of
vicinity of the best performing particle. The iteration repeats durations for the MAs is 15 and 41 days. The investor is
in order to ensure that the obtained solution is accepted holding stocks in hand. Despite the negative profit resulted,
with sufficient confidence until the algorithm terminates. The the magnitude of loss is acceptable where the the index had
strategy adopted to terminate the iterations is based on the been fallen for more than 33%.
saturation of the profits made. According to the criteria given 4) Hang Seng Index: The Heng Seng Index (HSI) of
in [16] with an acceptable error in making such decision, Hong Kong may be regarded as the market that is correlated
the PSO terminates after ten iterations where there is no to both established and emerging markets. Within the test
increase of profit made. That is, terminate the PSO iteration period, the index peak and the deep changed by a twofold,
if Pk = Pk−ω , where ω = 10 is the elapse of iterations that Fig. 1(d). There was a correction of over 50% and a rebound
there is no increase in profit. is recently observed. The MA durations are 16 and 37 which
The investor now has the pair of MA durations (N1 , N2 ) suggest a medium-term strategy is preferable.
given by the PSO algorithm and the buy/sell signals gener- 5) Nasdaq Composite: Technology shares are the major
ated, he or she then proceeds to execute the trading. class of stocks included in the Nasdeq index (IXIC), see Fig.
1(e). Since the severe correction in year 2000, investors are
IV. E XPERIMENT
quite cautious in this market. The MAs are 9 and 34 days.
In order to verify the effectiveness of the proposed ap- The investor is holding one lot at present. The separation
proach in making profits from investing in the stock market found in the two MAs may suggest that the market is difficult
using the PSO-tuned MA trading rule, tests are conducted to predict and whether short, medium or long term strategy
and results presented in this section. should be adopted is rather inconclusive.

151
6) Nikkei: The Nikkei index (NKK) of Japan is depicted aggregation of technical analysis trading indicators will be
in Fig. 1(f) for the test period. The Japan market is estab- attempted to further increase investment profits.
lished but its performance is rather not correlated with other R EFERENCES
markets. The profit available is 6% and the MAs are 7 and
48 days. It is observed that although buy/sell signals are [1] C. I. Lee, M. S. Pan, and Y. A. Liu, “On market efficiency
of asian foreign exchange rates: evidence from a joint vari-
issued during the fall, there is no buy signal during massive ance ratio test and technical trading rules,” Journal of Intl.
corrections. Financial Matkets, Institutions & Money, vol. 11, pp. 199–
7) Shanghai Composite: The Shanghai stock market 214, 2001.
(SSEC) may be regarded as one of the most profitable but [2] C. Fyfe, J. Marney, and H. Tarbert, “Technical analysis versus
volatile in the group of emerging markets. The index peaked market efficiency - a genetic programming approach,” Applied
Financial Economics, vol. 9, pp. 183–191, 1999.
to almost three times as compared to the start of the period [3] B. R. Marshall, M. R. Young, and L. C. Rose, “Candle-
considered, Fig. 1(g). The profit achievable is 2.99 and the stick technical trading strategies: can they create value for
MAs are 17 and 25 and short/medium-term trading strategies investors?” Journal of Banking & Finance, vol. 30, pp. 2303–
should be adopted. 2323, 2006.
8) Taiwan Weighted Index: The Taiwan Weighted Index [4] T. C. Fu, F. L. Chung, R. Luk, and C. M. Ng, “Stock time
series pattern matching: template-based vs. rule-based ap-
(TWII) is another example of un-correlated performance proaches,” Engineering Applications of Artificial Intelligence,
with other major markets. In Fig. 1(h), it is seen that the vol. 20, pp. 347–364, 2007.
strongest rebound is taking place. The profit obtained is 0.91 [5] N. G. Pavlidis, D. K. Tasoulis, V. P. Plagianakos, and M. N.
and the MAs are 23 and 30. From the MAs, it is suggested Vrahatis, “Computational intelligence methods for financial
that the investor should take a medium-term strategy when time series modeling,” Intl. Journal of Bifurcation and Chaos,
vol. 16(7), pp. 2053–2062, 2006.
trading in this market. [6] F. L. Chung, T. C. Fu, V. Ng, and R. W. P. Luk, “An evolu-
tionary approach to pattern-based time series segmentation,”
C. Summary and Discussion vol. 8(5), pp. 471–489, 2004.
A summary of the profits made from the markets under [7] M. Matilla-Garcia, “Are trading rules based on genetic al-
test is given in Table I. The table also contains the parameters gorithms portable?” Applied Economic Letters, vol. 13, pp.
tuned in the moving averages and the holding of stocks 123–126, 2006.
[8] J. Y. Potvin, P. Soriano, and M. Vallée, “Generating trad-
currently. If the investor is following the proposed MA-based ing rules on the stock markets with genetic programming,”
trading rule, he or she is able to make a profit from most Computers and Operations Research, vol. 31, pp. 1033–1047,
of the established and emerging markets. In particular, the 2004.
trading in the Shanghai Composite is most profitable. [9] M. M. Wong, W. K. and B. K. Chew, “How rewarding is
technical analysis? evidence from singapore stock market,”
Table I Applied Financial Economics, vol. 13, pp. 543–551, 2003.
S UMMARY OF RESULTS . [10] T. C. Shik and T. T. L. Chong, “A comparison of ma and rsi
returns with exchange rate intervention,” Applied Economics
Index Profit Short Long Letters, vol. 14, pp. 371–383, 2007.
BSESN 0.90 11 29 [11] J. M. J. Leung and T. T. L. Chong, “An emprical comparison
DJI 0.57 14 32 of moving average envelopes and bollinger bands,” Applied
FTSE -0.09 15 41 Economics Letters, vol. 10, pp. 339–341, 2003.
HSI 1.58 16 37 [12] F. F. dez Rodriguez, C. González-Martel, and S. Sosvilla-
IXIC 0.24 9 34 Rivero, “Optimization of technical rules by genetic algo-
NKK 0.06 7 48 rithms: evidence from the madrid stock market,” Applied
SSEC 2.99 17 25
TWII 0.91 23 30 Financial Economics, vol. 15, pp. 773–775, 2005.
[13] C. A. Ellis and S. A. Parbery, “Is smarter better? a cmparison
of adaptive, and simple moving average trading strategies,”
Research in International Business and Finance, vol. 19, pp.
V. C ONCLUSION 399–411, 2005.
This paper has presented an approach aimed at generating [14] J. Kennedy and R. Eberhart, “Particle swarm optimization,”
buy and sell signals for trading in a number of established in Proc. 1995 IEEE Intl. Conf. on Neural Networks, Perth,
Australia, 1995, pp. 1942–1948.
and emerging stock markets. These signals are initiated [15] N. M. Kwok, Q. P. Ha, T. H. Nguyen, J. Li, and B. Samali, “A
on the basis of crossings between two moving average novel hysteretic model for magnetorheological fluid dampers
sequences. The particle swarm optimization algorithm is and parameter identification using particle swarm optimiza-
employed to obtain proper average durations such that the tion,” Sensors & Actuators: A. Physical, vol. 132(2), pp. 441–
profit obtained by an investor could be increased. Tests using 451, 2006.
[16] N. M. Kwok, Q. P. Ha, D. K. Liu, G. Fang, and K. Tan, “Ef-
market indices, encompassing various trends and character- ficient particle swarm optimization: a termination condition
istics, have been conducted. It is shown that the proposed based on the decision-making approach,” in Proc. 2007 IEEE
approach could lead to substantial profits and to reduce Congress on Evolutionary Computation, Singapore, 2007, pp.
losses in unfavorable market conditions. In a future work, 3353–3360.

152
4
x 10 1.38 22 32 0 x 10
4 0.32 23 29 1

2 1.4
1.35
1.8
1.3
Index

Index
1.6 1.25
1.4 1.2

1.2 1.15
1.1
1
100 200 300 400 100 200 300 400
Trading days Trading days
(a) Bombay Stock Exchange Security Index (b) Dow Jones Industrial Average
−0.01 36 43 0 x 10
4 1.65 42 48 0

6600 3
6400
6200 2.5
Index

Index
6000
5800 2
5600
5400
100 200 300 400 100 200 300 400
Trading days Trading days
(c) Financial Times Stock Exchange Index (d) Hang Seng Index
0.22 21 47 1 x 10
4 0.08 40 48 0

2800 1.8
1.7
2600
1.6
Index

Index

2400 1.5
1.4
2200 1.3
1.2
2000
100 200 300 400 100 200 300 400
Trading days Trading days
(e) Nasdaq Composite (f) Nikkei
4.41 7 13 0 0.72 11 20 1
10000
6000

5000 9000
Index

Index

4000
8000
3000
7000
2000

100 200 300 400 100 200 300 400


Trading days Trading days
(g) Shanghai Composite (h) Taiwan Weighted Index

Figure 1. Trading signals from index series under test.

153

You might also like