You are on page 1of 6

GoldMiner: A Genetic Programming based

algorithm applied to Brazilian Stock Market

Alexandre Pimenta Eduardo G. Carrano
PPGEE Department of Electrical Engineering
Universidade Federal de Minas Gerais Universidade Federal de Minas Gerais
Belo Horizonte, MG, Brazil Belo Horizonte, MG, Brazil
Department of Computing carrano@cpdee.ufmg.br
Instituto Federal de Minas Gerais
Formiga, MG, Brazil Ciniro Aparecido Leite Nametala
alexandre.pimenta@ifmg.edu.br Department of Engineering and Computing
Instituto Federal de Minas Gerais
Frederico Gadelha Guimarães Bambui, MG, Brazil
Department of Electrical Engineering ciniro@ifmg.edu.br
Universidade Federal de Minas Gerais
Belo Horizonte, MG, Brazil Ricardo H. C. Takahashi
fredericoguimaraes@ufmg.br Department of Mathematics
Universidade Federal de Minas Gerais
Belo Horizonte, MG, Brazil
taka@mat.ufmg.br

Abstract – The possibility of obtaining financial gain by techniques such as fuzzy logic and neural networks are being
investing in the Stock Markets is a hard task since it is under widely used in an attempt to find satisfactory solutions to this
constant influence of economical, political and social factors. This problem [2].
paper aims to address the financial technical analysis of Stock
Markets, focusing on time series data instead of subjective
parameters. An algorithm based on genetic programming,
The automation of stock trade transactions is now a reality,
named GoldMiner, has been proposed to perform retrospective as it can be observed in several studies [2,4,6,7,9]. The
study in order to get predictions about the best time for trading algorithms developed for this purpose ignore the efficient
top stocks on the BOVESPA, the Brazilian stock exchange market hypothesis and, therefore, have faced difficulties in
market. nonlinear time series forecasting.

Keywords – genetic programming, technical analysis, This work proposes a computer system for decision-
exchange market, decision making making in stock trading at the Brazilian exchange market,
BOVESPA. The developed algorithm, named as GoldMiner,
was built based on four main concepts: genetic programming,
I – INTRODUCTION technical analysis of the stock market, scanning step, and
The stock market is seen as a possible source of income, trading systems with targets.
but its nature is complex and unstable. Predicting its future
behavior is not a simple task, since the stock market is The article was structured as follows: section II presents
constantly influenced by economical, political and social the work related to the topic. In section III, schemes of
factors. representation, operators of genetic programming and
indicators of technical analysis are. In section IV, an instance
Some economists claim that the efficient market of the problem and the testing framework is shown. Section V
hypothesis is valid [10]. This theory states that the price discusses the results in four BOVESPA top stocks: BOVA11,
variation of a stock behaves like a random walk and therefore VALE5, PETR4, and BBAS3. Finally, some conclusions are
any price forecasting technique consists on a useless effort. presented in Section VI.
Another issue to be considered is the non-linearity of price
variation of an asset on the stock exchange.
II – RELATED WORK
Despite the difficulties in financial time series forecasting, In this work, the forecasting techniques employed to stock
many efforts have been destined to provide better markets will be classified in three categories: conventional
understanding about the stock markets. Unconventional

978-1-4799-4518-4/14/$31.00 ©2014 IEEE 397

