IMECS2016 pp317-321
IMECS2016 pp317-321
IMECS2016 pp317-321
Choose K data points as initial centroids. no stocks on hand. At the end of the day, when the closing
Repeat price of all stocks were available, stocks were ranked using
Form K clusters by assigning each data point to its the method described in the next section. Using all available
closest centroid. cash, the top 10 stocks in the ranking were bought on the
Re-compute the centroid of each cluster. following day at the opening price on an equal-weight basis.
Until Centroids do not change. The portfolio was then rebalanced once every 20 trading
sessions (approximately one month) by re-computing the
K-means algorithm has been used as part of a process for ranking and making necessary buy/sell orders to maintain
stock trend prediction. For example, [20] used K-Means to top-10 stocks allocation, equally weighted.
aggregate similar technical charts in order to construct
trading rules. C. Stock Ranking
For this experiment, only stocks that were members of the
III. METHOD SET100 constituents on the day of the ranking were
considered. By definition, SET100 comprises 100 largest
A. Data Preparation and most liquid stocks in the market and therefore are most
As of September 2015, there were over 600 listed likely to be investment-grade and least likely to be
companies in the Thai stock market with total market maliciously manipulated. The task was to use trend and
capitalization of over THB 13 trillion. The main market momentum indicators to select a subset of these stocks that
index, the SET Index, is calculated from the stock price of all are most likely to outperform the market in the near term.
listed companies using market-capitalization weight. The Clustering was performed on five attributes: long-term trend
exchange also provides the SET50 and SET100 indices, indicator, short-term trend indicator, long-term momentum
respectively comprising top 50 and 100 stocks chosen based indicator, short-term momentum indicator, and current
on size and liquidity [21]. Constituents of SET50 and market capitalization of the stock. The inclusion of the
SET100 are regularly revised every six months. market capitalization as an attribute is based on a well-
The universe of 162 stocks in this analysis comprises all known observation that large stocks tend to move slower
stocks that have historically ever been included as members than small stocks and thus should be useful in the clustering
of SET100 constituents from January 2011 to September process. For each attribute, data values were normalized.
2015. All price data have been adjusted for any changes in To rank stocks for day i, technical indicator values
par values. calculated on day x-20 (20 trading sessions ago) were used
In order to compare price trend and momentum of in the clustering process. K-means clustering was performed
different stocks, the following four technical indicators were with 10 target clusters, corresponding to an average of 10
calculated. For each day, two trend indicators were stocks per cluster. Initial centroids were the 10 stocks that
computed, one for the long term trend and the other for the were placed equally far apart when ranked by their long-
short term trend. Each indicator is the percentage difference term trend indicator.
between the daily closing price and its exponential moving The resulting clusters of stocks formed 10 portfolios, each
average (3). of which is calculated for profit/loss as if it was held from
day x-20 to day x. The centroid of the most profitable (or
((P - EMA) / EMA) * 100 (3) least lost) cluster is then chosen as the best centroid. Finally,
the stock ranking is the ascending order of stocks based on
their distances to the best centroid (closest stock ranks
The 200-day exponential moving average was used for the
highest) calculated on day x-20. The rationale behind this
long term indicator and the 50-day exponential moving
ranking is that, for a given market condition, the trend and
average was used for the short term indicator.
momentum characteristics of the best-performing group of
For momentum indicators, 125-day and 20-day price
stocks will continue in the same direction.
Rates of Change were used for the long-term and the short-
term momentum indicators, respectively. The time periods
IV. RESULTS
chosen for all indicators were based on [22].
The overall result spanning January 2011 to September
B. Portfolio 2015 is shown in Figure 2. This is the result in which the
The exchange requires a minimum lot size of 100 shares portfolio was fully invested in stocks at all times with no
per trade. To make simulation realistic, a large starting cash holding. Specifically, the SET index generated 29.0%
amount of cash is required to minimize slippage, which is returns over the period, while the proposed method
the difference in quantity and price between the actual trade generated 104.0% return over the same period. It should be
and what the algorithm specifies. For example, if a stock is noted that the compounding effect of reinvested profits
priced at THB 400 per share, a buyer must buy multiples of greatly enhanced the return over the long run. The total
100 shares or multiples of THB 40,000, at a minimum. For commission fee paid was THB 26.5 million and was
this experiment, the starting amount of cash was THB 100 subtracted from the portfolio at the time of each transaction.
million. In addition, for each and every transaction (buying
or selling), a 0.1578% brokerage commission fee, which is
the normal rate for retail investors, was applied.
On the first day, the portfolio consisted of all cash, with
30.0
20.0
150
10.0
100 0.0
-10.0
50
-20.0
0 -30.0
Fig. 2. Portfolio value during the period of 19 consecutive quarters. SET Fig. 3. Quarterly returns using the proposed method compared to the SET
index return is provided for comparison. The return is greatly enhanced due index. During uptrends, the proposed method strongly outperformed the
to compounding effect of profit reinvestment. index. The method underperformed during high-volume sell offs.
To remove long-term compounding effect, the results are Figure 4 shows how performance degraded when number
examined on a quarterly basis and is shown in Table 1 and of stocks in the portfolio increased. There were 100 stocks
Figure 3. Average quarterly return from the SET index was to choose from the SET100 constituents. If the portfolio
1.8% versus 4.7% obtained from the proposed method. consisted of half of these stocks, performance degraded to
The proposed method underperformed the index during near that of the index return. However, if less than 5 stocks
the periods of high-volume sell-offs. Events corresponding were chosen, the return greatly increased, along with risks
to the major sell-offs were the year 2011 Thailand's country- specific to companies and sectors of the holdings.
wide flooding and the year 2013 political instability that led Nevertheless, the increase in return when fewer stocks were
to the coup d'état. These results are consistent with trend held demonstrated that the proposed method is effective in
following strategy as the stocks that have greatly picking out market-outperforming stocks.
outperformed in the past suddenly made reversals and
reverted back to the mean when exceptional events occurred. 350
And since the nature of technical indicators used in the
300
proposed method lag behind prices, it took some time for the
selection process to recover and outperform the market
Final Portfolio Value
250
(THB Million)
again.
200
TABLE I 150
QUARTERLY PERCENTAGE RETURNS
100
Quarter SET Proposed Method Outperformance
1st 2011 2.1 3.6 1.5 50
2nd 2011 2.4 6.5 4.1
3rd 2011 -20.3 -16.7 3.6 0
4th 2011 19.2 13.4 -5.8 1 6 11 16 21 26 31 36 41 46
1st 2012 15.7 16.9 1.2 Number of Stocks in Portfolio
2nd 2012 -0.9 -0.5 0.3
3rd 2012 9.3 22.8 13.5 SET Index Proposed Method
4th 2012 8.3 16.3 8.0
1st 2013 10.1 28.9 18.8
2nd 2013 -5.5 -13.2 -7.6
Fig. 4. Final portfolio value after 19 consecutive quarters for different
3rd 2013 -3.8 -10.2 -6.4
numbers of stocks held in portfolio. The more diverse the portfolio, the less
4th 2013 -12.6 -17.2 -4.6
the return. Holding less than 5 stocks greatly increase the return, but with
1st 2014 12.7 13.7 1.0
less diversification and more risk.
2nd 2014 7.5 17.9 10.3
3rd 2014 6.4 10.3 3.9
4th 2014 -6.6 -4.9 1.7 V. CONCLUSION AND FUTURE WORK
1st 2015 2.9 8.9 6.0
2nd 2015 -2.2 -7.8 -5.5 This paper contributes a method that uses a combination
3rd 2015 -9.8 0.3 10.1 of long-term and short-term, trend and momentum technical
Average 1.8 4.7 2.8 indicators to identify stocks that are most likely to
outperform the market index. The best combination of these
indicators are determined by way of cluster analysis. The
results show that the proposed method can outperform the
market in the long run.
REFERENCES
[1] C. Mateepithaktham, “Equity mutual fund fees & performance,” SEC
Working Papers Forum, The Securities and Exchange Commission,
Thailand, June 2015.
[2] J. Murphy, Technical analysis of the financial markets, New York
Institute of Finance, p 23, 1999.
[3] A. Haldane, “Patience and finance,” Oxford China Business Forum,
Beijing, September 2010.
[4] H. Yu, R. Chen, and G. Zhang, “A SVM stock selection model within
PCA,” 2nd International Conference on Information Technology and
Quantitative Management, ITQM 2014.
[5] C. Huang, “A hybrid stock selection model using genetic algorithms
and support vector regression,” Applied Soft Computing, 12 (2012),
pp. 807-818.
[6] A. Esfahanipour and S. Mousavi, “A genetic programming model to
generate risk-adjusted technical trading rules in stock markets,”
Expert Systems with Applications, 38 (2011), pp. 8438-8445.
[7] T. Chavarnakul and D. Enke, “A hybrid stock trading system for
intelligent technical analysis-based equivolume charting,”
Neurocomputing, 72 (2009), pp. 3517-3528.
[8] J. Larsen, “Predicting Stock Prices Using Tehnical Analysis and
Machine Learning,” Thesis, Norwegian University of Science and
Technology, June 2010.
[9] A. Sundén, “Trading based on classification and regression trees,”
Thesis, Kungliga Tekniska högskolan Institutionen för matematik,
2010.
[10] Y. Hu, K. Liu, X. Zhang, L. Su, E.W.T. Ngai, M. Liu, “Application
of evolutionary computation for rule discovery in stock algorithmic
trading: A literature review,” Applied Soft Computing, 36 (2015), pp.
534-551.
[11] J. Bollen, H. Mao, X. Zeng, “Twitter mood predicts the stock
market,” Journal of Computational Science, 2 (2011), pp. 1-8.
[12] W. Laoniramai, “Insider Trading Behavior and News Announcement:
Evidence from the Stock Exchange of Thailand,” CMRI Working
Paper 3/2013, The Stock Exchange of Thailand.
[13] K. Kwandham, “Insider trade filing and earnings announcement:
evidence from the stock exchange of Thailand,” International
Journal of Technical Research and Applications, Special Issue 16
(Jan-Feb 2015), pp. 69-79.
[14] C. Chotivetthamrong, “Stock market fund flows and return
volatility,” Ph.D. Dissertation, National Institute of Development
Administration, Thailand, 2014.
[15] E. Guresen, G. Kayakutlu, T.U. Daim, “Using artifical neural
network models in stock market index prediction,” Expert Systems
with Applications, 38 (2011), pp. 10389-10397.
[16] Y. Plyakha, R. Uppal, and G. Vilkov, “Equal or Value Weighting?
Implications for Asset-Pricing Tests,” World Finance Conference,
Venice 2014.
[17] N. Amenc, F. Goltz, “Smart Beta 2.0,” The Journal of Index
Investing, Winter 2013, Vol. 4, No. 3: pp 15-23.
[18] M. Covel, Trend following: how great traders make millions in up or
downmarkets, Financial Times Prentice Hall Books, 1st ed., New
Jersey, 2004, pp. 336.
[19] P. Tan, M. Steinbach, V. Kumar, Introduction to Data Mining, 1st ed.
2005, Pearson, p 497.
[20] K. Wu, Y. Wu, H. Lee, “Stock trend prediction by using K-means
and AprioriAll algorithm for sequential chart pattern mining,”,
Journal of Information Science and Engineering, 30 (2014), pp. 653-
667.
[21] SET50 and SET100 Indices Rule, Avalable: https://www.set.or.th
/en/products/index/files/2013-01-SET50-100-IndexRule-EN.pdf
[22] StockCharts Technical Rank, Available: http://stockcharts.com
/school/doku.php?id=chart_school:technical_indicators:sctr