Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. A Genetc Programmng Based Stock Prce Predctor together wth Mean-Varance Based Sell/Buy Actons Ramn Rajaboun and Ashkan Rahm-Kan Abstract In ths paper frst a precse mathematcal model s obtaned for four competng or cooperatng companes stock prces and then the optmal buy/sell sgnals are ascertaned for fve dfferent agents whch are tradng n a vrtual market and are tryng to maxmze ther wealth over one tradng year perod. The model s so that gves a good predcton of the next 3th day stock prces. The companes used n ths modelng are all chosen from Boston Stock Market. Genetc Programmng (GP) s used to produce the predctve mathematcal model. The nteracton among companes and the effect mposed by each of fve agents on future stock prces are also consdered n our modelng. Namely, we have chosen eght companes n order that there s some knd of nterrelaton among them. Comparson of the GP models wth Artfcal Neural Networks (ANN) and Neuro-Fuzzy Networks (traned by the LoLMoT algorthm) shows the superor potental of GP n predcton. Usng these models; fve players, each wth a specfc strategy and all wth one common goal (wealth maxmzaton), start to trade n a vrtual market. We have also relaxed the short-sales constrant n our work. Each of the agents has a dfferent objectve functon and all are gong to maxmze themselves. We have used Partcle Swarm Optmzaton (PSO) as an evolutonary optmzaton method for wealth maxmzaton. Key words: Stock market model, prce predcton, Genetc Programmng (GP), wealth maxmzaton, mean-varance portfolo selecton, Partcle Swarm Optmzaton (PSO). F I. INTRODUCTION ORECASTING the change n market prces and makng correct decsons s one of the most prncpal needs of anyone who economcal envronments concerns hm. Tme seres are the most common methods used n prce predcton [-3]. But the predomnant defect of these methods s that they use only the hstory of a company s prce to do a predcton. Recently, there has been growng attenton to the models that concern the nteracton among companes n modelng and the use of game theory [4-6] n decson makng because of provdng more realstc models. Because of complexty of the mutual effects of each company on the others, methods lke Artfcal Neural Networks (ANN), Neuro-Fuzzy Networks and State Space (SS) models are used more often for the stock prce modelng. In [7-] Neural Network s used to model the stock market and make predcton. In [8], Genetc algorthm (GA) s ncorporated to mprove the learnng and generalzablty of ANNs for stock market predcton. The R. Rajaboun and A. Rahm-Kan are wth the School of Electrcal and Computer Engneerng, Control and Intellgent Processng Center of Excellence, Unv. of Tehran, Tehran, Iran (Tell: +98-2-828433, Fax: +98-2-8863329, Emals: r.rajaboun@ece.ut.ac.r, arkan@ut.ac.r). proposed approach has reduced the dmensonalty of the feature space and has decreased rrelevant factors for stock market predcton. In [] the dfference between the prce and the movng average, hghest and lowest prces s used as nputs for one-day-ahead prce predcton. More over, volume of transactons, market ndcators and macro economc data are also consdered as nput varables [2]. There are also some studes beng performed on the fluctuatons and the correlatons n stock prce changes n physcs communtes, usng the concepts and methods n physcs [3-4]. In [5] a neuro-genetc stock predcton system s ntroduced, whch s based on the fnancal correlatons among companes. The genetc algorthm s used to select a set of nformatve nput features among them for a recurrent neural network. In [6-7], the neuro-genetc hybrds for stock predcton are proposed. The genetc algorthm (GA) s used to optmze the weghts of the neural network. Producng the rght buy/sell sgnals are also mportant for those who trade n the stock markets. In [8], two smple and popular tradng rules ncludng movng average and tradng range breakout are tested n the Chlean stock market. Ther results were compared wth the buy-and-hold strategy, and both tradng rules produced extra returns compared to the buy-and-hold strategy. Genetc Programmng (GP) s a symbolc optmzaton technque, developed by Koza [9]. It s an evolutonary computatonal technque (lke, e.g., genetc algorthm, evolutonary strategy, etc.) based on the so-called tree representaton. Ths representaton s extremely flexble because trees can represent computer programs, mathematcal equatons, or complete models of process systems [2]. In [2] GP s used to produce a one-day-ahead model to predct stock prces. Ths model s tested for a ffty consecutve tradng days of sx stocks and has yelded relatvely hgh returns on nvestment. In ths paper we use the GP to fnd the best mathematcal models for the four companes' stock prces under study. Our GP models are able to predct these stock prces for up to the next 3 days wth acceptable predcton errors n the market. Because, the GP s a well known algorthm we wll not present t n detals. However, reference [22] provdes a good revew of the GP algorthm. The modelng s done for four companes n Boston Stock Market [23]. Selected companes nclude: Advanced Mcro Devces (AMD), Ercsson (), Sony (), Phlps (), Internatonal Busness Machnes (), Intel Corporaton (INTC), Mcrosoft (MSFT) and Noka (NOK). These companes are assumed to have a relatonshp lke ISBN:978-988-72-3-7 WCE 28
Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. competton or cooperaton and so ther stock prces could affect on each other. Letters allocated n parentheses are the symbols usng whch one can access the prce data of each company. We use the prce hstory of these eght companes as nputs to predct our four objectve companes prces ncludng: Ercsson (), Internatonal Busness Machnes (), Sony () and Phlps (). Obtaned four models precson s compared wth two tradtonal methods: () Mult Layer Perceptron (MLP) and (2) Neuro-Fuzzy Network traned by Locally Lnear Model Tree (LoLMoT) method. The data are grouped n two sets: the tran data (the frst 7%) and the test data (the last 3%). After modelng the four companes' stock prces, we create fve agents who trade n a vrtual market n order to maxmze ther wealth. These agents (players) wll buy or sell ther n hand stocks accordng to ther unquely defned strateges. Each player has a unque objectve functon. The Buy/Sell actons of each player are obtaned so as to maxmze ts objectve functon n each tradng perod. The maxmzaton s done usng the Partcle Swarm Optmzaton (PSO) method [24]. The structure of the rest of paper wll be as follows: In secton 2, modelng and predcton s dscussed. Secton 3 demonstrates the vrtual stock market and argues ts constrants and presumptons. Then n secton 4 the results of our smulatons are shown and fnally the concluson s done n secton 5. II. MODELING AND PREDICTION As stated earler, our prmary goal s to obtan a predctve model that s able to predct the future stock prces precsely. The companes that we are gong to predct ther stocks nclude: Ercsson (), Internatonal Busness Machnes (), Sony () and Phlps (). We presume that these companes have some knd of nterrelatons wth four other companes ncludng: Advanced Mcro Devces (AMD), Intel Corporaton (INTC), Mcrosoft (MSFT) and Noka (NOK). So we downloaded these eght companes prce data from the Boston Stock Market [23]. The downloaded data encompasses some nformaton lke: daly openng prce, daly closng prce, daly hghest prce, daly lowest prce and exchange volume. In ths paper, we predct the average of daly openng and closng prces. Our data set contans sampled prce data for the nterval of 2/7/8 to 26/3/. We dvded these data n two groups: tran data (the frst 7%) and test data (the last 3%). The test data are used to verfy the obtaned model s accuraces. The crteron used to evaluate these models s the Normalzed Mean Square Error (NMSE), whch s defned as follows: NMSE = n = (y y ˆ ) n = y 2 2 where y and ŷ are the orgnal and predcted prce values, respectvely. () NMSE.2..8.6.4.2 NMSE for tran data MLP NEUROFUZZY GP Fg. - The predcton error (NMSE) for all companes (usng tran data) NMSE.5.4.3.2. NMSE for test data MLP NEUROFUZZY GP Fg. 2- The predcton error (NMSE) for all companes (usng test data) Fgure shows the NMSE values for the tran data set usng GP, ANN (MLP) and Neuro-Fuzzy networks (traned wth LoLMoT algorthm). Fgure 2 depcts ths comparson for the test data set. The GP-based stock prce models were ntalzed wth some functons and termnals. The termnals ncluded random number generators together wth ntegers from to 6. The functons ncluded: {+, -,,, log x, e x, x y }. The populaton szes were set to 6 except for, whch was set to 4. It s noteworthy that the populaton sze was ntalzed to 2 and then ncreased. Meanwhle the number of teratons was set to 8. As t can be seen from fgures and 2, the GP-based prce model predcton errors are acceptable for the tranng data set and less than both of the MLP and Neuro-Fuzzy models for test data set. The only drawback of the GP algorthm s ts tmeconsumng modelng characterstcs, whch s acceptable comparng to ts precse modelng, especally for stock prce predcton applcatons that precson s an mportant factor. Untl now we have modeled the nteractons of eght dfferent companes that affect the future prce values. But due to the fact that buyers/sellers also affect future stock prces of the companes, t s essental to nclude such nteractons n the modelng. Therefore, after modelng the stock prces for the above mentoned companes, we augment a new term to our prce models n order to nclude the effects of the market players actons (buy/sell weghts) nto the future prce changes. Snce there are not much avalable data on how the buy/sell volumes of the market players affect the future prces, we decded to add a new ISBN:978-988-72-3-7 WCE 28
Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. term to show these effects n our prce predcton models as follows: augmented term = γ W a Prce_vector (2) where: γ: s a weghtng coeffcent that regulates the mpact of the augmented term on the models. When γ s large the augmented term makes the model devate from the trend of the tme-seres market hstorcal data. Therefore, one should be careful n choosng the γ factor. W: s a weght vector that ts elements show each company s stock trade mpact on future prces. The elements of ths vector are between and. a: s the acton vector of all players. Its elements are between - and that show the buy/sell rates of the stocks. The negatve elements depct sellng and the postve ones ndcate buyng the stocks. Prce_vector: contans the current stock prce values n the market. The best value for the γ factor obtaned to be.. The W- vector was chosen as follows: W = [..5..2.2.2.5.]. Ths correspondng companes symbol vector are: [AMD INTC MSFT NOK ]. The augmented term makes t possble for us to see the effect of each player's market decson on the stock prces and other players' wealth (smlar to a non-cooperatve game). Our objectve n the next secton would be to fnd the best market actons (sell/buy of each stock) of each player so as to maxmze ts expected objectve functon (wealth) n the market. Our market smulaton studes are done n a Vrtual Stock Market and by means of an evolutonary optmzaton algorthm (the Partcle Swarm Optmzaton (PSO) method). In our smulatons a common PSO wth nerta was used. Table shows the parameters used n the PSO optmzaton. TABLE - THE PSO MODEL PARAMETERS Parameter Range [-, ] Maxmum optmzaton teratons each day 2 Populaton sze 8 Acceleraton constant 2 Acceleraton constant 2 2 Intal nerta weght.9 Fnal nerta weght.4 Mnmum error gradent -25 Epochs before error gradent termnaton 5 We assume fve players (agents) wth dfferent objectve functons and dfferent strateges n the market, but we assume that all the agents have access to the stock prce models (developed n secton 2) symmetrcally. The players strateges are as follows: Strategy of player : Ths player buys the maxmum number of allowed stocks when the predcton shows an ncrease n next 3 day prces compared to the average prces of the last days. Also t sells the maxmum number of allowed stocks when there s a decrease n next 3 day prces compared to the average prces of the last days. Strategy of player 2: Ths player uses the Mean-Varance Analyss (MVA). He chooses the standard devaton of the expected return (r p ) as a measure of rsk (σ p ). He plots the opportunty set (effcent fronter) for a four-asset portfolo and takes an average rsk and for an average return each day. A sample opportunty set for a four-asset portfolo s shown n fgure 3. III. VIRTUAL STOCK MARKET We assume fve players (agents) n the stock market. We also assume that these players have no stocks at the begnnng of the market. They just have 5,, USD and ntend to buy stocks that would maxmze ther expected wealth n the market. The players are free to buy and sell stocks n each round of the market. There are,, stocks assumed to be avalable from each company n our vrtual stock market (4,, stocks n total). The only lmtaton mposed by the market s the maxmum number of stocks each player can buy or sell each day. Ths buy/sell volume s lmted to stocks tradng per day for each company. Ths constrant s essental because f there s no lmtaton the whole stocks mght be bought at the begnnng of the tradng perod by one of the players. Ths way there wll be no chance for other players to buy some of the stocks. Through the augmented term added to the stock prce models we can see the effect of each agent's acton (sell/buy stocks) on the future prces and other agents' wealth n the market. Fg. 3 A sample opportunty set for a four-asset portfolo (dotted lne: The opportunty set wth A and B assets only) Strategy of player 3: Ths player beleves n Random Walk Theory. He beleves that the stock prces are unpredctable and therefore, he buys and sells stocks randomly. Strategy of player 4: Ths player acts just lke player 2. The only dfference s n hs rsk behavor. Ths player s rsk averse and therefore, n each stage plots the effcent fronter of the four-asset ISBN:978-988-72-3-7 WCE 28
Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. portfolo and then selects the buy/sell weghts on the knee of ths curve. Therefore, he selects the mnmum rsk wth mnmum expected return. Strategy of player 5: Ths player also acts lke player 2 wth the dfference that ths player s a rsk lover. Therefore, n each stage ths player plots the effcent fronter of the four-asset portfolo and then selects the buy/sell weghts wth the maxmum rsk and maxmum expected return. The workng regons of players 2, 4 and 5 on the rskreturn effcent fronter are shown n fgure 4. Expected Return.8.7.6.5.4.3 Mean-Varance Effcent Fronter and Random Portfolos Workng Regon of Player 5 Workng Regon of Player 2 Some of Selectable Ponts Workng.2 Regon of Player 4..2.4.6.8.2.22.24.26 Rsk (Standard Devaton) Fg. 4 The workng regons of players 2, 4 and 5 on the rsk-return effcent fronter (the red ponts can be selected n each tradng day) For more nformaton on Modern Portfolo Theory and Mean Varance Analyss (MVA) refer to [25]. These fve players buy and sell n the vrtual stock market. In the related lterature t s usually seen that short-sales are dsregarded when optmzng the players' objectve functons and the optmzaton s just done through stock purchases. However, n ths paper we have relaxed ths constrant and allowed the players to buy and sell ther stocks when needed. As stated before, the players try to maxmze ther wealth n each tradng day, usng the 3-day-ahead prce predctve models. In the followng, we defne the objectve functons for all players and demonstrate ther optmzaton process. For players 2, 4 and 5 that the rsk values are mportant n ther decsons, we defne ther objectve functon as follows: E = λe( rp ) ( λ) σ, = 2,4,5 p (3) where: E : s the Expected return of player. λ: s a constant between and. In fact, ths s a weght that shows the relatve mportance of the expected return (E(r p )) versus the rsk (σ p ) of player-. For λ= the rsk term dsappears form the objectve functon of player-: E = E(r p ). In our market smulaton studes, we chose λ={,.5, } for players {2, 4, 5} respectvely accordng to ther defned rsk behavors n the market. The players' objectve functons were optmzed wth respect to ther decson varables (stock sell/buy actons) usng the Partcle Swarm Optmzaton method and the results are presented and analyzed n the followng secton. IV. THE MARKET SIMULATION RESULTS The market smulaton results for the fve players are presented and analyzed n ths secton. Fgures 5 and 6 show the optmal buy/sell actons for players and 5 for each company's stock (,, and ). The optmal buy/sell actons for players 2, 3 and 4 are shown n the appendx. In these fgures, the buy actons are postve, sell actons are negatve and no-actons are zero. Player Trade weghts for each portfolo assets - 2 3 4-2 3 4-2 3 4-2 3 4 Fg. 5 The optmal tradng actons of player for all companes' stocks If the buy acton gets +, then the player should buy the maxmum number of stocks allowed for that company and when the sell acton gets -, t should sell the maxmum number of stocks allowed for that company. In fgure 7, the wealth of each player s shown for one tradng year perod. The wealth s measured as the values of the n-hand stocks added to the cash amount n-hand for each player. Player 5 Trade weghts for each portfolo assets - 2 3 4.5 -.5 2 3 4-2 3 4-2 3 4 Fg. 6 The optmal tradng actons of player 5 for all companes' stocks ISBN:978-988-72-3-7 WCE 28
Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. As can be seen from fgure 7, players and 5 have done better than the rest of them n terms of the wealth maxmzaton for one year stock tradng. In Table 2, the average wealth of each player for the tradng year s shown. Fgure 8 shows the expected rsk values n each tradng day for each player. As we expected, player has the mnmum expected rsk over the tradng perod and has also obtaned the maxmum return from the market. Treasure n hand ($) Treasure profle for each player x 7 2.5 player player 2 2 player 3 player 4.5 player 5.5 2 3 4 Fg. 7 The wealth of all players for all days of the tradng year Its strategy was to buy/sell maxmum stocks wth respect to the comparson of the predcted future-prces' trends wth those of the movng average -day-before prces. Snce the GP predcton models had small predcton errors for the test data, ths player dd well n the market by relyng on the predcton results. Among players 2, 4 and 5 (by referrng to fgure 7), we can see that player 5 wth the maxmum rsk level has made the most wealth (expected returns) and stands n the second rank (after player ) n terms of market returns. Player 3's strategy was to buy and sell randomly; by referrng to fgures 7 and 8, one can see that hs expected returns are smlar to those for player 2 but, hs expected rsks values are more than other players. TABLE 2 THE AVERAGE WEALTH OF EACH PLAYER DURING THE ONE YEAR TRADING PERIOD IN THE VIRTUAL STOCK MARKET (IN MILLION DOLLARS) Player Player2 Player3 Player4 Player5.95 6.388 6.626 6.659 8.65 V. CONCLUSION In ths paper we frst obtaned precse prce predctve models for four companes stocks usng the Genetc Programmng. Ths model ncorporated the effects of the players' actons (sell/buy) on the stock prces and other players' wealth. After the GP model was verfed (usng the test data from the Boston Market), t was used for makng sell/buy decsons by fve agents that traded n a vrtual stock market. The tradng perod was consdered one year for our market smulaton studes. Fve dfferent strateges and objectve functons were defned for the market tradng agents (wth dfferent rsk atttudes). The PSO algorthm was used (as an evolutonary optmzaton method) to obtan the optmal buy/sell actons Rsk Values (%) 4 2 2 3 4 4 2 2 3 4 4 2 2 3 4 4 2 2 3 4 4 2 2 3 4 Tradng Year Fg. 8 The expected rsk values for each player over the one tradng year (P to P5 from top to bottom graphs) P P2 P3 P4 P5 for each player n order to maxmze ther objectve functons (expected returns).the players' strateges and ther expected rsk-returns were obtaned and analyzed for the one year tradng perod. Our market smulaton studes showed that the player (P) who made hs buy/sell decsons based on the GP model future prce trends (compared to the -day-before movng average prces) and traded the maxmum number of stocks n each tradng day was the most successful one n our vrtual stock market. REFERENCES [] R. Thalhemer, M. M. Al, Tme Seres Analyss and Portfolo Selecton: An Applcaton to Mutual Savngs Banks, Southern Economc Journal, Vol. 45, No. 3, pp. 82-837, Jan. 979. [2] M. Pojarlev and Wolfgang Polasek, Applyng multvarate tme seres forecasts for actve portfolo management, Fnancal Markets and Portfolo Management, Vol. 5, pp. 2-2. [3] D. S. Posktt and A. R. Tremayne, Determnng a portfolo of lnear tme seres models, Bometrka, Vol. 74, No., pp.25-37, 987. [4] T. Basar and G. J. Olsder, Dynamc noncooperatve game theory. San Dego, CA : Academc Press, 995. [5] J. W. Webull, Evolutonary Game Theory. London: MIT Press, 995. [6] D. Fudenberg, J. Trole, Game Theory. Cambrdge, MA: MIT Press, 99. [7] S. Lakshmnarayanan, An Integrated stock market forcastng model usng neural network, M. Sc. dssertaton, College of Engneerng and Technology of Oho Unversty, August 25. [8] K. J. Km, W. B. Lee, Stock market predcton usng artfcal neural networks wth optmal feature transformaton, journal of Neural Computng & Applcatons, Sprnger, pp 255-26, 24. [9] K. Scherholt, C. H. Dagl, Stock market predcton usng dfferent neural network classfcaton archtectures, Computatonal Intellgence for Fnancal Engneerng, Proceedngs of the IEEEIAFE Conference, pp. 72-78, 996. [] K. Nygren, Stock Predcton A Neural Network Approach, M. Sc. dssertaton, Royal Insttute of Technology, KTH, March 24. [] E. P. K. Tsang, J. L, and J. M. Butler, EDDIE beats the bookes, Internatonal Journal of Software, Practce and Experence, Vol. 28, No., pp. 33 43, 998. [2] D. S. Barr and G. Man, Usng neural nets to manage nvestments, AI EXPERT, Vol. 34, No. 3, pp. 6 22, 994. [3] R. N. Mantegna and H. E. Stanley, An ntroducton to econophyscs: Correlaton and Complexty n Fnance, Cambrdge Unv. Press, Cambrdge, MA, 2. [4] J. P. Bouchaud and M. Potters, Theory of Fnancal Rsks: From Statstcal Physcs to Rsk management, Cambrdge Unv. Press, Cambrdge, MA, 2. ISBN:978-988-72-3-7 WCE 28
Proceedngs of the World Congress on Engneerng 28 Vol II WCE 28, July 2-4, 28, London, U.K. [5] Y. K. Kwon, S. S. Cho, B. R. Moon, Stock Predcton Based on Fnancal Correlaton, In Proceedngs of GECCO'25, pp. 26-266, 25. [6] Y. K. Kwon and B. R. Moon, Daly stock predcton usng neurogenetc hybrds, Proceedngs of the Genetc and Evolutonary Computaton Conference, pp. 223 224, 23. [7] Y. K. Kwon and B. R. Moon, Evolutonary ensemble for stock predcton, Proceedngs of the Genetc and Evolutonary Computaton Conference, pp. 2 3, 24. [8] F. Pars, A. Vasquez, Smple techncal tradng rules of stock returns: evdence from 987 to 998 n Chle, Emergng Market Revew, vol., pp. 52 64, 2. [9] J. Koza, Genetc Programmng: On the Programmng of Computers by Means of Natural Evoluton. Cambrdge, MA: MIT Press, 992. [2] J. Madar, J. Abony, and F. Szefert, Genetc Programmng for the Identfcaton of Nonlnear Input-Output Models, Ind. Eng. Chem. Res., Vol. 44, pp. 378-386, 25. [2] M. A. Kaboudan, Genetc Programmng Predcton of Stock Prces, Computatonal Economcs, Vol. 6, No. 3, pp. 27 236, 2. [22] S. Sette, L. Boullart, Genetc Programmng: prncples and applcatons, Eng. Appl. Artf. Intell., vol. 4, pp. 727-736, 2. [23] Boston Stock Group web page: http://boston.stockgroup.com [24] J. Kennedy, R. Eberhart, Partcle Swarm Optmzaton, Proceedngs of the IEEE Internatonal Conference on Neural Networks, Perth, Australa, pp. 942-945, 995. [25] D. Marnger, Portfolo Management wth Heurstc Optmzaton. Sprnger, 25. VI. APPENDIX Player 2 Trade weghts for each portfolo assets - 2 3 4-2 3 4-2 3 4-2 3 4 Fg. The optmal tradng actons of player 2 for all companes' stocks Player 3 Trade weghts for each portfolo assets.5 -.5 2 3 4-2 3 4.5 -.5 2 3 4.5 -.5 2 3 4 Fg. 2 The optmal tradng actons of player 3 for all companes' stocks Player 4 Trade weghts for each portfolo assets - 2 3 4.5 -.5 2 3 4-2 3 4-2 3 4 Fg. 3 The optmal tradng actons of player 4 for all companes' stocks ISBN:978-988-72-3-7 WCE 28