Full text
ESCUELA T´ ECNICA SUPERIOR DE INGENIER´ IA DEPARTAMENTO DE INGENIER´ IA DE SISTEMAS Y AUTOM´ ATICA Doctoral Thesis Forecasting and optimization of stock trades Gerardo Alfonso P´erez Thesis submitted for the degree of Doctor of Philosophy in the University of Seville Supervised by: Daniel Rodr´ıguez Ram´ırez
To my father, Antonio, and my mother, Pilar
Acknowledgements I would like to thank my thesis supervisor professor Daniel R. Ramirez for the help during the long process of studying for a PhD and for his support and encouragement. I would also like to thank professor Teodoro Alamo and Daniel Carnerero. Finally, but very importantly, I would like to thank my wife, Wandy, and my kids, Leo and Alyssa. Shanghai, 2021. I
Abstract The stock market is a complex and challenging field of research that has attracted researchers from several fields, such as for instance engineering. This dissertation approaches stock market analysis from an engineering point of view. It is empirically shown that techniques, such as neural networks, can be applied in many stock markets, as a tool creating reasonably accurate stock forecasts. This approach was also analyzed in the context of narrow markets. In this dissertation a broad definition of narrow market was followed, encompassing not only stock markets with a small trading volumes, which can potentially distort stock prices, but also markets that while having large daily trading volumes have some other features, such as a relatively large proportion of retail investors compared to institutional investors, that might result on price distortions. It is shown that neural networks can be applied, for forecasting purposes, even in narrow markets. However, some practical issues, such as stale prices, should be taken into account. The topic of technical indicator selection is also discussed in this dissertation. There is an ever increasing amount of technical indicators that are used in an attempt to discern future stock prices trends. Some of those indicators can generate contradicting signals. Therefore, it is important to choose the right combination of technical indicators when taking stock investment decisions. In this dissertation it is presented a new combinatorial algorithm for stock selection. It is shown, using this algorithm, that predictions are more accurate than using all the technical indicators together. It should also be noticed that using all the possible combinations it is not feasible given the enormous amount of potential combinations. Therefore, it is of clear importance to have algorithms that can generate adequate combinations of those technical indicators. The adaptation and application to stock forecasting of a forecasting technique based on local data is also shown in this thesis. It has been shown that this technique generates forecasts that are better than some commonly used benchmarks. At the core of this approach there is the assumption that stock prices then to follow, at least to some degree, historical patterns. Besides accuracy, an advantage of this technique is that it generates forecasts relatively fast, not requiring a time consuming training phase. Having a better understanding of the likely losses of the trade can help the investor to have a more complete investment decision process. Thus, it is also important, particularly from a risk management point of view, to have techniques that generate probability distributions for the predictions, that can be used to obtain intervals that are guaranteed to contain the future real prices with a prescribed probability. In this dissertation a probabilistic price interval estimation strategy has been adapted and applied to the problem of finding II
k -step ahead price intervals, getting better results than those obtained with well known techniques. Having good forecasting techniques is only a part of the investment process. After a buy or sell decision has been made it is important to carry out that trade efficiently in what it is commonly referred as “best execution”. There are multiple factors to take into account after the purchase (or sell) of a stock is decided, for instance in which period of the day (or over how many days) to carry out the trade. This is also related to the idea of avoiding distorting the market with the trade, i.e., a large order might unintentionally distort market prices. In this dissertation it is presented an approach that generates better results than frequently used benchmarks, such as for instance the Time Weighted Price (TWAP) or the Volume Weighted Price (VWAP). The approach is based on the concept of receding horizon optimization, well known in the predictive control community, but not used in the optimization of the execution of large trade orders. The technique can accommodate both market and limit orders and has shown a great potential economic impact in the execution of such large orders. III
Resumen El mercado de valores es un campo de investigaci´on complejo y desafiante que ha atra´ıdo a investigadores de varios campos, como por ejemplo la ingenier´ıa. Esta disertaci´on aborda el an´alisis burs´atil desde el punto de vista de la ingenier´ıa. Se mostrar´a emp´ıricamente que t´ecnicas, como las redes neuronales, se pueden aplicar en muchos mercados burs´atiles, como una herramienta que crea estimaciones del precio de las acciones razonablemente precisas. Este enfoque tambi´en se analiz´o en el contexto de un mercado estrecho. En esta disertaci´on se sigui´o una definici´on amplia de mercado estrecho, abarcando no solo mercado de valores con peque˜nos vol´umenes de negociaci´on, que potencialmente pueden distorsionar los precios de las acciones, sino tambi´en los mercados que, si bien tienen grandes vol´umenes de negociaci´on diarios, tienen algunas otras caracter´ısticas, como una proporci´on relativamente grande de inversores minoristas en comparaci´on con los inversores institucionales, que podr´ıan dar lugar a distorsiones en los precios. Se mostrar´a que redes neuronales se puede aplicar incluso en mercados estrechos. Sin embargo, deben tenerse en cuenta algunas cuestiones pr´acticas, como los precios obsoletos. El tema de la selecci´on de indicadores t´ecnicos tambi´en se discute en esta disertaci´on. Hay una cantidad cada vez mayor de indicadores t´ecnicos que se utilizan en un intento de discernir las tendencias futuras de los precios de las acciones. Algunos de esos indicadores pueden generar se˜nales contradictorias. Por lo tanto, es importante elegir la combinaci´on correcta de indicadores t´ecnicos al tomar decisiones burs´atiles. En esta disertaci´on se presenta un nuevo algoritmo combinatorio para la selecci´on de indicadores t´ecnicos. Se mostrara que las predicciones, usando este algoritmo, son m´as precisas que las estimaciones generadas usando todos los indicadores t´ecnicos juntos. Tambi´en debe tenerse en cuenta que usar todas las combinaciones posibles no es factible dada la enorme cantidad de combinaciones posibles. Por lo tanto, es de clara importancia tener algoritmos que puedan generar combinaciones adecuadas de esos indicadores t´ecnicos. Tambi´en se presenta en esta disertaci´on una aplicaci´on de una t´ecnica estad´ıstica basada en datos locales para fines de estimaci´on del precio de las acciones. Se mostrar´a que esta t´ecnica genera previsiones que son mejores que algunos bechmarks de uso com´un. En el n´ucleo de este enfoque est´a la suposici´on de que los precios de las acciones siguen, al menos hasta cierto punto, patrones hist´oricos. Adem´as de la precisi´on, una ventaja de esta t´ecnica es que genera pron´osticos relativamente r´apidamente, ya que no requiere una fase de entrenamiento que consume mucho tiempo. Tener una mejor comprensi´on de las p´erdidas probables de la operaci´on puede ayudar al inversor a tener un proceso de decisi´on de inversi´on m´as completo. Por lo tanto, tambi´en es importante, especialmente desde el IV
punto de vista de la gesti´on de riesgos, contar con buenas t´ecnicas de previsi´on que generen distribuciones de probabilidad para las predicciones, que puedan utilizarse para obtener intervalos que garanticen contener los precios reales futuros con una probabilidad prescrita. En esta disertaci´on se ha adaptado y aplicado una estrategia de estimaci´on de intervalos de precios probabil´ısticos al problema de encontrar intervalos de precios por delante de k-paso, obteniendo mejores resultados que los obtenidos con t´ecnicas bien conocidas. Tener buenas t´ecnicas de previsi´on es s´olo una parte del proceso de inversi´on. Despu´es de que se haya tomado una decisi´on de compra o venta es importante llevar a cabo esa operaci´on de manera eficiente en lo que com´enmente se conoce como “mejor ejecuci´on”. Hay m´ultiples factores a tener en cuenta despu´es de que la compra (o venta) de una acci´on se haya decidido, por ejemplo, en qu´e per´ıodo del d´ıa (o durante cu´antos d´ıas) se va a llevar a cabo la operaci´on. Esto se relaciona con la idea de evitar distorsionar el mercado con la operaci´on, es decir, una orden grande podr´ıa distorsionar involuntariamente los precios de mercado. En esta disertaci´on se presenta un enfoque que genera mejores resultados que los puntos de referencia utilizados con frecuencia, como por ejemplo el precio ponderado por tiempo (TWAP) o el precio ponderado por volumen (VWAP). El enfoque se basa en el concepto de retroceso de la optimizaci´on del horizonte, bien conocido en la comunidad de control predictivo, pero no se utiliza en la optimizaci´on de la ejecuci´on de grandes ´ordenes comerciales. La t´ecnica puede acomodar ´ordenes de mercado y l´ımite y ha demostrado un gran impacto econ´omico potencial en la ejecuci´on de ´ordenes tan grandes. V
Contents 1 Introduction 1 1.1 Thevalueofasecurity............................. 1 1.2 Main financial theories related to stock forecasting . . . . . . . . . . . . . . 4 1.2.1 The theory of the market efficiency . . . . . . . . . . . . . . . . . . 4 1.2.2 The behavioral finance theory . . . . . . . . . . . . . . . . . . . . . 5 1.2.3 Implications of the efficient market hypothesis and behavioral finance theories ................................. 6 1.3 Therandomwalk................................ 7 1.4 Motivation and objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 1.5 Mainresults................................... 11 1.6 Thesisoverview................................. 11 1.7 Publications................................... 12 2 Neural networks in stock prediction 14 2.1 Introduction................................... 14 2.2 TrainingAlgorithms .............................. 15 2.3 Neural networks for stock forecasting in narrow markets . . . . . . . . . . . 18 2.3.1 Stale prices and data availability . . . . . . . . . . . . . . . . . . . 21 2.3.2 Methods................................. 21 2.3.3 Results.................................. 27 2.3.4 Discussion................................ 29 2.4 Forecasting the Indian Stock Market . . . . . . . . . . . . . . . . . . . . . 29 2.4.1 Methodology .............................. 30 2.4.2 Results.................................. 31 VI
3 A technical indicator selection approach with application to the Chinese stock market 37 3.1 Introduction................................... 37 3.2 Technical Indicator Selection Approach . . . . . . . . . . . . . . . . . . . . 39 3.3 Chinese Equity Market Application . . . . . . . . . . . . . . . . . . . . . . 43 3.4 Results...................................... 51 3.5 Discussion.................................... 59 4 Stock forecasting using local data 61 4.1 Introduction................................... 61 4.2 Stock Price Forecasting using Local Data . . . . . . . . . . . . . . . . . . . 63 4.3 Probabilistic price interval forecasting . . . . . . . . . . . . . . . . . . . . . 65 4.4 Forecasting the Dow Jones Industrial Average index . . . . . . . . . . . . . 70 5 Receding horizon optimization of large trade orders 80 5.1 Introduction................................... 80 5.2 Problemstatement ............................... 83 5.3 Optimization algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 5.4 Case Study: Chinese stock market . . . . . . . . . . . . . . . . . . . . . . . 89 6 Conclusions and future work 100 6.1 Summary of contributions . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 6.2 Futurework...................................102 Appendix A Additional figures of chapter 2 103 A.1 Results of different algorithms and number of neurons . . . . . . . . . . . . 103 A.2 Results of different algorithms and moving averages . . . . . . . . . . . . . 108 List of figures 117 List of tables 121 Bibliography 123 VII
1.3. THE RANDOM WALK Nobel Prize in economics in 2013 for the “empirical analysis of asset prices”. Interestingly, the same year, professor Robert J. Shiller, from the University of Yale, also received the Nobel Prize (they shared the Nobel Prize) for his work on behavioral finance, which is an opposite theory to the market efficiency. The acceptance in the academic community of the efficient market hypothesis has fluctuated considerably. The theory was rapidly accepted in the seventies when it was first introduced becoming the dominant theory during the following few decades. This started to change by the end of the twenty century with the advent of new theories, such as behavioral finance, with authors such as [Malkiel, 2003] mentioning the change in status quo. There is an extensive literature regarding the topic of market efficiency. However, as just mentioned, there is less academic consensus about its validity than in the previous decades. There are for example mixed results when analyzing the stock market of different countries during different periods, see for instance [Kim and Shamsuddin, 2008]. 1.3 The random walk Another approach that is frequently followed in finance is modelling the stock price as a random walk. The objective of this approach is not so much trying to forecast stock price, as in a random walk it is assumed that forecasting the stock price in the next period (T+1) is not possible, but having a model that roughly gives an indication of the possible trends of the stock. This is sometimes used as a benchmark to measure the accuracy of forecasts generated by other techniques, such as illustrated in [Pemy, 2012]. A popular random walk model is the Brownian motion model [Pemy, 2012] that can be described by X(k+ 1) =X(k) + X(k)µt +σX(k)ζ(k)√t(1.2) X(0) =X, where X ( k ) is the stock price in step k, ζ ( k ) is a random input with zero mean and unity variance, σ the standard deviation, t the time fraction and µ the mean return. In figure 1.1 it can be seen an example of an actual stock modeled as a random walk and its real prices. This figure shows how the Brownian motion (random walk) it is not strictly speaking a forecasting model. In other words, the Brownian motion approach does not try to generate at time ( T ) an accurate forecast for the value of the stock in the next time step ( T +1) but simply tries to provide an indication of possible values for the stock according to historical volatility and returns. The implied basic assumption in a random walk is that the stock price follows a random process that cannot be forecast with accuracy. The random walk approach is followed in some well known financial techniques such as for instance option valuations. In fact the 1997 Nobel Prize in economics was obtained by Robert C. Merton and Myron S. Scholes for their work on the Black-Scholes-Merton 4 model on option valuation. However, it should be noted that, similar to the previous section, there is no scholar consensus [Cooper, 4 Professor Black, who died before 1997, was not awarded with the Nobel as this prize can only be granted to researchers that are alive at the time of the prize decision. 7
1.3. THE RANDOM WALK 0 10 20 30 40 50 60 70 80 90 10.43 10.44 10.45 10.46 10.47 10.48 10.49 10.5 10.51 Actual Stock Price Random Walk Figure 1.1: Sample of a stock price modeled as a random walk. 1982,Dupernex, 2007] regarding the validity of the random walk theory with multitude of papers both supporting it, such as [Fama, 1995], and strongly rejecting it, such as [Lo and MacKinlay, 1988,Frennberg and Hansson, 1993,Chaudhuri and Wu, 2003,Poshakwale, 2002,Hoque et al., 2007]. The discrepancies in views in the existing literature regarding the random walk hypothesis is rather substantial. Much of the discussion seems to be related with the specific market (country) and period analyzed with, overall, more support for the stock market following a random walk in the mid to late twenty century in the United States and, to some degree in the United Kingdom as well. There is however considerable amount of literature supporting that stock markets in several European markets as well as emerging markets, particularly in the twenty first century. Other factors, such as the liquidity of the market (narrow markets compared to deeper markets) has been proposed as factors impacting the random walk hypothesis on stock prices. The random walk hypothesis and the efficient market hypothesis are not unrelated. If market are fully efficient, therefore all the information (both private and public) is already incorporated in stock prices and hence stock should follow a random walk, i.e., a random process in which historical information (both quantitative and fundamental) cannot be use to develop an efficient trading strategy. The diverging views over the last few decades regarding the market efficient hypothesis has caused many scholar to question the, once widely accepted, random walk hypothesis with, as previously mentioned, that in at least some markets stocks do not appear to follow random walks. This is in fact one of the major open questions in finance and has been debated since the 1960s. Some proponents of random walks have equated stock investing with monkeys randomly throwing darts to the financial pages (figure 1.2) of the newspaper as there is no possible way of picking stocks in a sustainable way. In other words, if stock markets can be accurately described 8
1.4. MOTIVATION AND OBJECTIVES as a random walk, then the strong form market efficiency hypothesis is likely true, and it would be extremely difficult, likely impossible, to generate accurate stock forecasts and hence trading strategies. It should be noted, however, that there appear to be investors, such as for instance Warren Buffet that seem to consistently outperform the stock market during a multi-decade investment career. Perhaps the main takeaway of the literature review regarding both the efficient market hypothesis as well as random walk is that, while in previous decades they were financial dogmas, there is currently an increasing amount of literature against both of these ideas. The difference in methodologies, as well as on the data analyzed, make direct comparison among papers rather challenging. Furthermore, it is possible that the validity of these two concepts depends on the time period analyzed, i.e., with possible regime changes from one period to the next, as well as of the stock market analyzed. As previously mentioned there seems to be more support for the validity of these ideas in the US market while, there appears to be less empirical data supporting them in some European and emerging markets. A factor that should be also be taken into account is the potential for data mining, i.e., looking for a data set that corroborates the assumptions of the researcher, rather than trying to validate (or disprove) assumption with multiple datasets. Another important factor that will be addressed later in this dissertation is the quality of the underlying data, with some narrow markets having issues such as stale prices. If the underlying data is not reliable, then the conclusions from the models will not be reliable either. Stale data is usually related to lightly traded markets. In some narrow markets there is no trading in all securities everyday with the data showed in some data providers been the data from previous days. Less extreme cases are also important, for example, there might be only a few trades carried out by a few retail (individual) investors with the price recorded by data providers obtained from such trades. However, this price might not be representative of the price level at which an institutional investor can actually carry out a (large) trade. These are just some examples of data issues that can impact the results of the analysis, and that can potentially generate erroneous conclusions regarding the validity of the efficient market hypothesis and/or the random walk hypothesis. 1.4 Motivation and objectives While there is a large number of equity forecasting tools as well as trading techniques there is no consensus in the literature of the best possible approach. Therefore, developing techniques that improve, even is slightly, in the current techniques or that add some benefit, such as for example an algorithm that can be trained quicker than existing approaches, or with better forecasts, can have valuable practical applications. Stock trading is a highly complex process which can be impacted not only by multiple factors, such as human biases. Nevertheless, the potential rewards of even a small improvement over current techniques can be substantial as the frequency of the trading and the amount of shares traded magnify potential gains. 9
1.4. MOTIVATION AND OBJECTIVES Figure 1.2: Dart throwing to the financial pages. Statistical analysis of the stock market can be used not only to try to increase profits but also as a risk management tool. Risk management is becoming an increasingly important field of research as practice. In every trade there is some risk that the investor will lose money. Developing techniques that help managing or, at least realistically quantify the exposure of the investor to the market, is of clear practical value. All major international banks have large department with multimillion dollar budget allocated to such function. Another motivation behind this dissertation is the need to developed better trading models. Besides improvement in stock price forecasting there are other considerations to be taken into account when trading. In fact, the term “best execution” is increasingly important in the financial sector. Best execution refers to providing to the client an adequate trading techniques, after the buy or sell decision has been taken. The trading quality (after investment decision is made) is typically measured by comparing the average price obtained with a benchmark. Frequently used benchmarks are the Time Weight Average (TWAP) and the Volume Weighted Average (VWAP), which will be used in chapter 5. Based on these motivations the main objectives of this dissertation are as follows: •Create forecasting techniques for stock prices. •Develop techniques with applications in trading risk management. •Devise trading techniques based on optimization and forecasting. •Asses the application of learning techniques to stock forecasting. •Develop algorithms for automated selection of technical indicators, • Evaluate the applicability of forecasting techniques in stock markets with peculiarities, such as for instance narrow markets. 10
1.5. MAIN RESULTS 1.5 Main results • Neural networks were successfully applied to markets such as the Indian stock market, generating reasonably accurate forecasts. • The applicability of neural networks in narrow markets has been tested, concluding that they are suitable tools, identifying, however, practical issues such as stale prices, that could generate forecasts that superficially appear to be accurate, but that do not realistic represent the price at which an actual trade can be placed . • A new algorithm to select an adequate combination of technical indicators for stock forecasting purposes has been presented. The combination of technical indicators obtained in the simulations generated more accurate forecast than when using directly all the technical indicators available. • A technique, based on local data, was applied for the first time, to the task of stock forecasting. The technique does not need training and the computational burden is quite low. Furthermore, the estimates were more accurate than some frequent benchmarks. • Interval forecasting based on dissimilarity functions has been applied for the first time to the problem of price interval forecasting, adapting the technique to this particular problem, using only local data to better handle big datasets. This type of application can have direct practical applications in the field of risk management, as having a better understanding of the potential losses, with a related probability distribution, can help managing investments in a more balanced way. The results have been favourably compared to a well known technique. • Techniques for trading optimization. After the purchase or sell of a stock is decided by the investor it is important to carry out in an efficient way in what is frequently described as “best execution”. There are multiple factors to take into account such as for instance the potential impact of the order in the market and the need to divide the order into smaller trades. In this dissertation a technique to carry out such type of execution has been presented. The technique is based on forecasting and optimization and can accommodate different types of stock orders. The results, from the application to the Chinese Stock Market, show significant savings over two well known price benchmarks. 1.6 Thesis overview This dissertation is structured in six chapters plus appendixes. Beyond this first introductory chapter, the second chapter of the dissertation is devoted to show how neural networks can be applied for stock forecasting purposes, generating accurate forecasts in several markets. A section of this chapter is dedicated to analyze the applicability of neural networks to narrow markets. 11
1.7. PUBLICATIONS In chapter three it is presented an algorithm for the automated selection of technical indicators. There is a large amount of technical indicators available with some of those indicators generating conflicting signals. Given this large amount of indicators it is not feasible to check all possible combinations. It is also shown empirically in this chapter that it is possible to obtain a combination of indicators that produce more accurate trading signals than using directly the entire set of indicators. In chapter four a technique, based on local data, has been applied for stock forecasting purposes. This technique is based on the idea of using historical data that best approach the current stock situation. It has been illustrated by applying it to the Dow Jones Industrial Index. For completeness purposes other techniques, such as neural networks, were also used to determine a base benchmark for the technique. In this chapter it is also show how to apply to price interval forecasting a technique that build a probability distribution around a stock price forecast. This approach can have applications on risk management techniques. In chapter five it is presented a technique for the implementation of trades. After the investor has decided to do a trade, this trade has to be executed in an adequate way, in pursuit of a “best execution”. Factors such as not distorting the market price with an excessive large trade (which can be potentially be divided into smaller trades) must be taken into consideration. The proposed technique, based on forecasting and optimization, has proved to obtain better results than the TWAP and VWAP prices in several stocks from the Chinese Stock Market. Finally, in chapter six the conclusions, in the form of a summary of contributions, and some directions for future work are presented. 1.7 Publications The list of research papers in indexed journals as well as conference papers carried out during this dissertation are as follows: Journal papers • Alfonso, G.; Ramirez, D.R. A Nonlinear Technical Indicator Selection Approach for Stock Markets. Application to the Chinese Stock Market. Mathematics 2020, 8, 1301. Impact factor 1.747, JCR ranking: Q1 (2019). • Alfonso, G.; Ramirez, D.R. Neural Networks in Narrow Stock Markets. Symmetry 2020, 12(8), 1272. Impact factor 2.645, JCR ranking Q2 (2019). • Gerardo Alfonso, A. Daniel Carnerero, Daniel R. Ramirez, Teodoro Alamo. Stock forecasting using local data. IEEE Access 2021, vol.9, pp.9334-6344. Impact factor 3.745, JCR ranking Q1 (2019) 12
1.7. PUBLICATIONS International conference papers • Alfonso, G.; Ramirez, D.R. Forecasting the Indian Stock Market by Applying the Levenberg Marquardt and Scaled Conjugate Training Algorithms in Neural Networks. CSAE 2017. The International Conference on Computer Science and Application Engineering. Shanghai. China. Unpublished papers • Gerardo Alfonso, A. Daniel Carnerero, Daniel R. Ramirez, Teodoro Alamo. Receding horizon optimization of large trade orders. Submitted to IEEE Access (2021). 13
Chapter 2 Neural networks in stock prediction This chapter is based on the following journal publication: • Alfonso, G.; Ramirez, D.R. Neural Networks in Narrow Stock Markets. Symmetry 2020, 12(8), 1272 As well as from a conference presented at an international conference • Alfonso, G.; Ramirez, D.R. Forecasting the Indian Stock Market by Applying the Levenberg Marquardt and Scaled Conjugate Training Algorithms in Neural Networks. CSAE 2017. The International Conference on Computer Science and Application Engineering. Shanghai. China. 2.1 Introduction A large amount [Granger, 1992, Shively, 2003, Wang et al., 2012b] of stock forecasting techniques have developed overtime, with an increase in the number of such techniques in recent years, as asset prices became easily available and computer power, not only significantly increased, but also became more affordable. Among the different quantitative and machine learning techniques applied to stock forecasting, one of the most popular are neural networks [Zhang et al., 1998,Zhang and Suganthan, 2016,Cao et al., 2018,Refenes et al., 1994, Ballings et al., 2015, Kanas, 2001, Lahmiri, 2016, Li et al., 2016, Li et al., 2016,Quah and Srinivasan, 1999,Guresen et al., 2011,Moghaddam et al., 2016,Qiu and Song, 2016,Kimoto et al., 1990,Yoon and Swales, 1991,Zhang, 2007,Naeini et al., 2010,Chen et al., 2016,Qiu et al., 2020]. Neural networks are very flexible tools that do not require any previous modeling of the underlying system. However, there is a large amount of factors to take into consideration when building a network. Among these, the most important basic characteristics necessary to define a neuronal network are, the number of neurons and layers and the learning algorithm (supervised learning), that will be used to train the network. Artificial neural networks are composed by artificial neurons that 14
2.2. TRAINING ALGORITHMS Figure 2.1: Typical Artificial Neuron. Where I1 to Ii are the inputs, W1 to Wi the related weights, b1the bias and Out the output. are mathematical expression inspired on the function of biological neurons. A sample of a typical artificial neuron can be seen in figure 2.1. There are typically at least three steps when creating a neural network. In the first step the basic network architecture is chosen. In the second step, when the basic structure is already in place the network is trained. The training process entails some type of algorithm that iteratively adjust the weights of each neuron in an attempt to generate forecast that are as close as possible to the actual value. In order to do this it is necessary to have an error function, measuring the distance between the forecasted and actual values. This error is what the supervised learning algorithm tries to minimize. After that, in the last step, the network is used to create forecasts from previously unseen data (set aside during the training phase), and the forecasting accuracy is calculated. This last step is typically done to avoid the issue of over-fitting which can cause the network to generalize poorly or, in other words, perform poorly when applied to new (unseen) data. The remaining of the chapter is organized as follows: section 2.2 presents a brief review of the training algorithms used in the chapter. The application of neural networks to stock forecasting in narrow markets is discussed in section 2.3. Finally, section 2.4 presents the application of neural networks to forecast one of the main indexes of the Indian stock market. 2.2 Training Algorithms The choice of the learning algorithm as well as the number of neurons used can have a very significant impact on the results. In this section a very brief description of the training algorithms used for the neural networks is shown. All of them are well-known algorithms with applications in several areas. All the actual implementation of the algorithms used in this chapter are those of the Matlab Neural Network Toolbox, so, for clarity purposes, its notation and acronyms are followed. 15
2.2. TRAINING ALGORITHMS Quasi Newton back propagation The quasi Newton (BFG) [Dennis Jr and Schnabel, 1996] is a powerful and relatively fast training algorithm as it skips the exact computation of the second derivatives that it is necessary in the Newton’s method. The objective is to minimize a performance index, f ( X ), which measures forecasting accuracy as a function of X , the network bias and weights. The basic rule to iteratively adjust the value of Xis Xi+1 =Xi−γi Hi ∇f(xi),(2.1) where the parameter γi is selected to minimize the performance along the search direction, Xi are the weights and bias at iteration i , Hi is an approximate Hessian of f ( Xi ) and ∇f(xi) is its gradient [MathWorks, 2010]. Conjugate gradient Conjugate gradient methods, are popular training algorithms that update the weights according to the basic rule Xi+1 =Xi+γidi,(2.2) where γi plays the same role as in BFG method and di is a vector in the direction of the gradient, which is in turn updated according to di=−∇f(Xi) + φidi−1, being φi a constant with a different value depending on the conjugate gradient method considered. In the case of the Fletcher Reeves (CGF) algorithm [Al Baali, 1985] the scalar φis calculated as φi=∇fT(Xi)∇f(Xi) ∇fT(Xi−1)∇f(Xi−1).(2.3) On the other hand, in the case of the [Khoda et al., 1992,Zhang et al., 2006] Polak Ribiere (CGP) variant the parameter is computed using φi=(∇f(Xi−1)−∇f(Xi−2))T∇f(Xi) ∇fT(Xi−1)∇f(Xi−1)(2.4) Another of the conjugate gradient variant, and more complex, is the Fletcher Powell (CGB) algorithm [Powell, 1977]. Powell describes the idea as automatically resetting the search direction (restart) and it is done according to some conditions on the orthogonality of the gradient at successive steps. First, the algorithm uses a test to determine when to reset, i.e., the reset is performed if |∇fT(Xi−1)∇f(Xi)|⩾0.2||∇f(Xi)||2.(2.5) 16
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS Table 2.1: Country equity indexes Indexes Country Abbreviation Very deep market Dow Jones Industrial Average U.S. DJ Deep market FTSE 100 Index U.K. FTSE Deustche Bourse DAX Germany DAX CAC 40 Index France CAC Moderately narrow market IBEX 35 Spain IBEX CSI 300 China CSI OMX Rige Latvia RIGSE Narrow market Tunisia Stock Exchange Index Tunisia Tusise FTSE Namibia Namibia Namibia Tanzania All Share Index Tanzania Tanzania When forecasting stocks or equity indexes one of the most important factors, together with the chosen algorithm, is deciding what input to use. In this case it was decided to use several moving averages. Moving averages are some of the most frequently used indicators for stock performance [Adrian, 2015,Johnston et al., 1999,Gencay and Stengos, 1998,Larson, 2007,Raudys et al., 2013] and they are easily obtained. The moving average at any given time is just the average price over a predetermined number of previous days, that is, MAN(t) = 1 N N−1 X i=0 p(t−i) (2.12) where p ( t ) is the stock price at time t . Thus, the 50 day moving average will be the sum of the closing prices over the last 50 days divided by 50. In Figure 2.4 an example for the RIGSE index and its 50-day, 100-day and 200-day moving averages can be seen. The neural network inputs used are the 250 most recent values of the moving average. The target used in the training of the network is the price to be forecasted, thus the output of the network is the price forecast, i.e., ˆp(t+ 1) = NN(MAN(t), MAN(t−1), . . . , MAN(t−249)) On the other hand, as the forecasting accuracy will depend on the structure of the neural network, a relatively large amount of configurations will be tested, including ten different learning algorithms as well as varying number of neurons. The forecasting capability of neural networks for all the previously mentioned ten indexes, representing very deep, deep, moderately narrow and narrow markets were estimated. Daily closing prices of the indexes for the period from 2012 to 2017 were obtained from Bloomberg. Also different moving averages will be considered in the experiments, thus the 50, 100 and 200 day moving averages were also computed for each of 23
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS Figure 2.4: RIGSE index and moving averages (stock moving average (SMA)). the previously mentioned indexes. The structure followed for the neural network consisted of one hidden layer. The amount of neurons was increased from 10 to 100 in steps of 5. Then, the network was created using an input of one of the moving averages and the index as the target value. The process was repeated for all three moving averages (50-day, 100-day and 200-day). Due to different randomly generated initial conditions two neural networks with the same inputs, output and structure are likely to generate slightly different results (forecasts). In order to account for that 100 networks were estimated for each configuration. Each of these forecasts was regressed against the actual target. In this way a probability distribution for the R-square value was obtained. The standard procedure of setting aside 15% of the data for testing purposes was followed. It will be shown that increasing the number of neurons, for most cases, did not increase the accuracy of the forecasts. The opposite was actually true in many cases with accuracy gradually declining. A typical outcome can be seen in Figure 2.5. In total 10 learning algorithms were used, see Table 2.2, as a forecasting tool for the previously mentioned ten country stock indexes. The moving average was used as an input for the neural network (the process was repeated for all the three moving averages considered). As previously mentioned, 15% of the data was designated as testing data and therefore not used during the training period. The R-squared values showed in the results are the R-squared obtained when regressing the actual value with the estimated generated for the testing data set. This is the standard procedure to try to ensure that the trained neural network generalizes reasonably well when faced with new data, which is a critical step for neural networks. 24
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS Figure 2.5: Results for CAC index (France) using the 100-day moving average (MA) and quasi Newton (BFG) training algorithm. After a certain point, around 30 neurons, the forecasting accuracy, measured as the R-squared of the regression between the actual and forecasted values, decreases as the number of neurons increases. Choosing the appropriate learning algorithm for the neural network is of clear importance but it will be showed that there appear to be some general trends for all the ten learning algorithms analyzed, supporting the hypothesis that neural networks are actually an appropriate forecasting tool for stock prices in narrow markets. Calculating 100 networks per index and per configuration allowed for the estimation of confidence intervals. This was done in order to avoid having results that are relatively accurate but that can be obtained because a one off or relatively unlikely events. As an example, in Figure 2.6 it is shown the forecasting accuracy measured as the R-squared of the regression between the actual and forecasted values, using the OSS training algorithm, for all the indexes increasing the number of neurons and using the 50-day, 100-day and 200-day moving averages, which are denoted in the figures as MA50, MA100 and MA200. This analysis was carried out for all the previously mentioned 10 training algorithms. The results for all the other training algorithms can be seen in figures A.1 to A.9 (see appendix A). It could be also useful to compare how, given a specific configuration and choice of moving average, would the multiple neural network perform for each country, rather than just comparing several networks and moving averages for the same country index. In Figure 2.7 an example of this approach can be seen. This figure showed the accuracy of forecasts using the BFG training algorithm for all the indexes analyzed. The results for all other training algorithms can be seen in figures A.10 to A.18. 25
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS Table 2.2: Training algorithm and standard Matlab abbreviation Abbreviation Algorithm BFG Quasi Newton training algorithm CGB Conjugate Gradient (with restarts) CGF Conjugate Gradient Fetcher Powell CGP Conjugate Gradient Polak Ribiere DA Gradient Descent (adaptive learning) DM Gradient Descent (momentum) DX Gradient Descent (momentum and adaptive learning) LM Levenberg Marquardt RP Resilient backpropagation OSS Secant training algorithm Figure 2.6: Forecasting accuracy comparison of different moving averages using the Secant training algorithm (OSS). After a certain number of neurons, and regardless of the index analyzed, the forecasting accuracy of the algorithms decreases when additional neurons are added. 26
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS Figure 2.7: Results using BFG training per country (using the 50, 100 and 200 days moving average). 2.3.3 Results Of the models analyzed the best results, from a forecasting accuracy point of view, were those using the 50-day moving average and a relatively small number of neurons, typically 10. Increasing the number of neurons in the network did not increase the forecasting accuracy. This result was relatively consistent among most of the indexes, regardless if they belong to very deep, deep, moderately narrow or narrow categories, as well as across most of the training algorithms analyzed. It is noteworthy that the Namibian case appears to be the one with the best forecasting accuracy regardless of the choice of moving average. The results in the Namibian case, a particularly narrow market, should be taken with caution and present some unique characteristics. The forecasts for the Namibian case appear to be remarkably accurate, but this could be related to the stale price issue and the accuracy hence overstated. The result in this way could appear to be very accurate but 27
2.3. NEURAL NETWORKS FOR STOCK FORECASTING IN NARROW MARKETS a practical application of such a model for trading purposes could lead to disappointing results if the price quoted does not match the price at which a transaction can be actually done. It is also interesting to notice that in the case of Namibia, using the Levenberg Marquardt method the forecasting accuracy appears to increase as the number of neurons increases, which is not the case for the vast majority of other indexes and configurations. In this case there also appears to be no statistically significant difference between using the 50-day, 100-day or 200-day moving averages, which is again in direct contrast with the results from most of the other indexes. The case of Tanzania and Spain (IBEX) are examples of typical results with the 50-day moving average generating better results than any of the other indexes analyzed and forecasting accuracy gradually decreasing as the number of neurons increases. It should also be noted that the forecasting accuracy of the Dow Jones index, using the same configuration, did marginally increase when the number of neurons were increased. Another peculiarity showed by the Dow Jones index is that the selection of the moving average (50-day, 100-day or 200-day) did not have a significant impact on the forecasting accuracy for most of the configurations analyzed. On the other hand, in some other cases like the Spanish (IBEX), there is a significant difference between using one moving average or the other. This would translate in differences in the forecasting error. As an example, the RMSE values for the case of the IBEX and the Dow Jones are showed in table 2.3. Table 2.3: RMSE for the IBEX and the Dow Jones using a neural network with 20 neurons. The RMSE values showed are the average of 100 simulations for each case. Technical indicator IBEX Dow Jones Moving Average (50 days) 422.9 363.1 Moving Average (100 days) 576.9 385.6 Moving Average (200 days) 775.0 399.2 In this table it can be seen that there is a relatively large difference of the RMSE obtained using the IBEX index for the various moving averages while in the case of the Dow Jones the values of the RMSE appear to be relatively close, regardless of the moving average used. These different behaviours highlight the importance of input variable selection, and that forecasting performance is affected in a case dependant way. While the forecasting accuracy is good for all the indexes, regardless if it is a narrow market or not, there are some apparent differences with for instance moderately narrow markets, particularly in the case of the Spanish (IBEX) and Chinese (CSI) generating for most of the configurations analyzed slightly poorer forecasts than in the case of the other indexes. The difference appears to be particularly large in the case of the gradient descent with adaptive learning. In general terms the accuracy of the training algorithms was comparable. One of the noticeable exceptions was the gradient descent momentum that generated the worst results among all the training algorithms used. These poor results were obtained for all the 10 indexes and regardless of the number of neurons used. All the other training algorithms provided comparable results for the indexes regardless on the classification of the index. All the narrow and moderately narrow markets analyzed, with the previously mentioned 28
2.4. FORECASTING THE INDIAN STOCK MARKET caveat for the Namibian market, generated forecasts that are comparable to deep and very deep markets. 2.3.4 Discussion Neural networks appear to be an applicable tool for stock forecasting purposes on narrow markets with performance that is comparable but typically lower than in deeper markets. Forecasts in some particularly narrow markets might appear to be very accurate but that could be related to stale prices. This phenomenon appear when the quoted price is not representative of an actual transaction on the analyzed day but of some transaction on a previous day. This is typically associated with illiquid markets. Besides, for this type of extreme case, it would appear that neural networks do a relatively good job forecasting stock performance in the countries analyzed. The 50-day moving average provided results that were at least statistically not worse than the 100-day or 200-day moving averages for most of the neural network configurations analyzed. In fact, the 50-day moving average was the best choice in some of the indexes, like the CSI. For other, deeper, markets, such as the U.S. market, there appears to be less statistically significant differences between these different moving averages regarding forecasting accuracy. It should also be noted that increasing the number of neurons did, in most cases, not only not increase forecasting accuracy but it decreased it. This was a general trend observed when using virtually all of the training algorithms with basically all the ten stock indexes analyzed. This might be related to the issue of local minima in neural networks. As the number of neurons increases the neural network might get stuck in a local minimum, basically losing generalization power. Therefore, an important takeaway is that naively increasing the level of complexity of a neural networks, by adding large amounts of neurons to the network, is not likely to translate into more accurate stock forecasts. The fact that neural networks appear to be applicable for stock forecasting in narrow markets suggest that while there are clearly very big differences between narrow and deep markets they might also share some features that allow the successful use of the same forecasting technique, such as neural networks, in both types of markets. As previously mentioned the flow of information is likely very different in some of the narrow markets analyzed, with relatively poor telecommunication and trading infrastructure, compared to countries such as the United States, but, interestingly, it appears that regardless of these obvious differences neural networks have comparable levels of applicability, for stock forecasting purposes, in narrow and deep markets. 2.4 Forecasting the Indian Stock Market The Indian stock market is experiencing fast growth and has peculiarities that differentiate it from many other stock markets, particularly those in developed markets. Given the potential size of this stock market and the growing importance of the Indian economy it 29
2.4. FORECASTING THE INDIAN STOCK MARKET seemed reasonable to look at what tools provide reasonably accurately stock prices forecast. It is of clear practical and theoretical relevance to determine which type of algorithm to use in order to try to forecast stock market trends. In recent times there has been an increasing interest in applying neural networks to such aim. In this section it is shown that a neural network using as an input the closing price in the previous day and two different learning algorithms produce accurate forecast. This simple but efficient approach generated a one day forecasting accuracy, measured as the mean value of R2 , of [0.9952, 0.9972] for the Levenberg-Marquardt training algorithm and [0.9965, 0.9970] for the Scaled Conjugate learning algorithm. These results were obtained using only 10 neurons in the neural network. Increasing the number of neurons to 500 did not improve the out of sample forecasting accuracy. It actually decreased, for both algorithms. It would seem that at least for the period of time analyzed, from 2010 to 2016, neural networks did a reasonably good job forecasting stock prices. In order to forecast share prices it is necessary to decide what variables to use as inputs as well as the forecasting technique to use. In this case it was decided to use only historical values, rather than more complex indicators derived from historical values. On the other hand, neural networks with one hidden layer and two different learning algorithms, Levenberg-Marquardt and Scaled Conjugate Gradient, have been chosen as the forecasting tool. 2.4.1 Methodology The NSE Nifty 50 index is one of the most frequently quoted stock indexes in India and it is composed by the top 50 companies by market capitalization in the Indian stock market. The index is owned and maintained by India Index Services Products Ltd. and according to their data represent approximately 63% of the total free float market capitalization of the National Stock Exchange of India (NSE). All the share prices were obtained from the data provider Bloomberg Professional. The data consist of closing daily prices for the NSE nifty 50 for the period from 2010 to 2016. The closing price of the index in the previous 250 days was used as the input for forecasting the closing price in the following day, i.e., ˆp(t+ 1) = NN(p(t), p(t−1), . . . , p(t−249)) As previously mentioned the LM and Scaled Conjugate gradient were used as the learning algorithms. The neural network built had one hidden layer. Initially the number of neurons was set to 10. The number of neurons was then increase, in steps of initially 10 neurons, until reaching 100 neurons. From that point onwards the number of neurons were increased in steps of 50 neurons until reaching total of 500 in an attempt to determine the effect of such neural network parameter in the out of sample forecasting accuracy. The forecasting accuracy for each neural network (learning algorithm plus number of neurons) was tested in a series of 100 tests. The objective of this process was to estimate an average value and a 95% confidence interval for the mean value of R2 as well as of its 30
2.4. FORECASTING THE INDIAN STOCK MARKET volatility. As prediction is the main objective of this analysis the values R2 were calculated for the out of sample data, i.e., the data not previously seen by the neural network. All the calculations were performed in Matlab using the neural network toolbox. Figure 2.8: Output from NN using LM algorithm 2.4.2 Results The analysis was performed using the NSE Nifty 50 index. The results support the idea that neural networks are applicable to the Indian stock market, for the period from 2010 to 2016, for forecasting purposes. At a 95% confidence interval there was no statistically significant difference between the forecasting accuracy of a neural network with 10 neurons using the LM training algorithm and the Scaled Conjugate algorithm (table 2.4 and 2.5) using the mean value of R2 as the metric for comparisons. Always as the same confidence level, the standard deviation for the mean R2 was statistically significantly lower for the Scaled Conjugate approach than for the Levenberg-Marquardt approach. Visually, the goodness of the model can be appreciated in figures 2.8 and 2.9. The histogram of the error can be seen in figures 2.10 and 2.11. As previously seen for other markets, increasing the number of neurons by an order of magnitude did not help improving out-of-sample forecasting accuracy. In fact, for both the Scaled Conjugate and the LM approach the mean value, at a 95% confidence level, for the mean value of R2 was lower when using 100 neurons than when using 10 neurons. Similarly, the value for the standard deviation of the mean value of R2 was higher for the case with 100 neurons when compared to the 10 neurons approach for both learning 31
2.4. FORECASTING THE INDIAN STOCK MARKET Figure 2.9: Output from NN using scaled conjugate algorithm Figure 2.10: Error histogram from NN using LM algorithm 32
3.2. TECHNICAL INDICATOR SELECTION APPROACH et al., 1994,Yu and Chen, 1995] which can cause the neural network to generalize poorly or in other words, generate poor forecast when faced with new data. In this regard there has been a focus on reducing the dimensionality of the data to avoid having the neural network stuck in this local minima [Hinton and Salakhutdinov, 2006,Wang et al., 2012a,Becker et al., 2020,Kiarashinejad et al., 2020,Breger et al., 2017]. A strategy focused on finding the combination of technical indicators with the best forecasting accuracy would be very useful in this context. In this chapter it is proposed a combinatorial approach for variable selection applied to stock market technical indicators. Given the number of possible technical indicators that are available today, is clear that not all possible combinations can be tested. A pool of 35 technical indicators is used, so the number of possible combinations is staggering. Because of that the proposed approach resorts to randomization. The algorithm starts by generating a preset number of combinations each with a size of half the number of available indicators. The reason for using such size is because the maximum number of combinations for a given n and k , that is the binomial coefficient n choose k , is attained for k = bn 2c . This is evident by inspecting the Pascal’s Triangle, but can be proved using the properties of the Newton binomial. From this initial set of combinations, new combinations are generated randomly retaining the best ones in an iterative process that ends when the stop condition is met. The proposed method is shown to improve the baseline approach, that is using all the available indicators, when applied to the task of predicting market trends. As a case study for the proposed method, this chapter focuses on the Chinese stock market. China stock market is a very dynamic and of increasingly importance due to the economic grow of China. The most relevant Chinese stock indexes have been considered. The strategy described in this chapter has obtained good results and better combinations of technical indicators have been identified for such indexes. The remaining of the chapter is organized as follows: Section 3.2 presents the proposed approach. Section 3.3 shows the application of the proposed approach to the China stock market. Finally, the results are discussed in Section 3.5. 3.2 Technical Indicator Selection Approach Let Xi T ( t ) be tuple of T values of the i -th technical indicator from a pool of up to N nonlinear technical indicators computed at the time period t (usually the time period is measured in days, but could be weeks, months or whatever), such as for instance a moving average: Xi T(t) = {Xi(t−(T−1)), Xi(t−(T−2)), ..., Xi(t)},(3.1) where Xi(t) is the value of the i-th technical indicator evaluated at time t. Let RT ( t ) be a vector that groups the direction of the change of the price of a stock or index, in the period from t− ( T− 1) to t , that is RT = { 0 , 1 }T with 0 meaning that the stock increases or remains constant at the end of a period, 1 meaning otherwise. 39
3.2. TECHNICAL INDICATOR SELECTION APPROACH Additionally, let ˆ φdefine a nonlinear mapping from Xi T(t) to RT(t) ˆ φ(X1 T(t), X2 T(t), . . . , XN T(t)) = ˆ RT(t),(3.2) where ˆ RT ( t ) is an estimation of RT ( t ). In order to guarantee that an estimator ˆ φ can be found is necessary to assume the following: Assumption 2 (Ground truth function existence) . It is assumed that, φ , a mapping from Xi T(t)to RT(t)exists. Technical indicators in the stock market can produce contradictory signals and some non-linear techniques can have local minima issues when using high dimensionality input variables, (large N or T value). Therefore it might be convenient to find a combination of the technical indicators Xi T rather than using all N available indicators. A combinatorial selection approach for technical indicators, which do not have to be linear variable combination in non-linear processes, is presented. The steps are as follows: 1. Split the available instances of Xi T ( t ) and RT ( t ) data into two subsets, an estimation subset Se,{Xi T,e(t), RT,e(t)}and a validation1subset Sv,{Xi T,v(t), RT,v(t)}. 2. Generate Cs , a set of M combinations of bN 2c random numbers in the range { 1 , 2 , . . . , N} denoted from i1 to ibN 2c . Check for repetition within each combination. If there is repetition, leave out the repeated numbers and keep generating random numbers in the aforementioned range until there is no repetition. Similarly, check that there are no repeated combinations and proceed to replace the redundant ones. 3. For each of the M combinations in Cs , denoted as I∈Cs , perform the following steps: (a) Compute ˆ φ , i.e., the estimated non-linear classification mapping, using any technique of choice. In this case, the nonlinear mapping will have as arguments Xi T ( t ) ,∀i∈I . Using neural networks as an example, this step involves training a neural network with the training data set {Xi T,e(t), RT,e(t)}with i∈I. (b) Evaluate ˆ φ over the validation set. Let ˆ RT,v denote the estimated classification output of RT,v. (c) Calculate the error ξT ( t ) of the non-linear classification approach for each instance in the validation set, so that ξT(t) = (0 if ˆ RT,v(t) = RT,v(t), 1 Otherwise with the resulting total error being: ξT otal =P∀t∈SvξT(t) card(Sv),(3.3) 1To keep the notation as clear as possible here the term validation is used with the meaning of test 40
3.2. TECHNICAL INDICATOR SELECTION APPROACH where card ( Sv ) denotes the cardinality of Sv . This is therefore the total error for the initial random combination of technical indicators chosen in step 2. (d) Randomly generate a single value ia∈ { 1 , 2 , ..., N} that would denote a technical indicator candidate to be added to the combination chosen in step 2. Check for repetition with the previously generated N 2 values. If there is repetition, randomly generate another value ia . Repeat this step until there is no repetition. (e) Randomly generate a single value ir∈ {i1, . . . , iN 2} . This value will be used later to denote a technical indicator to be removed from the combination chosen in step 2. (f) Form a new combination of technical indicator indexes Iup as Iup ,I∪{ia} . In the same fashion, form a new combination Idown as Idown ,I−{ir} . If some of these combinations are already in Cs repeat either step 3d or 3e until a combination different from those of Csis obtained. (g) As in step 3a, compute two new mappings, denoted ˆ φup and ˆ φdown using this case as inputs arguments the technical indicators given by the index combinations Iup and Idown respectively. (h) As in step 3c compute the resulting total error of evaluating the two mappings computed in the previous step over the validation set. Denote these total errors as ξT otal up and ξT otal down . (i) Given the three previous index combinations I , Iup , Idown and their resulting total errors ξT otal , ξT otal up and ξT otal down pick the two combinations with the smallest error. (j) Substitute the initial combination I by the two combinations picked in the previous step. This will double the number of combinations in set Cs , i.e., Cs will contain 2Mcombinations after this step. 4. Retain the M combinations in Cs with the smallest error and discard the remaining Mcombinations with greatest error. 5. Find the minimum ξT otal of all the combinations I∈CS. 6. Repeat step 3 starting from 3d until a certain stop condition is met. Here it is proposed to check if a certain objective error is achieved or a maximum number of iterations is met, so that an infinite loop is avoided. Remark 1. This strategy can be easily parallelized as the tasks in step 3 can be done independently for each combination, hence can be done in parallel, with one exception. The latter part of step 3f, that is the rejection of repeated combinations, cannot be done in parallel and must be done sequentially in a separate step outside of step 3. Remark 2. The number of combinations in Cs , that is M , and the number of iterations are related in the sense that similar performances can be achieved by using a greater M and fewer iterations or vice versa. Besides the differences in performance due to the randomized nature of the proposed strategy, a practical difference can lead to one choice or the other. With a greater M one can exploit the parallelizable nature of the algorithm, whereas in the case of a high number of iterations that cannot be made. 41
3.2. TECHNICAL INDICATOR SELECTION APPROACH To illustrate the proposed approach consider a simple example with just two combinations (i.e., M= 2) and one iteration. If for instance, it is assumed that there are a total of 6 technical indicators to choose from, i.e., {X1 5, X2 5, X3 5, X4 5, X5 5, X6 5} , where the sub-index 5 means that each of the indicators are evaluated over five periods of time. There is also a related classification vector R5 identifying up and down movements in the stock at each time t (in this case R5∈ { 0 , 1 }5 ). First, the algorithm selects randomly 2 combinations of 3 initial technical indicator indexes. For example: Cs={I1, I2}={{3,5,6},{1,2,3}} Then the non-linear classification error is estimated for this configuration; let us assume that the obtained value is (with a slight abuse of notation the parameters of each combination will denote in this example the set of the parameters of both combinations): ξT otal ={0.6,0.5} Then the indexes iaand irare computed for each combination: ia={1,4}ir={6,2}. The addition of the new technical indicator index is done randomly, ensuring that there is no repetition, i.e., each input variable (technical indicator) is used only once. The index removed is also computed randomly. Then the combinations Iup and Idown are formed: Iup ={Iup 1, Iup 2}={{3,5,6,1},{1,2,3,4}} Idown ={Idown 1, Idown 2}={{3,5},{1,3}} Note that in every combination generated so far no index is repeated and that there are not repeated combinations. Once the new combinations are formed, their total classifying errors are computed: ξT otal up ={0.7,0.3} ξT otal down ={0.4,0.2} ξT otal ={0.6,0.5} For every combination in Cs two combinations (from I , Iup and Idown ) with the smallest error are chosen. From the first combination, Idown 1 and I1 are chosen. On the other hand, from the second combination Iup 2 and Idown 2 are chosen. Therefore, the augmented Cs will consists of: Cs={Idown 1, I1, Iup 2, Idown 2} with their errors: ξ={0.4,0.6,0.3,0.2} 42
3.3. CHINESE EQUITY MARKET APPLICATION The combinations are ordered using the error as sort criterion: Cs={{Idown 2, Iup 2, Idown 1, I1} ξ={0.2,0.3,0.4,0.6} Now the numbers of combinations can be reduced to its original number ( M = 2) picking the two with the smallest error: Cs={{Idown 2, Iup 2} with errors: ξ={0.2,0.3} Then at the end of this first iteration the algorithm would pick the combination Idown 2 as the best technical indicator combination, as it has the lowest error (0 . 2). Thus, the technical indicators proposed to forecast the direction of the change of price will be {X1 5, X3 5}. In practice, the number of combinations and iterations will be determined by the computing power available. The process thus will be repeated until a stop criteria is reached (that is, a maximum number of iterations or a target classification error). 3.3 Chinese Equity Market Application Data and Methodology The Chinese equity market is an increasingly important market propelled by the large economic expansion of the Chinese economy over the last few decades. The Chinese equity market is divided into two major stock exchanges. The Shanghai and the Shenzhen Stock Exchange with several major stock indexes describing the performance of those markets. It should be noted that there is no overlap between the Shanghai Stock market and the Shenzhen stock market i.e., there are no companies listed in both markets simultaneously. There are two main type of stocks. A-share and B-share. A-share is the main type of stocks while B-share are stocks that were originally created to allow foreign investors participate in the China onshore equity market. There hasn’t been any new IPO in the B-share in recent years and it is unlikely that there will be any in the future as it is a market been phased out. Therefore, it seem reasonable to focus the analysis on the A-share market. 6 different stock indexes describing the Chinese stock were used. These indexes reflect a wide spectrum of the Chinese equity market including small, large and medium caps. For example, the A50 is one of the most frequently used indexes for Chinese large cap stocks while the CSI 800 is a mid to small cap index describing companies listed in mainland China. For completeness purposes, and to limit some form of regional bias in the results, other international (non-Chinese) stock indexes (see Table 3.1) such as the Euro Stoxx 50, which is a frequently used index to describe the equity market 43
3.3. CHINESE EQUITY MARKET APPLICATION Table 3.1: Stock indexes. Indexes A50 FTSE China A50 index composed of the largest Chinese companies. CSI 300 Largest 300 companies listed in the Shenzhen and Shanghai Stock Exchanges CSI 800 Largest 800 companies listed in the Shenzhen and Shanghai Stock Exchanges Shanghai Composite Index composed of all the stocks listed in the Shanghai Stock Exchange Shenzhen Component Index composed of the largest 500 companies in the Shenzhen Stock Exchange SSE 50 Index composed of the largest 50 companies in the Shanghai Stock Exchange Euro Stoxx 50 Index composed by 50 of the largest companies from 11 Euro zone countries New York Composite Index composed of all the stocks listed in the New York Stock Exchange in Europe, and the New York Composite index which I used as a representative of the equity market in the United States were also used. As described in the previous section the selection approach is used to forecast the direction of the movement of the stock index (up or down) in the next time period rather than the exact end price for that period. Daily closing prices for all the indexes mentioned in Table 3.1 were collected from the Bloomberg database for the period from 14 February 2007 to 30 March 2020. The returns of those index can be seen in Figure 3.1. Positive or zero returns will result in an RTvalue of 0 and 1 otherwise. The proposed approach was used to identify an appropriate combination of technical indicators trying to describe the performance of the equity market. Stock technical indicators are indicators typically based on historical performance of the stock as well as the traded volume of that stock. There is an ever increasing amount of technical indicators in the existing literature which can generate contradictory signals. 35 commonly used stock technical indicators (see Table 3.2) extracted from the database Bloomberg were used. There is a very large amount of technical indicators ranging from simple moving averages (see figure 3.2) to proprietary indexes in which the actual algorithm describing the indexes is not publicly disclosed. It is also common to add volume information (see figure 3.3) as high or low volume can give an indication of possible stock price movements. In figure 3.2 it can be seen that the moving average acts as a smoothing of the actual stock price. The longer the time frame for the moving average the smoother output that this technical indicator will generate. It is common to use more than one moving average. The intuition behind this approach is using different time windows as indicators for mid 44
3.3. CHINESE EQUITY MARKET APPLICATION Figure 3.1: Returns of the indexes (measured in percentages). 45
3.3. CHINESE EQUITY MARKET APPLICATION Table 3.2: Technical indicators. Ct denotes the current price and Lt and Ht are the minimum and maximum prices in period t and MA means moving average. The exact formulas for some of the indexes are proprietary with the indicators for specific stocks obtainable from databases such as Bloomberg. Source: Blomberg, Kim [Kim, 2003]. N Indicator Description 1 SMAVG (50) 50 days simple MA. P49 i=0 Ct−i 50 2 SMAVG (100) 100 days simple MA. P99 i=0 Ct−i 100 3 SMAVG (200) 200 days simple MA. P199 i=0 Ct−i 200 4 Volume Total traded volume 5 Stochastic %K (14-day) Ct−min(Lt−n,∀n∈{1,...,14}) max(Ht−n,∀n∈{1,...,14})−min(Lt−n,∀n∈{1,...,14}) 6 %D (3-day) 3 days MA of stochastic %K. P2 i=0 Kt−i 3 7 %D (5-day) 5 days MA of stochastic %K. P4 i=0 Kt−i 5 8 Slow %D (3-day) MA of the 3 days %D. P2 i=0 Dt−i 3 9 Slow %D (5-day) MA of the 5 days %D. P4 i=0 Dt−i 5 10 Momentum (10-day) Change in price over a 10 days period. Ct−Ct−10 11 Moving average (5D) 5 days MA of 10-day Momemtum. P4 i=0 Mt−i 5 of Momentum (10-day) 12 ROC (daily) Change in price in % over 1 day period. Ct Ct−1100 13 Moving average (5D) of ROC 5 days MA of ROC. P4 i=0 ROCt−i 5 14 Williams (14) 14 days Williams’ indicator. max(Hn,∀n∈{1,...,14})−Ct max(Hn,∀n∈{1,...,14})−min(Ln,∀n∈{1,...,14}) 15 A/D oscillator Accumulation distribution indicator. Ht−Ct−1 Ht−Lt 16 MA (5) 5 days moving average. P4 i=0 Ct−i 5 17 MA (10) 10 days moving average. P9 i=0 Ct−i 10 18 Disparity 5 Ct MAt 19 Disparity 10 Ct MAt 20 OSCP MAt−MAn MAt 21 CMCI (13) (Ht+Lt+Ct)/3−P(Ht−i+1+Lt−i+1+Ct−i+1) 3n 0.015( P|Ht−i+1+Lt−i+1+Ct−i+1−P((Ht+Lt+Ct)/3)| n ) 22 RSI (14) on Close Relative strength index. 100 −100 1+ Average up Average down 23 MA (250) 250 days simple MA. P249 i=0 Ct−i 250 24 Z-score Distance in standard deviations from MA 25 AMAVG(14,2,30) Exponential MA 26 EMAVG (5) on Close 5 days exponential moving average with exponential term 2 t+1 27 TMAVG (5) on Close 5 days triangular moving average with factor t+1 2 28 VMAVG (5) on Close Variable MA with smoothing based in volatility 29 MACD(12,26) T1exponential MA (fast) minus T2exponential MA (slow) 30 Hurst(25) Exponential MA with mean reversion assumption. 31 FG(5) Ratio of buying and selling strength (5 days) 32 Kairi (Simple,25) Deviation of prices from its MA 33 Elder Force Index Relationship between price and trading volume movements 34 JKHL Index Relationship between new high and lows smoothed by two MA. 35 RMI(Close,14,10) Relationship between overbought and oversold levels 46
3.3. CHINESE EQUITY MARKET APPLICATION Figure 3.2: 50, 100 and 200 days moving average (CSI 500 Index). and long term performance. It also should be notice that, by definition, the moving average will roughly follow the trend of the actual stock price. This is clearly different of other technical indicators such as for instance, oscillators. The Chinese equity market has a large proportion of retail investors compared to institutional investors. Therefore it would seem reasonable to assume that indicators, such as momentum indicators, that are related to trend following investors (like retail investors usually are) is a reasonable technical indicator to consider. Therefore the 10-day momentum indicator (see figure 3.4) was included in the analysis. There is a large amount of momentum indicators available with most of them based on the idea that the market tend to follow, at least to some degree, the recent direction. It is easy to see that this type of technical indicator can generate a signal that it is rather different from the one obtained from a contrarian technical indicator, which are designed to try to indicate when an existing trend is likely to end. It seems reasonable to include both types of indicators as the market in fact shows these two types of behaviours. As previously mentioned there is a large amount of momentum indicators, being some of the basic distinctions among them the time frame over which the indicator is estimated. For example, in some momentum technical indicators for daily forecasts the indicator is built using historical data ranging from a couple of days to 300 days or even longer. Some momentum indicators use information only about the recent minimum and maximum while other use the entire stock prices time series for a predetermined period of time. There is a very large amount of potential combinations that can be used to build momentum technical indicators using historical data. The Williams indicator, seen in figure 3.5, and 47
3.3. CHINESE EQUITY MARKET APPLICATION Figure 3.3: Volume (CSI 500 index). the Relative Strength Index (RSI), seen in figure 3.6, are some other frequently used momentum indicators included in the analysis in this chapter. Some other technical indicators follow a completely different approach from momentum indicators (trend following) and try to detect when a stock is overbought or oversold and are hence defined as contrarian indicators. In figure 3.7 it can be seen one such indicator (OSCP) that was included in the analysis. The Z-score, showed in figure 3.8, is also typically used in stock forecasting as an indicator of the distance to typical values. From the graphs it is clear that the behavior of some of these technical indicators are clearly different and that can generate conflicting signals when used for stock forecasting or trend signaling. Another frequently used technical indicators are oscillators, such as the A/D oscillator showed in figure 3.9. These are perhaps among some of the most frequently used technical indicators, mentioned for instance in [Ahn et al., 2018,Ye and Huang, 2008], together with moving averages. Strictly speaking oscillators are a subtype of momentum indicators. The existing literature seems to support their use, particularly in markets with a high proportion of retail investors [Ni et al., 2015]. The idea, similarly to the case of overall momentum indicators, is that individual investors tend to follow the direction of the market (rather than taking contrarian views) in what is frequently called “Heard behavior” i.e., retail investors tend to buy when they see other retail investor buying a vice versa with little analysis regarding the future of the current trend. This type of trading can be potentially 48
3.4. RESULTS On the other hand, Figure 3.14 shows an example of the evolution of the error rate (misclassification of up/down days) in the training of one the neural networks. It can be seen that training improves the fitting to the data up to a significant number of training iterations, showing that the NN is really learning the ground truth function φ. Figure 3.14: Example of the evolution of the error rate as the number of iterations increases. The indicator selection approach is a combinatorial approach that can be used to select an appropriate combination of variables in non-linear models, using techniques such as neural networks. In the example illustrated the proposed approach was implemented in six different Chinese stock indexes plus two world indexes. The error rate obtained using the algorithm in combination with neural networks was lower than the error rate obtained using directly neural networks including all the 35 available variables, see Table 3.3. The average improvement in the error rate (over all the considered indexes) was 9.1%. It turns out that this is a very good result considering how difficult is the task of predicting the movements of the market and the great amount of benefits that can be realized even with a small improvement in the forecasting. Moreover, in some of the indexes the improvement is quite high, in excess of 11% (A50, Shanghai Composite and SSE50). A very interesting finding is that the baseline approach, that is, considering all the technical indicators available for forecasting yields error rates greater than 50% in some cases (A50, CSI800, Shanghai Composite, SSE 50 and Euro Stoxx 50). This means that tossing a coin produces better results than using the full pool of indicators. The reason for that is that, as pointed out in Section 3.3, some of the technical indicators produce contradictory signals. The histogram indicating the frequency of appearance of the technical indicators in the output of the algorithm for the various indexes shown in Table 3.3 can be seen in Figure 3.15. It is evident that some of the technical indicators are picked more frequently than others, thus they are more likely to provide better accuracy in the prediction of the price change direction. 55
3.4. RESULTS Table 3.3: Classification errors (up and down index movements) of the proposed approach using neural networks compared to the direct application of neural networks using all the 35 technical indicators. Index Direct Proposed Improv. Combinations (Error %) (Error %) (%) A50 54.0 41.2 12.8 (1,2,4,6,7,10,12,13,14,15 19,21,23,25,34,35) CSI 300 46.9 40.3 6.6 (2,3,4,7,8,11,12,13 15,19,21,25,26,29,34) CSI 800 50.7 41.1 9.6 (2,4,5,6,9,12,13,16 17,20,22,28,30,32,33,34) Shanghai Composite 52.3 40.1 12.2 (1,2,4,5,6,9,10,12,13,15 16,18,19,20,21,22,24,33) Shenzhen Component 45.6 40.7 4.9 (2,4,5,8,10,12,14,19,21 22,25,28,29,30,33,34,35) SSE 50 51.0 39.6 11.4 (1,2,3,7,9,10,11,12,20,21 22,24,25,27,28,30,32,35) Euro Stoxx 50 50.1 41.8 8.3 (3,4,7,11,17,18,20,22 25,27,28,31,33,34) New York Composite 47.2 40.7 9.0 (1,3,7,8,9,11,14,15,17,19 20,25,27,28,29,33,34) Average 49.7 41.0 9.1 56
3.4. RESULTS Nevertheless, this does not imply that using only these more relevant indicators will lead to a better forecasting. As an example the combination formed by the indicators with highest frequency of occurrence in Table 3.3 and Figure 3.15, i.e., { 2 , 4 , 12 , 25 , 34 } , gives an average improvement of 2 . 3% over the baseline approach, which is significantly worse than that achieved by using the proposed combinations. Figure 3.15: Histogram of the technical indicators appearance in the output of the proposed algorithm. Table 3.4 shows the improvement along the iterations on the algorithm. The average improvement from the first iteration to the last was 7.1%. While this value clearly evinces that the algorithm improves the initial combinations, a more rigorous test has been done. A Wilcoxon test was carried out comparing the distribution of error rates obtained in the first and last iterations for each index. The Wilcoxon test rejects the hypothesis, for all the indexes analyzed, that the median of the error rates for the initial and final distributions are statistically the same (Table 3.5), suggesting that the iterative process does significantly improve accuracy. The same approach was followed to compare the error rate using neural networks directly (with all 35 technical indicators) with the error rate obtained using the technical indicator selection approach (Table 3.6). The Wilcoxon test rejects the null hypothesis that the median of the error rates obtained using these two methods are statistically equivalent, suggesting that the proposed method statistically significantly improved the forecasting accuracy of up/down stock index movements. Remark 2 has been also taken into account, and the algorithm has also been used with M = 2 and a total 125 , 000 iterations which should be roughly equivalent to the parameters used previously, that is 100 combinations and 2500 iterations. The average improvement in this case was 8 . 7% which is marginally worse than that previously achieved. The difference could be due to the lower diversity of the set of candidate solutions, but also to the randomized nature of the strategy. 57
3.4. RESULTS Table 3.4: Classification errors (up and down index movements) of the selection approach using neural networks. Index Error Error Improvement (Initial) % (Final) % % A50 48.4 41.2 7.2 CSI 300 48.1 40.3 7.8 CSI 800 48.3 41.1 7.2 Shanghai Composite 46.9 40.1 6.8 Shenzhen Component 46.1 40.7 5.4 SSE 50 47.3 39.6 7.7 Euro Stoxx 50 49.7 41.8 7.9 New York Composite 47.5 40.6 6.9 Average 47.5 40.7 7.1 Table 3.5: Wilcoxon test comparing the error rate in the first and last iterations (p-values). Index p-Value A50 5.5467E-127 CSI 300 6.3542E-31 CSI 800 2.8497E-126 Shanghai Composite 6.4421E-115 Shenzhen Component 7.8451E-51 SSE 50 6.5487E-121 Euro Stoxx 50 4.6587E-114 New York Composite 7.6257E-112 Table 3.6: Wilcoxon test comparing the error rate using neural networks directly with all the 35 technical indicators and the algorithm output. Index p-Value A50 6.7894E-172 CSI 300 5.6284E-161 CSI 800 3.5487E-155 Shanghai Composite 4.6672E-167 Shenzhen Component 3.4837E-175 SSE 50 4.45728E-156 Euro Stoxx 50 4.6524E-156 New York Composite 2.7845E-165 58
3.5. DISCUSSION The average total time per index (100 initial configurations times 2500 iterations) was 157,691 s. The calculation time for each index can be seen in Table 3.7. The calculations were carried out in Matlab 2016 in an Intel, i5-3470, 3.2 GHz, 64 bit computer. The selection approach requires a significant amount of computation time but it clearly is faster than calculating all the possible combinations of technical indicators, which is for the example presented not a feasible calculation in a normal computer. Table 3.7: Calculation time. Index Total Time (sec) A50 159,132 CSI 300 177,876 CSI 800 144,195 Shanghai Composite 150,710 Shenzhen Component 169,498 SSE 50 156,739 Euro Stoxx 50 142,816 New York Composite 160,566 Average 157,691 3.5 Discussion The proposed method can be a feasible approach, when trying to determine a combination of variables or features to be used when forecasting the behaviour of non-linear processes. In the particular example of the stock market, there is a very large number of technical indicators that are intended to give the investor some indication of the future performance of the stock. These indicators can generate contradictory signals and selecting the appropriate combination of technical indicators can become a difficult task. Reducing the dimensionality of the problem is also important to avoid issues such as local minimum, that can cause poor generalization when applying techniques such as neural networks. It is showed in this chapter that it is possible to use this approach in the Chinese stock market (generating an appropriate combination of independent variables for non-linear models), obtaining better results than directly applying neural networks to all the available independent variables. This was tested using 6 Chinese stock index (as well as two international indexes) and 35 technical indicators. There was an average 9.1% improvement when using the combinatorial approach with neural networks over the results using directly all the technical indicators and neural networks as the non-linear forecasting technique. The formal statistical analysis comparing the results using neural networks directly (all technical indicators) with the results from the combinatorial approach using neural networks shows that there are statistically significant difference for the error rates obtained at a 1%, 5% and 10% significance level, supporting once more the hypothesis that the combinatorial approach using neural networks is a more 59
3.5. DISCUSSION appropriate tool for forecasting the direction of the stock market movement, at least for the 8 indexes analyzed, than using neural networks directly. Thus, for eight different indexes, better combinations of the technical indicators have been found, offering a practical choice to improve the forecasting accuracy and hence the expected benefits. The total calculation time per index (100 initial configurations time 2500 iterations) was 157,691 seconds. While this is a substantial amount of time it is a calculation that can be done with a normal laptop computer. Moreover, many of the operations of the proposed algorithm can be done in parallel further shortening the computation times. Although a direct comparison is challenging, the approach of using the combinatorial approach with neural networks seems to be generate better results for stock forecasting purposes than other approaches used in the existing literature, such as for instance the Box–Jenkins approach used by Groda and Vrbka [Groda and Vrbka, 2017], which the authors considered not suitable. A more comparable paper is Kim and Han [Kim and Han, 2000] that achieved a hit rate of 61% in the Korean market using genetic algorithm in combination to neural networks which is comparable to the 59% rate obtained in the Chinese market. Nevertheless comparison across different stock markets should be taken with caution. For instance, it should be naive to believe that the same approach would generate the same results in two markets as different as South Korea and China with China being an open stock market dominated by institutional investors while the Chinese market is a market dominated by local retail investors. The selection approach was illustrated in the context of the stock market and using neural networks but the approach is easily applicable to other fields. This is increasingly important as the amount of data available in many fields has increased substantially over the last few decades with an ever increasing need for tools to process large databases. Besides neural networks other non-linear models, such as for instance support vector machines or the forecasting techniques presented in the next chapter, can be used in the proposed approach. This could be an interesting area of future work. 60
Chapter 4 Stock forecasting using local data This chapter is based on the following journal publication: • Gerardo Alfonso, A. Daniel Carnerero, Daniel R. Ramirez, Teodoro Alamo. Stock forecasting using local data. IEEE Access 2021, vol.9, pp.9334-6344. Impact factor 3.745, JCR ranking Q1 (2019) 4.1 Introduction Stock price forecasting is a challenging field that has attracted researchers from different fields including engineers and scientists. It is likely fair to say that there is not yet an approach for stock forecasting that is accepted as superior, with the existing approaches having their strengths and weaknesses. Due to the financial relevance of stock price forecasting, many different techniques have been applied to the problem. The almost random nature of the market have made brownian motion [Osborne, 1959] and martingale models [Danthine, 1977,Barnett and Serletis, 2000] one of the first choices. Since the efficient market hypothesis is not proved, more elaborate techniques have been used trying to exploit the market inefficencies. Among these techniques, in the literature can be found applications with linear models [Zheng and Zhu, 2017], support vector machines [Lin et al., 2013], genetic algorithms [Mahfoud and Mani, 1996] or more frequently neural networks [Baba and Kozaki, 1992, White, 1988,Guresen et al., 2011] and deep learning methods [Cao and Wang, 2019,Yu and Yan, 2020,Chen et al., 2020] (for a recent survey on the topic see [Rao et al., 2020]). While neural networks are an important stock forecasting technique it should be noted that, as in any other technique, it has limitations. [Hor´ak and Krulick`y, 2019] did in this regard an interesting comparison between the exponential time series alignment method and the time series alignment with neural networks. The authors highlighted the importance of neural networks in the field of stock forecasting mentioning that generally neural networks provide better forecast than traditional methods. However, they also concluded that in their example, applied 61
4.1. INTRODUCTION to a volatile stock, the traditional forecasting method generated better results than the neural network. This highlights the importance of using the appropriate stock forecasting techniques with papers in the existing literature finding less than optimal results for some popular techniques. For instance, [Groda and Vrbka, 2017] concluded that the widely used Box–Jenkins model is not an appropriate method in the case of stocks listed in the Prague Stock Exchange. In this chapter two quantitative techniques that have not been applied to the problem of stock price and price interval forecasting are presented. One is an approach derived from the predictive control strategy presented in [Salvador et al., 2020,Salvador et al., 2018], which in turn can be related to the direct weight optimization approach [Bravo et al., 2016, Roll et al., 2005b, Jianhong, 2015]. Direct weight optimization uses linear estimators and convex optimization [Roll et al., 2005a], and has been applied in different fields like predictive control [He et al., 2010], nonlinear system identification [Bai and Liu, 2007] or electron density analysis [Wu and Van Voorhis, 2005]. The proposed approach uses local data, that is, only a subset of the whole data available, chosen among those past stock market states that are close to the current state. With such subset, the approach computes an optimal linear combination of past states that equals the current state, using such combination then to compute the price forecast. Unlike other methods, like neural networks, the proposed approach do not use a training phase as the subset and the linear combination is computed each time a forecast is needed. This allows an easy adaptation to different market situations and also the updating of the database as new data are available without having to retrain the estimator. Furthermore, the use of local data results in a lower computational burden, as the cardinality of the subset will be much lower than that of the whole data set. The other technique proposed in the chapter is a probabilistic price interval strategy previously presented in a more general context in [Carnerero et al., 2020]. This strategy can be used to forecast stock prices but its main application is to provide price intervals with a guaranteed probability of containing the real price. In this sense is complementary to the first approach as it provides the guarantees that the previous one lacks. On the other hand, although the algorithm is highly parallelizable, the computational burden is higher, thus it does not replace the first approach if no guarantees are required. This approach uses dissimilarity functions evaluated on local data to build an empirical probability distribution of the predicted price. Thus using such distribution it is possible to build price intervals using the desired percentiles and also predict the forecast using the median of the distribution. This can be very useful for risk management purposes [Berkowitz, 2001], a field of increasing importance in finance. Finally, as a case study, the techniques have been applied to the task of predicting future values of the Dow Jones Industrial Average Index up to 5 days (i.e., a full week), and also in the intraday market, validating the results in relation to two baseline approaches, a persistence (martingale) predictor and a neural network based predictor. Furthermore, quantile regression [Koenker and Hallock, 2001,Pradeepkumar and Ravi, 2017] has been used as a third baseline approach to validate the predicted price intervals. The results 62
4.2. STOCK PRICE FORECASTING USING LOCAL DATA prove that the proposed techniques are a valuable tool that can be added to the portfolio of existing techniques for stock price forecasting. The chapter is organized as follows: section 4.2 presents the first strategy for stock price forecasting using local data. The probabilistic price interval strategy is shown in section 4.3. Section 4.4 presents the results of these two strategies when used to forecast the Dow Jones Average Industrial Index. 4.2 Stock Price Forecasting using Local Data The first approach used in this chapter to forecast stock prices is based on the technique presented for predictive control in [Salvador et al., 2020,Salvador et al., 2018]. Consider the evolution of the price of a stock as a time series p ( t ) ∈ P , being t the time index expressed in the proper time unit, usually days in the case of the daily market, and P the possible range of values for the stock price. The state of the price time series is described as the value at time tof series of technical indicators, i.e., z(t)=(Z1(t), Z2(t), . . . , Znz(t)) ∈ <nz. These technical indicators can be past values of p ( t ), stock price returns or more complex metrics like moving averages or the relative strength indicator amongst others (see chapter 3). The objective is to be able to predict k -steps ahead the price of a stock, that is, to obtain ˆp(t+k) at time tin such a way that it is as close as possible to p(t+k). The approach presented here uses a database of past values of z ( t ) and k -step ahead stock prices. The database DBk for predicting k -steps ahead the price of p ( t ) will be implemented as a table with NDB entries (i.e., rows), in which each entry contains a past value of z(t) and the corresponding p(t+k), as shown in table 4.1. z(i1)p(i1+k) z(i2)p(i2+k) z(i3)p(i3+k) . . .. . . Table 4.1: Structure of the database DBk. Note that the time indexes ij of the past states do not have to be ordered in any way or be consecutive, thus they are not required to form a proper time series. The only requisite is that the price associated to z(ij) is the one corresponding to ksteps after time ij. The proposed approach does not use the database to train or fit a predictor, as in the training of a neural network. Thus, the database is not considered a training set (except for the tuning of a reduced number of hyperparameters). Instead, it is used every time a prediction is needed in an oracle fashion. Furthermore, the approach considered in this section uses only a subset of the database, denoted as Ω( z ( t )), to compute the prediction ˆp ( t + k ). In this sense it is also different from techniques like neural networks in 63
4.2. STOCK PRICE FORECASTING USING LOCAL DATA which the estimator is fitted using the whole training set. More precisely, given a distance measurement function d ( z ( t ) , z ( ij )), and cardinality parameter N , the elements of Ω( z ( t )) are obtained selecting the N states z ( ij ) closer to z ( t ). Thus, the prediction is computed using only local data. Once the data that are to be included in Ω(z(t)) are selected, the proposed approach proceeds to compute an optimal combination of all the z ( ij ) in Ω( z ( t )) that matches z ( t ), using the weights of such combination to compute ˆp ( t + k ) as the corresponding combination of all the p ( ij + k ) in Ω( z ( t )). Furthermore, a regularization term, weighted by a scalar γ≥ 0, is included in the computation of the optimal combination. Algorithm 1 gives a formal description of the proposed approach. Algorithm 1 k-step ahead stock forecasting using local data Input: DBk,z(t), Nand γ. Output: ˆp(t+k) (estimation of price at t+k). 1: Compute the distance d(z(t), z(ij)) for all z(ij) in the database DBk. 2: Create a list of the entries in DBk sorted according to the distances d ( z ( t ) , z ( ij )). Denote as zl and pl,k the state z ( ij ) and k -step ahead price p ( ij + k ) of the l -th entry in this ordered list. 3: Build Ω(z(t)) using the first Nentries in the ordered list, that is, Ω(z(t)) ,{(zl, pl,k)} ∀l∈ {1, . . . , N}. 4: Solve the following QP problem: min λ1, λ2, ..., λN N X l=1 λ2 l+γ|λl| s.t. N X l=1 λl= 1, N X l=1 λlzl=z(t). 5: Compute ˆp(t+k) as: ˆp(t+k) = N X l=1 λlpl,k. Remark 1. The distance d ( ·,· )can be any measure of how close are the states z ( ij )stored in DBk to z ( t ). A typical choice would be the Euclidean distance, i.e., d ( z ( t ) , z ( ij )) = kz ( t ) −z ( ij ) k , but also could consider other aspects like the time span between states, i,e., d(z(t), z(ij)) = kz(t)−z(ij)k+ρ|t−ij|, where the non negative scalar ρ would be a weighting factor. In this way recent data would be prioritized in the selection process of step 3 in algorithm 1. Other aspects like seasonality 64
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX 0 50 100 150 200 250 300 Day 1.55 1.6 1.65 1.7 1.75 1.8 1.85 Closing Price 104 Forecast Real 0 50 100 150 200 250 300 Day 1.55 1.6 1.65 1.7 1.75 1.8 1.85 Closing Price 104 Forecast Real Figure 4.1: Forecasted and real prices (5-day EMA) for 1 day and 2 days forecasting. 71
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX 0 50 100 150 200 250 300 Day 1.55 1.6 1.65 1.7 1.75 1.8 1.85 Closing Price 104 Forecast Real 0 50 100 150 200 250 300 Day 1.55 1.6 1.65 1.7 1.75 1.8 1.85 Closing Price 104 Forecast Real Figure 4.2: Forecasted and real prices (5-day EMA) for 3 and 4 days forecasting. 72
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX 0 50 100 150 200 250 300 Day 1.55 1.6 1.65 1.7 1.75 1.8 1.85 Closing Price 104 Forecast Real Figure 4.3: Forecasted and real prices (5-day EMA) for 5 days forecasting. The approach for price interval forecasting has been also applied to the case study. The parameters have been N = 250, Np = 1000, pmin = 6684 . 3, pmax = 19445, Nγ = 10, γmin = 0, γmax = 5, Nc = 60, cmin = 0 . 25, cmax = 15. The 10-th and 90-th percentiles were chosen for the price intervals, thus the probabilistic specification is that the intervals contain the real price is 0 . 8. The results obtained are shown in figures 4.4 to 4.6 in which the price intervals are represented as envelopes. It can be seen that although the price intervals are quite tight for k = 1, they grow as k rises. This is congruent with the fact that for farther prediction horizons the uncertainty on the forecasting is greater. Note also that sometimes the real price is not inside the computed price interval. This is also congruent to the fact that it should fall outside of the interval about 20% of the times. Even if the results obtained seem correct at a glance, it is necessary some form of validation. Thus, the results have been validated in relation to a persistence predictor, i.e., martingale, that has been used as a baseline approach forecasting the prices as ˆp ( t + k ) = p ( t ). Furthermore, a multi-layer perceptron (MLP) with 20 neurons in the hidden layer and trained with the Levenberg-Marquardt rule has been also used as a baseline approach. Table 4.2 shows the mean squared errors (MSE) for proposed and baseline approaches. It can be seen that the approach proposed in section 4.2 presents the lower MSE of all approaches and that the forecast using the strategy of section 4.3 is the second best for k up to 4. Another parameter to be studied is the dispersion of errors. Table 4.3 shows the standard deviations of the errors for all approaches. It can be seen that, as in the case of the MSE, the approach of section 4.2 has the tighter errors in all cases and that the forecasting using the median of the price distribution is the second best for k up to 4. Thus, the errors are expected to be smaller with the proposed 73
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX Figure 4.4: Price intervals for 1 to 2 days (5-day EMA). 74
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX Figure 4.5: Price intervals for 3 to 4 days (5-day EMA). 75
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX Figure 4.6: Price intervals for 5 days (5-day EMA). strategies and more close to their mean values. This also results in lower uncertainty on the quality of the prediction. Furthermore, the results show that the approach of section 4.2 is complementary to that of section 4.3 producing better forecasts with a much lower computational burden. In fact, when implemented in Matlab on an Intel Core i7-4790 CPU computer, the computation time for the strategy of section 4.2 was 0 . 0037 seconds. On the other hand, the implementation of Algorithm 2 took 0 . 3997 seconds on the same computer, whereas the implementation of algorithm 3 required 4 . 5 hours to find γ∗ and c∗ . Note, however, that γ∗ and c∗ are computed only once provided that the database does not suffer major changes. Table 4.2: MSE obtained using the proposed and baseline approaches (5-day EMA) Proposed Proposed kSection II Section III MLP Persistence 1 3,294.8 3,520.5 3,577.0 5,296.4 2 12,433.2 13,607.3 14,190.8 16,867.4 3 26,659.0 28,574.7 30,829.6 31,975.0 4 45,475.9 46,931.0 50,794.9 49,072.4 5 66,859.6 71,300.9 77,017.5 66,943.4 Although the MSE and standard deviation is better for the approach of section 4.2, it is practically equal to the MSE of the persistence predictor for k = 5. The reason for this is that as the prediction horizon k grows, the price time series becomes more similar to a random walk, making persistence predictors a good choice for price forecasting. This is more evident when the smoothing of the prices is quite light, like in the previous 76
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX Table 4.3: Standard deviation of the errors (σ); 5-day EMA Proposed Proposed kSection II Section III MLP Persistence 1 57.4 59.4 59.9 72.8 2 111.5 116.4 119.3 130.0 3 163.1 168.2 175.6 178.9 4 212.9 215.7 224.9 221.6 5 257.8 266.4 276.0 258.8 simulations. More typical periods in the EMA smoothing (12 and 26 days are common in stock trading for short term forecasting) show how the proposed approaches make a better job predicting the price trend than persistence predictors. Tables 4.4 and 4.5 show the MSE and standard deviations for all the approaches when using a 15-day EMA smoothing. These tables show that in this case the proposed approaches have always lower MSE and tighter errors. Furthermore, the MLP is also better than the persistence for all k , whereas in the case of the lighter smoothing it was worse for kequal to 4 and 5. Table 4.4: MSE obtained using the proposed and baseline approaches (15-day EMA) Proposed Proposed kSection II Section III MLP Persistence 1 469.2 486.8 606.8 1,531.7 2 2,129.4 2,313.2 2,492.3 5,642.4 3 5,386.7 5,907.5 7,538.6 11,944.6 4 10,596.6 11,554.2 13,629.2 20,151.2 5 17,745.7 19,856.5 24,768.5 29,953.1 Table 4.5: Standard deviation of the errors (σ); 15-day EMA Proposed Proposed kSection II Section III MLP Persistence 1 21.6 22.1 24.6 42.1 2 45.9 47.9 49.9 78.7 3 72.8 76.0 85.6 113.2 4 101.8 105.9 114.2 145.9 5 131.4 138.5 152.8 177.1 The proposed strategies can also be used to forecast intraday stock prices. The Dow Jones Industrial Average prices from 06/03/2020 to 11/03/2020 have been considered as an example. Tables 4.6 and 4.7 show the MSE and standard deviation values when forecasting half-hourly prices from this period. In these tests the longest forecasting horizon was 3 . 5 hours, thus k varies from 1 to 7. A 2 . 5-hour EMA has been used to smooth the prices and the structure of market state z ( t ) is the same as before but changing daily prices and RDP for their half-hourly counterparts. It can be seen that the strategy of section 4.2 performs as expected and that, in this case, there is no need for further smoothing to keep 77
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX the performance better than the persistence predictor. On the other hand, the strategy of section 4.3 has a higher MSE than the MLP (but lower than the persistence predictor). Note, however, that the strategy of section 4.3 is used to produce interval forecasts rather than price forecasts. Table 4.6: MSE obtained using the proposed and baseline approaches with intraday half-hourly prices (2.5-hour EMA) Proposed Proposed kSection II Section III MLP Persistence 1 1,034.9 1,153.1 1,037.7 2,103.9 2 4,406.9 4,816.6 4,498.1 7,335.2 3 10,233.0 11,527.9 10,589.7 14,584.5 4 17,423.8 19,859.2 18,599.3 22,933.7 5 25,453.4 29,444.1 27,880.3 31,796.9 6 34,002.5 39,619.5 37,676.9 40,947.9 7 43,086.0 49,990.4 49,331.7 50,124.3 Table 4.7: Standard deviation of the errors (σ); 2.5-hour EMA Proposed Proposed kSection II Section III MLP Persistence 1 32.2 33.5 32.1 45.9 2 66.4 68.2 66.9 85.7 3 101.2 104.6 102.6 120.9 4 132.0 136.8 135.9 151.6 5 159.5 165.8 166.4 178.5 6 184.3 191.6 193.3 202.5 7 207.4 215.4 221.2 224.1 On the other hand, the previous results and baseline approaches are not useful to validate the price interval forecasting obtained using the strategy of section 4.3. In order to do so, the well-known quantile regression has been chosen as a baseline approach to validate the interval forecasting. Table 4.8 shows the empirical probabilities and interval width of the proposed strategy and quantile regression using the same data and theoretical probability (0 . 8). It can be seen that the intervals computed using the proposed approach contains the real price with a higher probability than the specified one, whereas the quantile regression produces tighter intervals that do not meet the specified probability for any k . Thus, the quantile regression fails in this case. However, in the case of the intraday dataset both strategies work well (see table 4.9), being the proposed strategy a bit more conservative. Note that some form of tightening could be used with the proposed approach to make the intervals narrower while meeting the probability in practice, but the resulting intervals will not have the probabilistic guarantee of the approach. 78
4.4. FORECASTING THE DOW JONES INDUSTRIAL AVERAGE INDEX Table 4.8: Empirical probability of the real price to be contained in the computed intervals (the theoretical one is 0.8) and average width of the price intervals using the proposed approach and quantile regression. Empirical probability Average interval width kProposed Q. regression Proposed Q. regression 1 0.8679 0.6006 162.4802 99.8091 2 0.8459 0.6101 315.7218 190.5443 3 0.8553 0.6321 477.8004 287.5774 4 0.8648 0.6761 638.8747 397.3780 5 0.8805 0.6950 813.5661 489.7816 Table 4.9: Empirical probability and average width of the price intervals using the proposed approach and quantile regression (intraday dataset). Empirical probability Average interval width kProposed Q. regression Proposed Q. regression 1 0.8820 0.8614 88.5662 74.3958 2 0.8846 0.8373 178.6064 159.0279 3 0.8635 0.8279 275.3878 238.7693 4 0.8571 0.8214 378.3202 313.8665 5 0.8358 0.8119 443.9647 389.4412 6 0.8293 0.8084 516.9591 457.2965 7 0.8348 0.8138 576.9186 516.4660 Finally, the growing values of the forecasting error and its dispersion together with the effect of smoothing the prices suggest, that although not a perfect random walk for very short term forecasting, as the prediction horizon grows, the price time series becomes more difficult to forecast, gradually approaching to a random walk. 79
Chapter 5 Receding horizon optimization of large trade orders 5.1 Introduction Stock trading is becoming an increasingly complex field as investors try to maximize their profits, and reduce their risks with increased emphasis in recent years on optimal execution. After an investor has decided to buy or sell stocks, there remains many options on how to execute this trade. There are two basic types of trading orders: 1) market orders and 2) limit orders. A market order is an order to be executed immediately at the prevailing market price. The focus on this type of order is speed rather than price optimization. Limit orders on the other hand focuses on price efficiency. A limit order necessarily has an associated price over (below) which the buy (sell) order cannot be executed. It should be noted that the usual convention for limit prices orders is described by the expression “or better”. In other words, if the limit price on a buy limit order is 15 that the maximum price that the investor would pay, but the actual transaction price could be any price below that number. There is a tradeoff between speed of execution and price optimization. It is also very frequent to split orders into smaller orders in an attempt to not to impact the market. For instance, a buy order to purchase a large amount of stock could push the price of the stock up if executed in one single block. The market impact of that order can be potentially de reduced by splitting that single order in smaller orders, and execute them over time rather than in one go. There are clearly many ways in which this can be accomplished. One of the simplest approaches is called “Time Weighted Average Price”, commonly referred as TWAP. A TWAP order will split the order in blocks of shares of the same size, that are then executed at regular time intervals. For example, a TWAP order to buy 1,000 shares could be divided into 10 orders of 100 shares, each to be executed every 5 minutes. Therefore the complete trade takes 50 minutes to complete. An investor using a TWAP order needs to specify the time period over which the order needs to be executed. In the previous case this would be the previously mentioned 50 minutes. A TWAP trade can use market or limit price orders. In a TWAP market order there is almost certainty of execution as the transactions at each time interval is carries out at 80
5.3. OPTIMIZATION ALGORITHM Algorithm 5 Optimal execution of large limit orders. Input: M, Np, α, β, µ, σ, ι, c, pl. 1: repeat 2: Compute ˆ p(t) and ˆ v(t). 3: Form Ras in (5.7), and ˆ pR(t),ˆ vR(t). 4: if i1= 1 then solve (5.11) to obtain m∗R(t). 5: end if 6: Wait for next time bucket. 7: if i1= 1 & m∗ R(t+i1|t)>0 & p(t+ 1) ≤plthen 8: Send m∗ R(t+i1|t) to the market. 9: M←M−m∗ R(t+i1|t). 10: end if 11: Np←Np−1. 12: until M= 0 Finally, market and limit orders described so far can easily be executed under the “max” policy described in section 5.1 by imposing the additional constraint m(t+k|t)≤ˆv(t+k|t) cmax ∀k∈ {1, . . . , Np}(5.12) to (5.6) or m(t+ij|t)≤ˆv(t+ij|t) cmax ∀ij∈R(5.13) to problem (5.11), being cmax > 1 the parameter that adjust the limit on the volume fraction. 5.3 Optimization algorithm In this chapter, it is proposed to use a Particle Swarm Optimization (PSO) algorithm [Kennedy and Eberhart, 1995] to solve problems (5.6) and (5.11) defined in section 5.2. The reasons for such a choice are the potentially high number of decision variables and the fact that they are integer. Specifically, the implementation of the PSO algorithm is of the PSO with “Constriction coefficients” or “Constriction factor” type [Clerc and Kennedy, 2002], with a tailored treatment of the suborder constraints. In a PSO algorithm, particles represents potential solutions of the optimization problem to be solved. That is, they are compounded of feasible values of the decision variables. Also, the effectiveness of the particles is evaluated by means of a cost function or fitness function (as it is known in the PSO literature). After computing the cost for each particle, particles evolve to another generation following certain rules that are specific for each PSO algorithm. Usually, the worst particles are attracted to better solutions whereas the best particles tend to stay in their place. In the case of the proposed PSO algorithm, the particles are attracted to the best solution found in their evolution and to the best global solution found among all 87
5.3. OPTIMIZATION ALGORITHM the particles. This process is repeated until a sufficiently good solution is found, or an iteration or time limit constraint is met. In the proposed algorithm, every particle sistores the following data: •Current suborder sequence, mi∈NNp 0. • Current cost function value, i.e., Vi = V ( mi,ˆp ( t ) ,ˆv ( t )). Note that in the algorithm the forecasts of price and traded volumes are considered as input data, and therefore must be computed in advance. • Best past suborder sequence that has been found through the evolution of si denoted as mb i, and its associated cost function value, that is Vb i=V(mb i,ˆp(t),ˆv(t)). • The computed update velocity, ∆ mi . Velocities will determine how the particles are updated through the iterations of the algorithm. The steps of the proposed algorithm will be exposed in the the following. First it is necessary to give initial values to all the L particles in the particle set. This is done by means of a random generation of the vectors mi of each particle si and the computation of its associated costs. In this initial values the best suborder sequence and cost of each particle will be obviously set to the initial mi and its associated cost. Also. the algorithm needs to know the best cost so far, Vbest , that it is initially set to infinity, so that it gets updated in the first iteration. Then the algorithm iterates through the following steps: 1. Compute the cost Vifor every particle si. 2. Update the best so far cost Vb i and the best so far sequence mb i of each particle si if necessary (that is, if Vi< V b i). 3. Find the particle with the lowest cost and update the best so far global cost Vbest if necessary, also saving the associated sequence of suborders in a variable denoted by mbest. 4. Compute the update velocity ∆ mi for every particle and update the particles. The computation takes into account mainly two terms, one attracts the particle to mb i and the other attracts the particle to mbest , i.e., the velocity of a particle i is computed as ∆mi←χ∆mi+φ1r1mb i−mi+φ2r2mbest −ui,(5.14) where χ , φ1 and φ2 are constants with values 0 . 7298, 2 . 0500 and 2 . 0500 respectively, and r1∈[0,1] and r2∈[0,1] random numbers [Poli et al., 2007]. 5. Update the sequence of orders of every particle si according to mi←mi + ∆mi , rounding the resulting micomponent-wise to the nearest natural number. 88
5.4. CASE STUDY: CHINESE STOCK MARKET 6. Feasibility verification and particle modification. As the update of particles do not take into account the problem constraints, feasibility verification and restoration have to be performed after updating the particles. Handling inequality constraints is straightforward, as it is only needed to limit the values of the suborders, according to the maximum and minimum allowed. Equality constraints like (5.4), on the other hand, require a more complex treatment, using the following strategy based on random perturbations of the sequence of suborders: (a) First, for every particle, compute di=M− Np X k=0 mi(k),(5.15) that is, the amount of shares for which constraint (5.4) is violated. (b) Then, for every particle, apply random perturbations to some randomly chosen time buckets in the prediction horizon Np. (c) Check that all particles verify the inequality constraints and correct if necessary. (d) Compute again di, and repeat from 6b for those particles in which di6= 0. Once a stop condition is met (e.g., a total number of iterations or a limit in the change of Vbest ), the algorithm returns mbest as the solution. Algorithm 6 formally describes the steps of the proposed PSO strategy. Finally, constraints (5.12) or (5.13), required for “max”, can be handled easily by the algorithm in the same way as constraints (5.5) and (5.8). 5.4 Case Study: Chinese stock market The proposed approach has been validated using stocks from the Chinese Stock Market. A brief description of some market rules of the Chinese Stock Market is given in the following. The Chinese A-share market (main board) has several practical restrictions. Stocks traded in the onshore Chinese A-share market can only be purchased in increments of 100 shares. The portfolio of an investor can actually hold what is commonly referred as “odd lots”. For example, an investor can actually own 217 shares of a given stock. This is because of the result of corporate actions, such as stock dividends or conversion of convertible bonds. This odd lots can be disposed of, but there are limitations. The investors can sell the entire position (217 shares) or the odd lots (17 shares). The investor can also sell round lots, i.e., 100 shares or 200 shares. However, the investor will not be able to sell a different odd lot, such as for instance 8 shares. While this are limitations specific to the Chinese A-share market there are similar limitations in many other stock markets. The focus of this chapter is on the continuous trading period. Every working day has two continuous trading sessions. The morning session, from 9:30 to 11: 30, and the afternoon session. Additionally, there are two auctions. An opening auction, from 9:15 89
5.4. CASE STUDY: CHINESE STOCK MARKET Algorithm 6 PSO for large orders trading Input: L, c, M, Np,ˆp(t),ˆv(t) 1: Initialize the variables and particles with random generation of the mi. 2: repeat 3: for i= 1 to Ldo 4: Compute Viusing (5.2). 5: if Vi< V b ithen 6: Vb i←Vi. 7: mb i←mi. 8: end if 9: end for 10: Find m= arg min iVi. 11: if Vm< V best then 12: Vbest ←Vm. 13: mbest ←mm 14: end if 15: for i= 1 to Ldo 16: Compute ∆miaccording to (5.14). 17: mi←round(mi+∆mi). 18: for k= 1 to Npdo 19: if mi(k)>M cthen mi(k)←M c. 20: end if 21: if mi(k)<0 then mi(k)←0. 22: end if 23: end for 24: end for 25: for i= 1 to Ldo 26: f←0 27: while f= 0 do 28: Apply random perturbation to mi. 29: for k= 1 to Npdo 30: if mi(k)>M cthen mi(k)←M c. 31: end if 32: if mi(k)<0 then mi(k)←0. 33: end if 34: end for 35: Compute dias in (5.15). 36: if di= 0 then f←1 37: end if 38: end while 39: end for 40: until a stop condition is fulfilled. 90
5.4. CASE STUDY: CHINESE STOCK MARKET to 9:25, and a closing auction, from 14:57 to 15:00. The opening and closing auction set the opening and closing prices for the day, and follow different rules than the continuous trading session. This chapter focuses on the continuous trading session. Another important rules to take into account in the Chinese equity market is the up/down limit of 10%. This rules prevents any stock traded in the main board for increasing (decreasing) by more than 10%, compared to the previous day closing price. Please notice that there are different rules for stocks listed in the Chinext and STAR Board, which are outside of the scope of this thesis. To validate the proposed strategy, nine stocks from the Chinese Stock Market have been chosen, splitting the choices between small, mid or large capitalization stocks. Table 5.1 show the names and tickers of the nine stocks ordered according to their capitalization. The validation consists on the optimization of market orders of 2 , 000 , 000 shares over Table 5.1: Stock dataset. The following levels of market capitalization were followed for stock classification: small ( < 80 bn RMB), mid (from 80 to 300 bn) and large ( > 300 bn). Name Ticker Capitalization Nanjing Port 002040 Small Baotou Dongbao Biotech 300239 Small Royal Flush Information Network 300033 Small Advanced micro-fabrication equipment 688012 Mid Tianqi Lithium 002466 Mid Shangahi Pudong Development Bank 600000 Mid Ping An Bank 000001 Large Midea Group 000333 Large Kweichow Moutai 600519 Large a validation set of 20 two hour sessions randomly chosen from the range 1/4/2017 to 12/29/2020 (except the newer stock 688012 which is 1/2/2020 to 12/29/2020). The validation data sets are shown in figures 5.1 to 5.9. It can be seen that the sessions in each set show bearish, bullish and sideways trends. Furthermore, some of the sets, shown in figures 5.2 and 5.3, include sessions in which the 10% limit was activated. Note that in this situation the trading continues, albeit at most at that saturated price and, usually, with small traded volumes. The proposed trading strategy relies on forecasting of prices and traded volumes, but it is not linked to any particular forecasting technique. Here it is proposed to use the forecasting strategy of section 4.2. This predictor has proved to be more accurate than other methods like modelling the stock as a brownian motion process or forecasting with neural networks. In figure 5.10 it can be seen a sample of the obtained forecasted values, for the stock Shanghai Pudong Development Bank (600000) during a 120 minutes time interval (intraday), using the strategy of section 4.2 as well as neural network and brownian motion process (random walk). The neural network employed had a single hidden layer with 30 neurons. The random walk simulation was obtained following equation 1.2, and using the average return as the expected return (2.8%) and the historical standard deviation (0.1%) as the measure of the volatility of the process. As expected, the Brownian motion was the 91
5.4. CASE STUDY: CHINESE STOCK MARKET 0 20 40 60 80 100 120 20.5 21 21.5 0 20 40 60 80 100 120 20 20.2 20.4 20.6 0 20 40 60 80 100 120 18.7 18.8 18.9 0 20 40 60 80 100 120 19.8 20 20.2 0 20 40 60 80 100 120 20.8 21 21.2 0 20 40 60 80 100 120 18.7 18.75 18.8 18.85 0 20 40 60 80 100 120 19.4 19.6 19.8 0 20 40 60 80 100 120 19.2 19.4 19.6 0 20 40 60 80 100 120 19.2 19.3 19.4 0 20 40 60 80 100 120 19 19.2 19.4 0 20 40 60 80 100 120 20.2 20.4 20.6 0 20 40 60 80 100 120 20.6 20.8 21 0 20 40 60 80 100 120 18.7 18.8 18.9 0 20 40 60 80 100 120 18.8 19 19.2 0 20 40 60 80 100 120 18.8 19 19.2 0 20 40 60 80 100 120 17.2 17.3 17.4 0 20 40 60 80 100 120 20.5 21 21.5 22 0 20 40 60 80 100 120 20.8 21 21.2 0 20 40 60 80 100 120 21 22 23 0 20 40 60 80 100 120 19.4 19.5 19.6 Figure 5.1: Data set for 002040. 0 20 40 60 80 100 120 4.05 4.1 4.15 0 20 40 60 80 100 120 5.5 5.55 5.6 0 20 40 60 80 100 120 3.8 4 4.2 0 20 40 60 80 100 120 5 5.05 5.1 0 20 40 60 80 100 120 6.3 6.32 6.34 6.36 0 20 40 60 80 100 120 4.68 4.7 4.72 4.74 0 20 40 60 80 100 120 6.12 6.14 6.16 6.18 0 20 40 60 80 100 120 5.04 5.06 5.08 5.1 0 20 40 60 80 100 120 5.25 5.3 5.35 0 20 40 60 80 100 120 6.75 6.8 6.85 6.9 0 20 40 60 80 100 120 5.12 5.14 5.16 5.18 0 20 40 60 80 100 120 3.9 3.92 3.94 0 20 40 60 80 100 120 4.14 4.16 4.18 4.2 0 20 40 60 80 100 120 8.1 8.15 8.2 0 20 40 60 80 100 120 4.8 4.85 4.9 0 20 40 60 80 100 120 5.2 5.25 5.3 0 20 40 60 80 100 120 4.14 4.16 4.18 4.2 4.22 0 20 40 60 80 100 120 5.6 5.7 5.8 0 20 40 60 80 100 120 5 5.05 5.1 0 20 40 60 80 100 120 5.3 5.35 5.4 Figure 5.2: Data set for 300239. 92
5.4. CASE STUDY: CHINESE STOCK MARKET 0 20 40 60 80 100 120 37.8 38 38.2 38.4 0 20 40 60 80 100 120 118 118.5 119 0 20 40 60 80 100 120 34 34.5 35 35.5 0 20 40 60 80 100 120 63 63.5 64 0 20 40 60 80 100 120 50 51 52 0 20 40 60 80 100 120 42.6 42.8 43 43.2 0 20 40 60 80 100 120 41 41.5 42 0 20 40 60 80 100 120 68.5 69 69.5 70 0 20 40 60 80 100 120 47.5 48 48.5 0 20 40 60 80 100 120 58 60 62 0 20 40 60 80 100 120 42.6 42.8 43 0 20 40 60 80 100 120 100 102 104 0 20 40 60 80 100 120 51 51.5 52 0 20 40 60 80 100 120 142 144 146 148 0 20 40 60 80 100 120 53 53.5 54 0 20 40 60 80 100 120 69.6 69.8 70 70.2 0 20 40 60 80 100 120 82 83 84 0 20 40 60 80 100 120 48.5 49 49.5 0 20 40 60 80 100 120 51 51.5 52 0 20 40 60 80 100 120 80 82 84 Figure 5.3: Data set for 300033. 0 20 40 60 80 100 120 160 165 170 0 20 40 60 80 100 120 148 149 150 0 20 40 60 80 100 120 152 153 154 0 20 40 60 80 100 120 160 162 164 0 20 40 60 80 100 120 220 225 230 0 20 40 60 80 100 120 156 158 160 0 20 40 60 80 100 120 155 160 165 0 20 40 60 80 100 120 212 214 216 0 20 40 60 80 100 120 258 260 262 264 266 0 20 40 60 80 100 120 220 230 240 0 20 40 60 80 100 120 150 160 170 0 20 40 60 80 100 120 172 173 174 0 20 40 60 80 100 120 165 170 175 0 20 40 60 80 100 120 190 195 200 0 20 40 60 80 100 120 170 180 190 200 0 20 40 60 80 100 120 152 154 156 0 20 40 60 80 100 120 215 220 225 230 0 20 40 60 80 100 120 195 200 205 0 20 40 60 80 100 120 230 240 250 260 0 20 40 60 80 100 120 170 180 190 200 Figure 5.4: Data set for 688012. 93
5.4. CASE STUDY: CHINESE STOCK MARKET 0 20 40 60 80 100 120 35 36 37 0 20 40 60 80 100 120 67 68 69 70 0 20 40 60 80 100 120 28.8 29 29.2 29.4 0 20 40 60 80 100 120 75 76 77 0 20 40 60 80 100 120 25.4 25.6 25.8 26 0 20 40 60 80 100 120 23.4 23.6 23.8 24 0 20 40 60 80 100 120 24.6 24.8 25 25.2 0 20 40 60 80 100 120 34 34.2 34.4 34.6 0 20 40 60 80 100 120 52 54 56 0 20 40 60 80 100 120 34.6 34.8 35 0 20 40 60 80 100 120 57 57.5 58 0 20 40 60 80 100 120 61 61.5 62 0 20 40 60 80 100 120 22 23 24 0 20 40 60 80 100 120 46 46.5 47 0 20 40 60 80 100 120 55 56 57 0 20 40 60 80 100 120 23.6 23.8 24 0 20 40 60 80 100 120 69 69.5 70 0 20 40 60 80 100 120 63 64 65 66 0 20 40 60 80 100 120 23.1 23.2 23.3 0 20 40 60 80 100 120 25.8 26 26.2 26.4 Figure 5.5: Data set for 002466. 0 20 40 60 80 100 120 11.86 11.87 11.88 11.89 0 20 40 60 80 100 120 16.5 16.55 16.6 16.65 0 20 40 60 80 100 120 14.7 14.8 14.9 0 20 40 60 80 100 120 12.8 12.9 13 0 20 40 60 80 100 120 12.32 12.34 12.36 12.38 0 20 40 60 80 100 120 10.2 10.25 10.3 0 20 40 60 80 100 120 10.6 10.65 10.7 0 20 40 60 80 100 120 16.54 16.56 16.58 16.6 16.62 0 20 40 60 80 100 120 11.3 11.35 11.4 0 20 40 60 80 100 120 11.1 11.12 11.14 11.16 0 20 40 60 80 100 120 15 15.05 15.1 0 20 40 60 80 100 120 11 11.02 11.04 11.06 0 20 40 60 80 100 120 12.85 12.9 12.95 13 0 20 40 60 80 100 120 13.04 13.06 13.08 13.1 0 20 40 60 80 100 120 16.7 16.75 16.8 0 20 40 60 80 100 120 11.65 11.7 11.75 11.8 0 20 40 60 80 100 120 12.75 12.8 12.85 0 20 40 60 80 100 120 11.55 11.6 11.65 0 20 40 60 80 100 120 10.25 10.3 10.35 0 20 40 60 80 100 120 11.5 11.6 11.7 11.8 Figure 5.6: Data set for 600000. 94
5.4. CASE STUDY: CHINESE STOCK MARKET 0 20 40 60 80 100 120 11.5 11.55 11.6 0 20 40 60 80 100 120 11 11.1 11.2 11.3 0 20 40 60 80 100 120 14.6 14.8 15 0 20 40 60 80 100 120 12.6 12.65 12.7 0 20 40 60 80 100 120 12 12.2 12.4 0 20 40 60 80 100 120 10.75 10.8 10.85 10.9 0 20 40 60 80 100 120 14.6 14.8 15 0 20 40 60 80 100 120 9.3 9.32 9.34 9.36 0 20 40 60 80 100 120 13.2 13.25 13.3 0 20 40 60 80 100 120 9.25 9.26 9.27 0 20 40 60 80 100 120 12.65 12.7 12.75 12.8 0 20 40 60 80 100 120 12.1 12.15 12.2 12.25 0 20 40 60 80 100 120 12.8 12.9 13 0 20 40 60 80 100 120 11.65 11.7 11.75 0 20 40 60 80 100 120 14.8 15 15.2 0 20 40 60 80 100 120 11.9 12 12.1 0 20 40 60 80 100 120 10.7 10.8 10.9 0 20 40 60 80 100 120 13.6 13.7 13.8 0 20 40 60 80 100 120 12 12.2 12.4 0 20 40 60 80 100 120 10 10.1 10.2 Figure 5.7: Data set for 000001. 0 20 40 60 80 100 120 51 51.5 52 0 20 40 60 80 100 120 59 59.2 59.4 59.6 0 20 40 60 80 100 120 54.5 55 55.5 56 0 20 40 60 80 100 120 57.5 58 58.5 59 0 20 40 60 80 100 120 51 51.5 52 0 20 40 60 80 100 120 54.4 54.6 54.8 0 20 40 60 80 100 120 41.4 41.6 41.8 42 0 20 40 60 80 100 120 38.5 39 39.5 0 20 40 60 80 100 120 40 40.2 40.4 40.6 0 20 40 60 80 100 120 71 71.5 72 0 20 40 60 80 100 120 52 53 54 0 20 40 60 80 100 120 51.8 52 52.2 52.4 0 20 40 60 80 100 120 50.8 51 51.2 0 20 40 60 80 100 120 54 54.2 54.4 54.6 0 20 40 60 80 100 120 50.5 51 51.5 52 0 20 40 60 80 100 120 46.5 47 47.5 48 0 20 40 60 80 100 120 40 40.5 41 0 20 40 60 80 100 120 52.9 53 53.1 53.2 0 20 40 60 80 100 120 60.5 61 61.5 62 0 20 40 60 80 100 120 48.5 49 49.5 Figure 5.8: Data set for 000333. 95
5.4. CASE STUDY: CHINESE STOCK MARKET 0 20 40 60 80 100 120 488 490 492 494 0 20 40 60 80 100 120 472 474 476 0 20 40 60 80 100 120 755 760 765 0 20 40 60 80 100 120 346 348 350 0 20 40 60 80 100 120 465 470 475 0 20 40 60 80 100 120 470 472 474 476 0 20 40 60 80 100 120 755 760 765 0 20 40 60 80 100 120 1070 1080 1090 1100 0 20 40 60 80 100 120 870 880 890 900 0 20 40 60 80 100 120 705 710 715 0 20 40 60 80 100 120 714 716 718 0 20 40 60 80 100 120 435 440 445 0 20 40 60 80 100 120 493 494 495 0 20 40 60 80 100 120 1000 1002 1004 1006 0 20 40 60 80 100 120 1075 1080 1085 0 20 40 60 80 100 120 780 790 800 0 20 40 60 80 100 120 354 355 356 357 0 20 40 60 80 100 120 652 654 656 0 20 40 60 80 100 120 472 474 476 0 20 40 60 80 100 120 680 685 690 Figure 5.9: Data set for 600519. less accurate of all the forecasting techniques used. In order to forecast prices using the 0 20 40 60 80 100 120 17.85 17.9 17.95 18 18.05 18.1 18.15 Stock Price NN Brownian LD Figure 5.10: Sample of forecasts with the strategy of section 4.2, neural networks and brownian motion. strategy of section 4.2, the market state, denoted as zp ( t ) has been described as composed by the last 100 prices and the last traded volume, i.e., zp(t) = [p(t−1), p(t−2), . . . , p(t−100), v(t−1)]. 96
Appendix A Additional figures of chapter 2 A.1 Figures with results of testing different training algorithms and number of neurons. This section contains the figures for the results of using different training algorithms and number of neurons when using neural networks to forecast the stock indexes proposed in chapter 2. Each graph contains the evolution of the forecasting accuracy as the number of neurons is increased for a given index. For instance, figure A.1 shows how the forecasting accuracy, measured as R-squared, tends to decrease as the number of neurons increases for all the equity index (see table 2.1) for the quasi Newton learning algorithm (BFG). The abbreviations for each training algorithm can be seen in table 2.2. Figure A.1: Forecasting accuracy comparison of different moving averages using the quasi Newton (BFG) training algorithm (99% confidence interval). 103
A.1. RESULTS OF DIFFERENT ALGORITHMS AND NUMBER OF NEURONS Figure A.2: Forecasting accuracy comparison of different moving averages using the conjugate gradient (with restarts) training algorithm (99% confidence interval). Figure A.3: Forecasting accuracy comparison of different moving averages using the conjugate gradient Fetcher Powell training algorithm (99% confidence interval). 104
A.1. RESULTS OF DIFFERENT ALGORITHMS AND NUMBER OF NEURONS Figure A.4: Forecasting accuracy comparison of different moving averages using the conjugate gradient Polak Ribiere training algorithm (99% confidence interval). Figure A.5: Forecasting accuracy comparison of different moving averages using the gradient descent (adaptive learning) training algorithm (99% confidence interval). 105
A.1. RESULTS OF DIFFERENT ALGORITHMS AND NUMBER OF NEURONS Figure A.6: Forecasting accuracy comparison of different moving averages using the gradient descent (momentum) training algorithm (99% confidence interval). Figure A.7: Forecasting accuracy comparison of different moving averages using the gradient descent (momentum) training algorithm (99% confidence interval). 106
A.1. RESULTS OF DIFFERENT ALGORITHMS AND NUMBER OF NEURONS Figure A.8: Forecasting accuracy comparison of different moving averages using the Levenberg Marquardt training algorithm (99% confidence interval). Figure A.9: Forecasting accuracy comparison of different moving averages using the resilient backpropagation training algorithm (99% confidence interval). 107
A.2. RESULTS OF DIFFERENT ALGORITHMS AND MOVING AVERAGES Figure A.10: Results using conjugate gradient (with restarts) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. A.2 Figures of results using different training algorithms and different moving averages In this section every figure is divided into three subplots. From top to bottom this graph represents the analysis for the 50, 100 and 200 days moving averages showing how the forecasting accuracy evolves as the number of neurons is increased. For instance, figure A.10 illustrates the evolution of the forecasting accuracy of the conjugate gradient (with restarts) learning algorithm for all the ten stock indexes considered. 108
A.2. RESULTS OF DIFFERENT ALGORITHMS AND MOVING AVERAGES Figure A.11: Results using conjugate gradient Fetcher Powell training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. 109
A.2. RESULTS OF DIFFERENT ALGORITHMS AND MOVING AVERAGES Figure A.12: Results using gradient descent (adaptive learning) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. 110
A.2. RESULTS OF DIFFERENT ALGORITHMS AND MOVING AVERAGES Figure A.13: Results using gradient descent (momentum) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. 111
A.2. RESULTS OF DIFFERENT ALGORITHMS AND MOVING AVERAGES Figure A.14: Results using Levenberg Marquardt training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. 112
LIST OF FIGURES 5.10 Sample of forecasts with the strategy of section 4.2, neural networks and brownianmotion................................. 96 A.1 Forecasting accuracy comparison of different moving averages using the quasi Newton (BFG) training algorithm (99% confidence interval). . . . . . 103 A.2 Forecasting accuracy comparison of different moving averages using the conjugate gradient (with restarts) training algorithm (99% confidence interval). 104 A.3 Forecasting accuracy comparison of different moving averages using the conjugate gradient Fetcher Powell training algorithm (99% confidence interval). 104 A.4 Forecasting accuracy comparison of different moving averages using the conjugate gradient Polak Ribiere training algorithm (99% confidence interval). 105 A.5 Forecasting accuracy comparison of different moving averages using the gradient descent (adaptive learning) training algorithm (99% confidence interval)......................................105 A.6 Forecasting accuracy comparison of different moving averages using the gradient descent (momentum) training algorithm (99% confidence interval). 106 A.7 Forecasting accuracy comparison of different moving averages using the gradient descent (momentum) training algorithm (99% confidence interval). 106 A.8 Forecasting accuracy comparison of different moving averages using the Levenberg Marquardt training algorithm (99% confidence interval). . . . . 107 A.9 Forecasting accuracy comparison of different moving averages using the resilient backpropagation training algorithm (99% confidence interval). . . 107 A.10 Results using conjugate gradient (with restarts) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . 108 A.11 Results using conjugate gradient Fetcher Powell training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . 109 A.12 Results using gradient descent (adaptive learning) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . 110 A.13 Results using gradient descent (momentum) training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . 111 A.14 Results using Levenberg Marquardt training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . . . . . . . 112 A.15 Results using Secant training per country, 99% confidence interval, using the 50, 100 and 200 days moving average . . . . . . . . . . . . . . . . . . . 113 A.16 Results using resilient backpropagation training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . . . . . . . 114 A.17 Results using Polak Ribiere training per country, 99% confidence interval, using the 50, 100 and 200 days moving average. . . . . . . . . . . . . . . . 115 119
LIST OF FIGURES A.18 Results using gradient descent with momentum and adaptive learning training per country, 99% confidence interval, using the 50, 100 and 200 daysmovingaverage................................116 120
List of Tables 2.1 Countryequityindexes............................. 23 2.2 Training algorithm and standard Matlab abbreviation . . . . . . . . . . . . 26 2.3 RMSE for the IBEX and the Dow Jones using a neural network with 20 neurons. The RMSE values showed are the average of 100 simulations for eachcase. .................................... 28 2.4 R2values using LN training (95% confidence) . . . . . . . . . . . . . . . . 34 2.5 R2values using Scaled Conjugate training (95% confidence) . . . . . . . . 35 3.1 Stockindexes................................... 44 3.2 Technical indicators. Ct denotes the current price and Lt and Ht are the minimum and maximum prices in period t and MA means moving average. The exact formulas for some of the indexes are proprietary with the indicators for specific stocks obtainable from databases such as Bloomberg. Source: Blomberg, Kim [Kim, 2003]. . . . . . . . . . . . . . . . . . . . . . 46 3.3 Classification errors (up and down index movements) of the proposed approach using neural networks compared to the direct application of neural networks using all the 35 technical indicators. . . . . . . . . . . . . . . . . 56 3.4 Classification errors (up and down index movements) of the selection approach using neural networks. . . . . . . . . . . . . . . . . . . . . . . . . . 58 3.5 Wilcoxon test comparing the error rate in the first and last iterations (p-values)..................................... 58 3.6 Wilcoxon test comparing the error rate using neural networks directly with all the 35 technical indicators and the algorithm output. . . . . . . . . . . 58 3.7 Calculationtime. ................................ 59 4.1 Structure of the database DBk. ........................ 63 4.2 MSE obtained using the proposed and baseline approaches (5-day EMA) . 76 4.3 Standard deviation of the errors (σ); 5-day EMA . . . . . . . . . . . . . . 77 4.4 MSE obtained using the proposed and baseline approaches (15-day EMA) . 77 121
LIST OF TABLES 4.5 Standard deviation of the errors (σ); 15-day EMA . . . . . . . . . . . . . . 77 4.6 MSE obtained using the proposed and baseline approaches with intraday half-hourly prices (2.5-hour EMA) . . . . . . . . . . . . . . . . . . . . . . . 78 4.7 Standard deviation of the errors (σ); 2.5-hour EMA . . . . . . . . . . . . . 78 4.8 Empirical probability of the real price to be contained in the computed intervals (the theoretical one is 0.8) and average width of the price intervals using the proposed approach and quantile regression. . . . . . . . . . . . . 79 4.9 Empirical probability and average width of the price intervals using the proposed approach and quantile regression (intraday dataset). . . . . . . . 79 5.1 Stock dataset. The following levels of market capitalization were followed for stock classification: small ( < 80 bn RMB), mid (from 80 to 300 bn) and large (>300bn).................................. 91 5.2 Average prices in the validation set (RMB) . . . . . . . . . . . . . . . . . . 98 5.3 Savings on the validation set over VWAP and TWAP (RMB). . . . . . . . 99 122
Bibliography [Adrian, 2015] Adrian, Z.-I. (2015). The sensitivity of moving average trading rules performance with respect to methodological assumptions. Procedia Economics and Finance, 32:1353–1361. (Cited on page 23). [Ahn et al., 2018] Ahn, K., Choi, M., Dai, B., Sohn, S., and Yang, B. (2018). Modeling stock return distributions with a quantum harmonic oscillator. EPL (Europhysics Letters), 120(3):38003. (Cited on page 48). [Al Baali, 1985] Al Baali, M. (1985). Descent property and global convergence of the fletcher reeves method with inexact line search. IMA Journal of Numerical Analysis, 5(1):121–124. (Cited on page 16). [Almgren, 2003] Almgren, R. F. (2003). Optimal execution with nonlinear impact functions and trading-enhanced risk. Applied mathematical finance, 10(1):1–18. (Cited on page 84). [Anderberg, 1973] Anderberg, M. R. (1973). Cluster analysis for applications. Academic press. (Cited on page 65). [Atsalakis and Valavanis, 2009] Atsalakis, G. S. and Valavanis, K. P. (2009). Forecasting stock market short-term trends using a neuro-fuzzy based methodology. Expert systems with Applications, 36(7):10696–10707. (Cited on page 3). [Baba and Kozaki, 1992] Baba, N. and Kozaki, M. (1992). An intelligent forecasting system of stock price using neural networks. In [Proceedings 1992] IJCNN International Joint Conference on Neural Networks, volume 1, pages 371–377. IEEE. (Cited on page 61). [Bai and Liu, 2007] Bai, E.-W. and Liu, Y. (2007). Recursive direct weight optimization in nonlinear system identification: A minimal probability approach. IEEE Transactions on Automatic Control, 52(7):1218–1231. (Cited on page 62). [Baldi and Hornik, 1989] Baldi, P. and Hornik, K. (1989). Neural networks and principal component analysis: Learning from examples without local minima. Neural networks, 2(1):53–58. (Cited on page 38). [Ballings et al., 2015] Ballings, M., Van den Poel, D., Hespeels, N., and Gryp, R. (2015). Evaluating multiple classifiers for stock price direction prediction. Expert Systems with Applications, 42(20):7046–7056. (Cited on page 14). 123
BIBLIOGRAPHY [Barnes, 1986] Barnes, P. (1986). Thin trading and stock market efficiency: The case of the kuala lumpur stock exchange. Journal of Business Finance & Accounting, 13(4):609–617. (Cited on page 19). [Barnett and Serletis, 2000] Barnett, W. A. and Serletis, A. (2000). Martingales, nonlinearity, and chaos. Journal of Economic Dynamics and Control, 24(5-7):703–724. (Cited on page 61). [Bask, 2020] Bask, M. (2020). Pure announcement and time effects in the dividenddiscount model. The Quarterly Review of Economics and Finance, 77:266–270. (Cited on page 2). [Battiti, 1992] Battiti, R. (1992). First-and second-order methods for learning: between steepest descent and newton’s method. Neural computation, 4(2):141–166. (Cited on page 18). [Becker et al., 2020] Becker, M., Lippel, J., Stuhlsatz, A., and Zielke, T. (2020). Robust dimensionality reduction for data visualization with deep neural networks. Graphical Models, 108:101060. (Cited on page 39). [Berkowitz, 2001] Berkowitz, J. (2001). Testing density forecasts, with applications to risk management. Journal of Business & Economic Statistics, 19(4):465–474. (Cited on page 62). [Bertsimas and Lo, 1998] Bertsimas, D. and Lo, A. W. (1998). Optimal control of execution costs. Journal of Financial Markets, 1(1):1–50. (Cited on page 82). [Bettman et al., 2009] Bettman, J. L., Sault, S. J., and Schultz, E. L. (2009). Fundamental and technical analysis: substitutes or complements? Accounting & Finance, 49(1):21–36. (Cited on page 37). [Bia lkowski et al., 2008] Bia lkowski, J., Darolles, S., and Le Fol, G. (2008). Improving vwap strategies: A dynamic volume approach. Journal of Banking & Finance, 32(9):1709– 1722. (Cited on page 82). [Bianchini et al., 1994] Bianchini, M., Gori, M., and Maggini, M. (1994). On the problem of local minima in recurrent neural networks. IEEE Transactions on Neural Networks, 5(2):167–177. (Cited on page 38). [Bofa, 2007] Bofa (2007). Marching up the learning curve: The second buy-side algorithmic trading survey. Bank of America. (Cited on page 81). [Bokhari et al., 2005] Bokhari, J., Cai, C., Hudson, R., and Keasey, K. (2005). The predictive ability and profitability of technical trading rules: does company size matter? Economics letters, 86(1):21–27. (Cited on page 38). [Bravo et al., 2016] Bravo, J. M., Alamo, T., Vasallo, M., and Gegundez, M. (2016). A general framework for predictors based on bounding techniques and local approximation. IEEE Transactions on Automatic Control, 62(7):3430–3435. (Cited on page 62). 124
BIBLIOGRAPHY [Breger et al., 2017] Breger, A., Ehler, M., Bogunovic, H., Waldstein, S., Philip, A.-M., Schmidt-Erfurth, U., and Gerendas, B. (2017). Supervised learning and dimension reduction techniques for quantification of retinal fluid in optical coherence tomography images. Eye, 31(8):1212–1220. (Cited on page 39). [Brown and Jennings, 1989] Brown, D. P. and Jennings, R. H. (1989). On technical analysis. The Review of Financial Studies, 2(4):527–551. (Cited on page 38). [Bruand and Gibson-Asner, 1998] Bruand, M. and Gibson-Asner, R. (1998). The effects of newly listed derivatives in a thin stock market. Review of Derivatives Research, 2(1):59–86. (Cited on page 18). [Bruni, 2017] Bruni, R. (2017). Stock market index data and indicators for day trading as a binary classification problem. Data in brief, 10:569–575. (Cited on page 38). [Budagaga, 2020] Budagaga, A. R. (2020). Dividend policy and market value of banks in mena emerging markets: residual income approach. Journal of Capital Markets Studies. (Cited on page 2). [Cao and Wang, 2019] Cao, J. and Wang, J. (2019). Stock price forecasting model based on modified convolution neural network and financial time series analysis. International Journal of Communication Systems, 32:e3987. (Cited on page 61). [Cao et al., 2018] Cao, W., Wang, X., Ming, Z., and Gao, J. (2018). A review on neural networks with random weights. Neurocomputing, 275:278–287. (Cited on page 14). [Carnerero et al., 2020] Carnerero, A. D., Ramirez, D. R., and Alamo, T. (2020). Probabilistic interval predictor based on dissimilarity functions. arXiv e-prints, page arXiv:2010.15530. (Cited on pages 62, 65, 66, 67, 68, and 70). [Chaudhuri and Wu, 2003] Chaudhuri, K. and Wu, Y. (2003). Random walk versus breaking trend in stock prices: Evidence from emerging markets. Journal of Banking & Finance, 27(4):575–592. (Cited on page 8). [Chen et al., 2016] Chen, J.-F., Chen, W.-L., Huang, C.-P., Huang, S.-H., and Chen, A.-P. (2016). Financial time-series data analysis using deep convolutional neural networks. In 2016 7th International Conference on Cloud Computing and Big Data (CCBD), pages 87–92. IEEE. (Cited on page 14). [Chen et al., 2020] Chen, Q., Zhang, W., and Lou, Y. (2020). Forecasting stock prices using a hybrid deep learning model integrating attention mechanism, multi-layer perceptron, and bidirectional long-short term memory neural network. IEEE Access, 8:117365– 117376. (Cited on page 61). [Chitra, 2011] Chitra, R. (2011). Technical analysis on selected stocks of energy sector. International Journal of Management & Business Studies, 1(1):42–46. (Cited on page 37). 125
BIBLIOGRAPHY [Chong et al., 2014] Chong, T. T.-L., Ng, W.-K., and Liew, V. K.-S. (2014). Revisiting the performance of macd and rsi oscillators. Journal of risk and financial management, 7(1):1–12. (Cited on page 37). [Clerc and Kennedy, 2002] Clerc, M. and Kennedy, J. (2002). The particle swarmexplosion, stability, and convergence in a multidimensional complex space. IEEE transactions on Evolutionary Computation, 6(1):58–73. (Cited on page 87). [Cooper, 1982] Cooper, J. C. (1982). World stock markets: Some random walk tests. Applied Economics, 14(5):515–531. (Cited on page 7). [Crawford et al., 2018] Crawford, B., Soto, R., San Mart´ın, M. A., de la Fuente-Mella, H., Castro, C., and Paredes, F. (2018). Automatic high-frequency trading: An application to emerging chilean stock market. Scientific Programming, 2018. (Cited on page 82). [Cui et al., 2009] Cui, W., Brabazon, A., and O’Neill, M. (2009). Efficient trade execution using a genetic algorithm in an order book based artificial stock market. In Proceedings of the 11th Annual Conference Companion on Genetic and Evolutionary Computation Conference: Late Breaking Papers, pages 2023–2028. (Cited on page 82). [Danthine, 1977] Danthine, J.-P. (1977). Martingale, market efficiency and commodity prices. European Economic Review, 10(1):1–17. (Cited on page 61). [de Souza et al., 2018] de Souza, M. J. S., Ramos, D. G. F., Pena, M. G., Sobreiro, V. A., and Kimura, H. (2018). Examination of the profitability of technical analysis based on moving average strategies in brics. Financial Innovation, 4(1):3. (Cited on page 38). [DeFusco et al., 2015] DeFusco, R. A., McLeavey, D. W., Pinto, J. E., and Runkle, D. E. (2015). Quantitative investment analysis workbook. John Wiley & Sons. (Cited on pages 1 and 3). [Dennis Jr and Schnabel, 1996] Dennis Jr, J. E. and Schnabel, R. B. (1996). Numerical methods for unconstrained optimization and nonlinear equations. SIAM. (Cited on page 16). [Ding et al., 2015] Ding, Y., Cheng, L., Pedrycz, W., and Hao, K. (2015). Global nonlinear kernel prediction for large data set with a particle swarm-optimized interval support vector regression. IEEE transactions on neural networks and learning systems, 26(10):2521–2534. (Cited on page 82). [Dixon, 2018] Dixon, M. (2018). Sequence classification of the limit order book using recurrent neural networks. Journal of computational science, 24:277–286. (Cited on page 82). [Dupernex, 2007] Dupernex, S. (2007). Why might share prices follow a random walk. Student Economic Review, 21(1):167–179. (Cited on page 7). [Fama, 1991] Fama, E. F. (1991). Efficient capital markets: Ii. The journal of finance, 46(5):1575–1617. (Cited on page 20). 126
BIBLIOGRAPHY [Fama, 1995] Fama, E. F. (1995). Random walks in stock market prices. Financial analysts journal, 51(1):75–80. (Cited on page 8). [Forsyth et al., 2012] Forsyth, P., Kennedy, J., Tse, S., and Windcliff, H. (2012). Optimal trade execution: A mean quadratic variation approach. Journal of Economic Dynamics and Control, 36(12):1971 – 1991. (Cited on page 82). [Forsyth, 2011] Forsyth, P. A. (2011). A hamilton jacobi bellman approach to optimal trade execution. Applied Numerical Mathematics, 61(2):241 – 265. (Cited on page 82). [Frennberg and Hansson, 1993] Frennberg, P. and Hansson, B. (1993). Testing the random walk hypothesis on swedish stock prices: 1919–1990. Journal of Banking & Finance, 17(1):175–191. (Cited on page 8). [Gencay, 1998] Gencay, R. (1998). The predictability of security returns with simple technical trading rules. Journal of Empirical Finance, 5(4):347–359. (Cited on page 38). [Gencay and Stengos, 1998] Gencay, R. and Stengos, T. (1998). Moving average rules, volume and the predictability of security returns with feedforward networks. Journal of Forecasting, 17(5-6):401–414. (Cited on page 23). [Glabadanidis, 2015] Glabadanidis, P. (2015). Market timing with moving averages. International Review of Finance, 15(3):387–425. (Cited on page 38). [Glaser et al., 2004] Glaser, M., N¨oth, M., and Weber, M. (2004). Behavioral finance. Blackwell handbook of judgment and decision making, pages 527–546. (Cited on page 6). [Gori and Tesi, 1992] Gori, M. and Tesi, A. (1992). On the problem of local minima in backpropagation. IEEE Transactions on Pattern Analysis and Machine Intelligence, 14(1):76–86. (Cited on page 38). [Granger, 1992] Granger, C. W. (1992). Forecasting stock market prices: Lessons for forecasters. International Journal of Forecasting, 8(1):3–13. (Cited on page 14). [Groda and Vrbka, 2017] Groda, B. and Vrbka, J. (2017). Prediction of stock price developments using the box-jenkins method. In SHS Web of Conferences, volume 39, page 01007. EDP Sciences. (Cited on pages 60 and 62). [Guresen et al., 2011] Guresen, E., Kayakutlu, G., and Daim, T. U. (2011). Using artificial neural network models in stock market index prediction. Expert Systems with Applications, 38(8):10389 – 10397. (Cited on pages 14 and 61). [Guyon and Elisseeff, 2003] Guyon, I. and Elisseeff, A. (2003). An introduction to variable and feature selection. Journal of machine learning research, 3(Mar):1157–1182. (Cited on page 38). [Hasibuan et al., 2019] Hasibuan, D., Jaya, I. K., Rumahorbo, B., Naibaho, J., Napitupulu, J., and Rajagukguk, E. (2019). Time series financial market forecasting based on support vector regression algorithm. In 2019 International Conference of Computer Science and Information Technology (ICoSNIKOM), pages 1–4. IEEE. (Cited on page 81). 127
BIBLIOGRAPHY [He et al., 2010] He, Q., Tan, S., and Wanshan, D. (2010). DWO based predictive control for nonlinear systems. In 2010 International Conference on Measuring Technology and Mechatronics Automation, volume 2, pages 38–41. IEEE. (Cited on page 62). [Hinton and Salakhutdinov, 2006] Hinton, G. E. and Salakhutdinov, R. R. (2006). Reducing the dimensionality of data with neural networks. science, 313(5786):504–507. (Cited on page 39). [Hocking, 1976] Hocking, R. R. (1976). A biometrics invited paper. the analysis and selection of variables in linear regression. Biometrics, 32(1):1–49. (Cited on page 38). [Hoque et al., 2007] Hoque, H. A., Kim, J. H., and Pyun, C. S. (2007). A comparison of variance ratio tests of random walk: A case of asian emerging stock markets. International Review of Economics & Finance, 16(4):488–502. (Cited on page 8). [Hor´ak and Krulick`y, 2019] Hor´ak, J. and Krulick`y, T. (2019). Comparison of exponential time series alignment and time series alignment using artificial neural networks by example of prediction of future development of stock prices of a specific company. In SHS Web of Conferences, volume 61, page 01006. EDP Sciences. (Cited on page 61). [Idowu et al., 2012] Idowu, P. A., Osakwe, C., Aderonke, A. K., and Adagunodo, E. R. (2012). Prediction of stock market in nigeria using artificial neural network. International Journal of Intelligent Systems and Applications, 4(11):68. (Cited on page 20). [Ince and Trafalis, 2008] Ince, H. and Trafalis, T. B. (2008). Short term forecasting with support vector machines and application to stock price prediction. International Journal of General Systems, 37(6):677–687. (Cited on page 3). [Jianhong, 2015] Jianhong, W. (2015). Improvement on direct weight optimization identification. Journal of Control and Systems Engineering, 3:1–9. (Cited on page 62). [Johnston et al., 1999] Johnston, F., Boyland, J., Meadows, M., and Shale, E. (1999). Some properties of a simple moving average when applied to forecasting a time series. Journal of the Operational Research Society, 50(12):1267–1271. (Cited on page 23). [Kanas, 2001] Kanas, A. (2001). Neural network linear forecasts for stock returns. International Journal of Finance & Economics, 6(3):245–254. (Cited on page 14). [Kennedy and Eberhart, 1995] Kennedy, J. and Eberhart, R. (1995). Particle swarm optimization. In Proceedings of ICNN’95-International Conference on Neural Networks, volume 4, pages 1942–1948. IEEE. (Cited on page 87). [Khaidem et al., 2016] Khaidem, L., Saha, S., and Dey, S. R. (2016). Predicting the direction of stock market prices using random forest. arXiv preprint arXiv:1605.00003. (Cited on page 37). [Khoda et al., 1992] Khoda, K., Liu, Y., and Storey, C. (1992). Generalized polak-ribiere algorithm. Journal of Optimization Theory and Applications, 75(2):345–354. (Cited on page 16). 128
BIBLIOGRAPHY [Ye et al., 2014] Ye, X., Yan, R., and Li, H. (2014). Forecasting trading volume in the chinese stock market based on the dynamic vwap. Studies in Nonlinear Dynamics & Econometrics, 18(2):125–144. (Cited on page 82). [Yoon and Swales, 1991] Yoon, Y. and Swales, G. (1991). Predicting stock price performance: A neural network approach. In Proceedings of the twenty-fourth annual Hawaii international conference on system sciences, volume 4, pages 156–162. IEEE. (Cited on page 14). [Yu and Yan, 2020] Yu, P. and Yan, X. (2020). Stock price prediction based on deep neural networks. Neural Computing and Applications, 32:1609–1628. (Cited on page 61). [Yu and Chen, 1995] Yu, X.-H. and Chen, G.-A. (1995). On the local minima free condition of backpropagation learning. IEEE Transactions on Neural Networks, 6(5):1300–1303. (Cited on page 38). [Yuan and Lin, 2006] Yuan, M. and Lin, Y. (2006). Model selection and estimation in regression with grouped variables. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 68(1):49–67. (Cited on page 38). [Zhang et al., 1998] Zhang, G., Patuwo, B. E., and Hu, M. Y. (1998). Forecasting with artificial neural networks:: The state of the art. International journal of forecasting, 14(1):35–62. (Cited on page 14). [Zhang, 2007] Zhang, G. P. (2007). A neural network ensemble method with jittered training data for time series forecasting. Information Sciences, 177(23):5329–5346. (Cited on page 14). [Zhang and Suganthan, 2016] Zhang, L. and Suganthan, P. N. (2016). A survey of randomized algorithms for training neural networks. Information Sciences, 364:146–155. (Cited on page 14). [Zhang et al., 2006] Zhang, L., Zhou, W., and Li, D.-H. (2006). A descent modified polak– ribi`ere–polyak conjugate gradient method and its global convergence. IMA Journal of Numerical Analysis, 26(4):629–640. (Cited on page 16). [Zheng and Zhu, 2017] Zheng, C. and Zhu, J. (2017). Research on stock price forecast based on gray relational analysis and armax model. In 2017 International Conference on Grey Systems and Intelligent Services (GSIS), pages 145–148. (Cited on page 61). 135