Figure 1 . each individual is composed of two decision Genetic Programming to forecast the stock market. 398 . The features of the system are presented below. a selling decision tree. trees.B.GP) [3] has also been used for this purpose. individuals. In Atsalakis and K. payment of dividends. such as net profit. ARIMA CO Chaikin oscillator (autoregressive integrated moving average). [6] [7] also uses genetic programming for operators AND. in which genetic programming and technical market analysis are combined. Figure 1 shows an example of a buying decision showing gains above the market. OR. market methods and computational intelligence TABLE I – USED INDICATORS based methods. Valavanis EMA Exponential Moving Average [1] a broad study about these techniques is presented. followers. Genetic Programming [4] was the first reference to present a solid employment of In GoldMiner. Up to the authors knowledge. ARMA BB Bollinger Bands (autoregressive moving average models).: the trading system. Using these characteristics.PROPOSED TOOL The proposed tool was inspired by studies carried out in [7]. III . P. the authors demonstrate that computational systems financial volume traded. These indicators were chosen because they represent the four main groups of technical analysis indicators: trend With regard to computational intelligence based methods. B. the verification system. [6] [7] to work with daily trading.methods. 1 Forex is an equity market that is characterized by high liquidity. Genetic programming (Genetic Programming . one for buying and another for selling. stock price at market review of 150 publications that use these techniques. among others. 12 indicators of technical analysis [5] were used as shown in Table I. the goal system and the construction and parameterization of the GP. Besides. a fact that allowed Myszkowski P. WR Williams %R RSI Relative Strength Index Market methods can be divided in two types: fundamental S Stochastic analysis and technical analysis [5]. also called Figure 2 . maximum or minimum of the day and the study. all of them can be obtained fuzzy logic. Valavanis [2] it is shown a based on the values of the time series. XOR and the indicators of technical such a kind of prediction. systems of bands and operators that act the most used techniques employ neural networks and/or against the trend [5]. The logical Myszkowski P. In these references the authors made analysis presented in Table I are used to compose such experiments on the Forex1 and on the Warsaw stock markets.selling decision tree Daytrade Operations. Indicator Name Conventional methods are those created mainly by SMA Simple Moving Average statistics and econometrics. In Atsalakis and K. tree and picture 2. ARCH and OCV Oscillator Chaikin Volatility AD Accumulation and Distribution GARCH models are the techniques of this group with better OBV On Balance Volume results [1]. P. debt level. In this opening or closing. All of these indicators are explained in reference [5]. Technical Analysis In GoldMiner. In fundamental analysis. Four main features distinguish GoldMiner from the system presented by Myszkowski P.B. usually show better results than conventional methods.buying decision tree A. VO Volume Oscillator the investor has parameters that define the company financial PO Price Oscillator position. In technical analysis. the main focus is the stock value and the trade movement in a given period. B. oscillators. GoldMiner is a computational system that uses genetic programming with technical analysis to make decisions and trade stocks in the stock market in an automated way.

Apply the operators (mutation and crossover) fitness in the training phase can be very ineffective in the according to the given probabilities. Its operation consists on the following steps: The rented stocks can be traded without necessarily being owned. ten individuals with the best fitness are selected. mutation [3]. the system of trading on the stock exchange. The initial population of the GP has been implemented 3. 399 . are guided by two decision trees (buying and selling trees). Generate the initial population using the Grow in step 4. called short selling [5]. The verification system was created in order to improve the hit rate. The selected individuals are tested on the using the Grow method. 2. forecasting window. • It buys and sells on the closing price of the market. The selection is based on binary tournament. all the profits subtracted from all losses. checking and • It leverages the capital once the value of available assets. After the training. in the case of GoldMiner. The implementation of the verification system was necessary because it was observed that individuals with best 4.losses) Generation 10 The Fitness is calculated simply by counting the profitability. Figure 3 – window training. as follows: evaluated in the forecasting window. The second module addresses how the C. These decisions are taken based on the buying and selling decision trees. • It uses a target profit of 10% as stop condition. It is responsible for selling. sell or buy. Perform selection using binary tournament. the crossover by point and the shrink window tests I and II. The decision module True True Stay is responsible for making decisions that.. 2. the windows of training. and situations just like the last row of Table III may occur. as shown in Table III. Trading System and Goals Buying Decision Tree Selling Decision Tree Action The core of a system that buys and sells stocks on the False False Stay stock exchange can be divided in two key modules: (i) True False Buy False True Sell decision module and (ii) trading module. 3. The success rate has risen considerably 5. i. TABLE II – CONFIGURATION OF GP Construction of the Tree Grow Method Selection Method Tournament 2 Crossover 90% Mutation 40% (Shrink) Population 60 Fitness All (profit . Evolve the population in the training window. buying or performing shutdown operations. Calculate the Fitness of the solutions. In Figure 3. This type of operation is a practice in the stock market 1. population generated in step 1.B. reaching gains up to 30%. It should be noticed that indicators of technical analysis do not indicate the same action always. Verification System negotiation will be executed. the system of prior check solutions and parameterization of the GP. checking and forecast TABLE III – DECISION MAKING FOR BUYING AND SELLING D. If no individual meets the requirements described 1.e. As stated earlier. The GP follows the steps of 20% return in window tests I and II is chosen to be an evolutionary algorithm. • It makes use of rented stocks. [7] in four specific points: the The trading module that was built has four characteristics: targeting system. 5. The individual with higher fitness and more than parameters are shown in Table II. with the use of the verification system. return to step 2. run the procedure again from a new initial method. If he stop criterion is not met. Fitness = Sum of all profits . forecasting are presented. The configuration and construction of the GP and the training 4. GoldMiner differs from studies carried out by Myszkowski P.sum all losses Each individual of the population can lead to three different decisions: stay.

Up to now. VERIFICATION AND FORECASTING Window Work Time Another feature of the trading system is the moment of Window check I T=30 to T=280 buying and selling the stocks.com Price Position Position Assets Hand PETR4 Stocks of the company Petróleo Brasileiro SA- http://www. To perform the experiment. 2 BOVESPA Index is a market index that measures the return on an Maximum Day. Minimum Day. IV. Indications to buy or to sell a stock at a given moment can be executed only if there are interested buyers and sellers available.vale. checking and increases the operation risks. GoldMiner works leveraging the prediction windows. Each element is composed of Date. This fact enables that predictions and negotiations are carried out at intervals of 5. [7] proposed a software that operates primarily with daytrade operations [5] in a strong liquidity market.Bank of Brazil SA . In Table IV.. leverage is a general term for any technique applied to multiply the profitability through debt. In finance. This variation in with the Brazilian economy. although BOVESPA liquidity is not critical as in other markets (i. stocks by once. INSTANCES AND TESTS Myszkowski P.00 http://www. and operations are done at market close. considering the forecast from 2013 to early 2014 [11]. It has been set that when GoldMiner reaches a profit of The starting date of the forecast window was added by two 10%. The profitability of the Brazilian the forecast window aimed to test the consistency and government bonds ranged between 8% and 10% annually. Another common practice in the stock market is to validation and prediction were performed in the range of T = leverage [5] in purchase and sale transactions. Volume. a brief description of each of them is shown.br Technical analysis uses the time series of a particular stock as input. Closing Value and Negotiated investment in a theoretical portfolio calculated by BM & FBOVESPA. any forecasting system to daytrade operations should consider book offerings. then the operations are closed.petrobras. TABLE VI – EXAMPLE OF THE TRADE SYSTEM WITH BOVA11 Code of the Description stock BOVA11 follows BOVESPA index Step Market Initial Final Evolution of Cash on VALE5 Stocks of Vale SA . even for top stocks (so-called Blue Chips). This profit is compatible days each test. These stocks have been selected because they have representation in BOVESPA index and they present liquidity for being bought and sold in day candles.com. Forex).bb. 10 and 15 minutes.000. 1 R$ 57. robustness of the results achieved by GoldMiner. TABLE V – TRAINING WINDOW. The leverage also Table V presents the intervals of training.. to 60 exchange at the closing of the day.4. there are two moments on the day in which buying and selling indications of blue chips can be executed with high probability: one hour after the market opening and at the final 30 minutes [8]. and it was repeated 30 times. GoldMiner used the same composed of stocks issued by companies that account for over 80% of the time interval for the four stocks mentioned.00 R$ 2. Therefore. 30 on 02-24-2010 until T = 1026 on 02-28-2014.e. PETR4 and BBSA3. example of the trading system TABLE IV – CODES OF TRADED STOCKS.000. number of trades and of the financial volume verified in the cash market (standard batch) of BM & FBOVESPA. This Window training T=530 to T=777 decision was taken due to the high liquidity [5] of the stock Forecasting window T=778 +N to T=1026 N=0. 400 .6.br BBSA3 Stocks of the company . in which the transactions are performed at the close of market. Decisions to buy. In Figure 4 and Table VI it can be observed the operation of the trade system. B.2. The training. However. The system works with day Window check II T=281 to T=529 candles [5].15 Stop Sold R$ 1.site http://www. Figure 4 – BOVA11. sell and close for BOVA112 stock are presented. The system aims to return at least 10% of profit on a maximum of V-RESULTS one hundred and ninety days. namely BOVA11 VALE5.com. on the BOVESPA. the GP was tested on BOVESPA with four stocks. Open Value. This aspect justified the choice for day candles in GoldMiner.

15 Bought Sold R$ 1. the system indicates a purchase with the stock price of R$ 54. the rent value for the period of the operations was 2. The results obtained with GoldMiner are shown in Table Figure 6 – Time to obtain financial return.33% 55.000.000.66% 80.15.026.00 to R$ 1.55 stocks is registered. on 04-23-2013.83 days 2 R$ 54.57. the outliers on Figure 6 indicate that the goal return above 10% in 190 days or less.103.92 stocks is done.93 days 3 R$ 54. The system indicates sale at stock price of R$ 57.00 in cash.60 R$ 2. Buying and Selling Rules: An example of the application of optimal buying and selling rules on the market can be seen in Table VI. The assets increases to R$ 1. the initial capital is increased from R$ 1.5% per year [8].On 04-11-2013.053.00 Boxplot graphs with details about these results can be seen in Figures 5 and 6.32 when the profitability reaches 10%. the system indicates a purchase at a stock price of R$ 51. • Step 4 .On 03-20-2013. In the specific case of BOVA11.On 03-08-2013. was not reached within 190 days.067.053. The Buy and Hold Runs return time Strategy states that the best way to form a portfolio of stock 401 . the system indicates a sale with the stock price of R$ 54. In general.69 Bought Stop R$ 1.026. A total of 36.040.57 R$ 0.95.96 stocks with $0. The outliers in Figure 5 also indicate that It is expected to include such features in future versions of GoldMiner did not reach the set target.76 days VALE5 30 27 90% 33. some outliers lower than 190 days have been obtained for PETR4 stock. • Step 3 . the initial capital was R$ 1. However.00 in cash.00 in cash and 17.32 R$ 1.15.50. the operations are terminated.96 stocks and R$ 2. Since the buying and selling operations are It is important to emphasize that operating costs. The purchase of 39.Finally. In the case of VALE5. with $ 0.00. the system indicates a sale and the GoldMiner reaches the goal profit of 10%.040. As explained earlier. GoldMiner. In this case. The assets increases to R$ 1.067. After rent and sale of the stock. The sale of 37. They present the financial returns of the 4 R$ 51.50 R$ 0. The assets decreases to R$ 1.86.51 stocks is done and it a surplus of 20. Figure 5 – Financial return with GoldMiner to four top stocks. TABLE VII – CONSOLIDATED RESULTS The efficiency of the proposed system has been compared Stock Runs Suc.00 PETR4 30 28 93.000.56 days BBAS3 30 29 96. registering a deficit of -18. slightly above 10%. the variation of the intervals is minimal since 5 R$ 53.32 within 32 days. the rental price of a stock can vary it has been observed loss in some runs.On 04-14-2013. BOVA11 30 27 90% 53.103. most part of the profits are costs and fractioning batch were not considered in this work.95 Sold Bought R$ 1. from 1% to 5% of its value. • Step 1 . • Step 2 . • Step 5 . registering a surplus of 18.49 stocks. VII. there is R$ 2. From this example.130. Ratio Average with the Buy and Hold Strategy [5]. reaching the goal means getting a In general.54 stocks are purchased.60. rental conducted at market closing. In Figure 5. It can be seen that the target was hit in at least 90% of the tests.00 stocks and the time required to obtain these returns.86 Sold Bought R$ 1.00 in cash.

"Is Technical Analysis in the foreign exchange market profitable? A Genetic Programming Approach.bmfbovespa. buying and stock exchange using coevolutionary algorith..bcb.CONCLUSION 31 -6.42 11. but the inclusion of the two windows of verification and the trading 52 -9. Yew Soon.33 530-777 794-1020 system features a key distinguishing point for reaching the results of this work. pp.15 [11] http://www.58 11.Period in which GoldMiner acts.62 530-777 796-1020 ACKNOWLEDGEMENTS 48 -11.79 11. Journal of Finance. ms. CNPq and FAPEMIG by the financial support. it was possible to obtain such profit in very short time on the considered stocks.94 402 .69 10. the target time and profity were reached in more than 90% of 56 -11. Eugene F.43 11.B.br [9] D. This system uses 62 -11.. Mallick. [3] Koza J. Initial results are promising.2009. and Bicz A. 405-426. GoldMiner..37 10. 2010 and Hold strategy. 2008 International Conference on 30 2008-July 2 2008 Stock Buy and Hold GoldMiner [10] Fama.47 530-777 800-1020 REFERENCES 44 -9. P. selling stocks.1992 .33 11. Atsalakis and K. BBAS3 5. p. Efficient capital markets: a review of theory and empirical work.R.12 10.47 530-777 798-1020 The authors would like to thank the Brazilian agencies CAPES.53 11. advances in AI and App. In TABLE VIII . Mragwo(poland). 49-104. Nova Science Publishers. Proceedings of the 2010 International Multiconference on 81- executions compared to the average profitability of the Buy 88 18-20 Oct. V. Jour.02 11.Part I: Conventional methods.53 530-777 782-1020 genetic programming combined with indicators of financial technical analysis. Lee and O. Inc. being this strategy considerably better than the Buy and Hold strategy. BOVA11 -9. S. C. Dittmar R. 25:383-417.1997 at the time GoldMiner was used.47 530-777 802-1020 [1] G. Days – the number of days that show the time required for the Applications Vol.com.21 these stocks for an indefinite period of time. Rachwalski L.investments is to buy assets with positive history and keep VALE5 -1. Buy and Hold .33 530-777 790-1020 the runs.33 530-777 786-1020 market when it is ner to close.Return obtained after using the Buy and Hold Strategy [4] Neely C.. In Zopounidis C. Atsalakis and K.Part II: Soft computing methods Expert Systems with .33 530-777 788-1020 This software was tested on BOVESPA with four top stocks in different time windows.. pp81-88. Valavanis Surveying stock market forecasting techniques . of .. "Genetic Programming: On the programming of computer by means of natural selection".00 530-777 778-1020 In this work.33 11. . [8] http://www.33 530-777 792-1020 analysis has previously been treated in the literature. MIT Press. "Technical analysis of the financial markets". 50 -11. New York [2] G. Trading rule discovery in warsaw . a decision-making and trading 29 -6.33 530-777 784-1020 purchasing and selling stocks. B.18 11. 1970. Evolutionary algorithm in Forex trade Table IX shows the average profitability of all Goldminer strategy.88 9. An empirical study of Genetic Programming generated trading rules in computerized stock trading TABLE IX – BUY AND HOLD X GOLDMINER AVERAGE PROFITABILITY service system. [7] Myszkowski P.br PETR4 -9. symp.BUY AND HOLD VERSUS GOLDMINER TO BOVA11 addition. and Quantitative Analysis 32(4).77 Table VIII presents some of the results obtained with BOVA11 stocks in the Buy and Hold strategy compared to the results obtained with GoldMiner. 1999. 4th inter. [5] Murphy J.. The observed results indicate that the proposed algorithm is able to reach good profit in several situations. 46 -10.gov. . The application identifies the time of 62 -17. GoldMiner . [6] Myszkowski P.98 11.47 530-777 804-1020 Compendium.98 10..p.93 11.45 10.Represents the appreciation/depreciation of the stock finan. considering the liquidity of the 60 -14.80 11. Valavanis Surveying stock market forecasting In which: techniques . 58 -11. Forecasting window . 36 35932-5941 April 2009 return achieved by GoldMiner. P. Computation Optimization in Economics and Finance Research 42 -11. Weller P. S.. Days Buy and GoldMiner Window Forecasting Hold training window VI . The combination of genetic programming with technical 54 -11.00 530-777 780-1020 algorithms for the stock market is presented.Training Period of GoldMiner. Window Training .