A S t u d y of F i n a n c i a l M a r k e t s w i t h Hete rogeneous A gen t s A Numerical Approach by Bruno L'Esperance B.Sc, Universite de Montreal, 2005 A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF T H E REQUIREMENTS FOR T H E DEGREE OF Master of Science in The Faculty of Graduate Studies (Mathematics) T H E UNIVERSITY OF BRITISH COLUMBIA August 2007 © Bruno L'Esperance 2007 Abstract In this thesis, we present a model of a financial market with many heterogeneous agents in a continuous double auction market organization. We introduce the different concepts related to continuous double auction and electronic limit order book. We then construct a financial market model with heterogeneous agents that are using this electronic order book to trade. At each time, the next agent to trade is chosen independently of others according to a Poisson process. Each agent will decide to buy or to sell the stock according to the rec-ommendation of a financial expert. These recommendations represent the expert expected price of the stock for the next period. There are three types of financial experts: the noise traders, the fundamentalist traders and the chartist traders. The recommendations from the noise traders are random, the recommendations from the fundamentalists are based on some fundamental value of the stock price while the recommendations of the chartists are form using some extrapolatory or contrarian rules. The agents are choosing the financial expert by comparing each of them using a performance measure. In our case, they compare a discounted sum of past profits their recommendation would have generated. Once the financial expert is determined, the agent forms her excess demand and then executes her trade according to the sign of her excess demand. Finally, we present numerical results from the simulation of this model and compare them with previously found empirical re-sults. Some interesting results include the relation between the volatility of the stock and the trading volume, the bid and ask spread and the stock returns, the analysis of the effects of the variation of some important parameters like the tick size, the market activity and the level of patience of the agents, the analysis of the effects of the chartist traders on the return and price distributions and the comparison of the tail of the return distribution with a power-law distribution. The most important result is the suggestion of the existence and uniqueness of a unique stationary distribution for the price process. ii Table of Contents A b s t r a c t 1 1 Table of Contents iii List of Tables v List of Figures vi Acknowledgements v ' i i Dedicat ion l x 1 Introduct ion 1 1.1 Review of Literature 1 1.2 Details of the Most Relevant Literature 3 1.2.1 Models of Continuous Double Auction 4 1.2.2 Financial Market with Heterogeneous Agents 5 1.3 Relevance of this Thesis 7 1.4 Outline of the Thesis 8 2 O r d e r B o o k D y n a m i c s 10 2.1 Continuous Double Auction and Definitions 10 2.2 Order Book Dynamics 15 2.2.1 Case 1 16 2.2.2 Case 2 17 2.2.3 Case 3 18 2.2.4 Case 4 19 2.2.5 Case 5 20 2.2.6 Case 6 26 2.2.7 Case 7 27 3 T h e M o d e l 29 3.1 The Model in Brief 29 3.2 The Agents 30 iii Table of Contents 3.2.1 The Case of Buy Orders 33 3.2.2 The Case of Sell Orders 34 3.3 The Experts 37 3.4 The performance measure 38 3.5 Order Submission Mechanism 39 4 S imulat ion and Results 42 4.1 Setting the parameters 42 4.2 Results 44 4.2.1 Shape of the Order Book 44 4.2.2 The Volatility in the Asset Prices 46 4.2.3 Some Relevant Parameters 53 4.2.4 The Effects of the Chartists 57 4.2.5 Power-law Distribution 62 4.2.6 In Search of the Stationary Distribution 68 5 Discussion and Conclusions 72 5.1 Discussion 72 5.2 Conclusion 73 5.3 Further Research 73 Bib l iography 75 Appendices A M a i n Func t ion of the P r o g r a m 79 B Lis t of O t h e r Funct ions 100 B . l How to Produce the Figures 100 B. 2 Other Functions 100 C Statistical Tests 102 C l Converting the Data 102 C. 2 Results 102 List of Tables 4.1 Setting the parameters 4.2 The Different Correlations List of Figures 2.1 Order book representation 13 2.2 Second order book representation 14 2.3 Best bid, best ask, spread and middle 15 2.4 Receiving a buy market order 16 2.5 Receiving a sell market order 17 2.6 Receiving some buy limit orders 18 2.7 Receiving some sell limit orders 19 2.8 Matching buy limit orders 20 2.9 Matching buy limit orders, case A 21 2.10 Matching buy limit orders, case B 22 2.11 Matching sell limit orders 23 2.12 Matching sell limit orders, case A 24 2.13 Matching sell limit orders, case B 25 2.14 Right side of the order book is empty 26 2.15 Left side of the order book is empty 27 3.1 Submitting some buy market orders 33 3.2 Submitting some buy market and limit orders 34 3.3 Submitting some sell market orders 35 3.4 Submitting some sell market and limit orders 36 4.1 Typical fundamental value path 44 4.2 Order book at the end 45 4.3 Average order book 46 4.4 Volatility and trading volume 47 4.5 Price and volume 48 4.6 Volatility and cumulative spread 49 4.7 Price and bid and ask spread 50 4.8 Volatility and return 51 4.9 Volatility and Number of Orders 52 4.10 Dependence on the market activity A 54 4.11 Dependence on the tick size A 55 4.12 Dependence on the time horizon h 56 vi List of Figures 4.13 Effects of Chartists 58 4.14 Return distribution 59 4.15 Return distribution 60 4.16 Normal plot of the return 1 61 4.17 Normal plot of the return 2 62 4.18 Tail of the return distribution 1 64 4.19 Tail of the return distribution 2 65 4.20 Tail of the return distribution for different values of r 66 4.21 Tail of the return distribution for different values of r 67 4.22 Returns distribution with different values of T 68 4.23 The price stationary distribution 70 4.24 Returns stationary distribution 71 Acknowledgements I want to thank Dr. Rachel Kuske for all her time and encouragement. I also want to thank Dr. Ulrich Horst for the idea of this project, his time and his patience. I also want to thank my friend and colleague Terry Soo for teaching me how to use Latex. Finally, I give a special thanks to my wife Tracey, for her support throughout my entire master program. viii A mes parents ix C h a p t e r 1 Introduction The study of financial markets has interested many researchers since the very beginning of their existence. Many different approaches have been used on the road to a better understanding of the financial markets. Among them are the use of statistical techniques for both description and prediction of financial data and the creation of theoretical models with the hope to explain some of the phenomena found in these data. Other types of models try to link the financial market with general economic theory. More recently, some more sophisticated mathematical models have emerged from the field of mathematical finance. The goal of this thesis is the study of financial markets using multiple approaches. More precisely, we start with a mathematical theoretical model, make the link between this model and important concepts of economic theory, modify the model to take into account a particular form of financial market microstructure, use computer simulation to get intuition about the model and use statistical methods to find relations between different variables. Finally, we use statistical methods to compare our results with other results previously found in the empirical literature. 1.1 Review of Literature Our study of financial markets or asset pricing models, as sometimes called in the literature, brings us back to the seminal paper of Merton (1973). Merton's model is include in the broader theory of general equilibrium under uncertainty. 1 In these models, all agents solve an optimal investment problem and the equilibrium price of the asset is determined using a market clearing condition of zero excess demand. After the publication of Merton's paper, the influential model of Breeden (1979), known as the consumption based capital asset pricing model (CCAPM), appeared. This author develops the previous model further by also considering the consumption in the optimization problem. The importance of Breeden's model relies on the fact that his model can be empirically tested. This great characteristic of Breeden's model allowed many researchers to test the C C A P M empirically and concluded that it does not agree with the empirical financial data. In particular, these tests brought a considerable number of finanical puzzles: equity premium puzzle, volatility ' For a complete presentation of the theory of general equilibrium we refer the reader to the book of Mas-Colell, Whinston and Green (1995). 1 Chapter 1. Introduction puzzle, risk free rate puzzle, temporal predictability puzzle, etc. This disagreement with the data has encouraged the fast development of extensions of the model within the last 28 years. An extensive listing of all the developments done during these years is too long and not the main goal of this thesis. We mention here only some of the different directions that the researchers took in extending the CCAPM. These extensions were made by considering: borrowing constraints, short selling constraints, incomplete markets, production economy, information, habits, transaction costs, taxes, etc. 3 The general problem of all these models is that the equilibrium is found by considering a representative agent. As noted by many authors, models with representative agents have poor predictive power (in particular, see Meese and Rogoff (1983), Frankel and Rose (1995) and Cheung et al. (2002)). Moreover, an empirical study by Chinois and MacDonald (2002) suggests that there is considerable heterogeneity of expectations within the different agents acting on a financial market. Heterogeneous expectations are also necessary to explain other phenomena as pointed out by Bachetta and Wincoop (2005). For these different reasons, we need to introduce models that do not assume a representative agent, or more precisely, that consider agents with heterogeneous expectations. One of the difficulties of such models is that once we introduce heterogeneous expec-tations, we need to have another theory beside the usual rational expectation equilibrium. At this point, different options are available. Some authors have introduced agents with wrong expectations (see De Long et al. 1989 and 1990), other have use dispersed infor-mation models with higher order expectations (see Townsend (1983)) while finally some suggest that a unique stationary distribution for the price process can be considered as the proper equilibrium notion in such model ( see Follmer, Horst and Kirman (2005)). Within these directions we have decided to retain the one by Follmer, Horst and Kirman (2005). The reason being that even when really sophisticated, the other models need to assume some irrationality from the agent to obtain interesting results. As an example, assuming irrationality is necessary to reproduce typical characteristics of financial time series such as bubbles and crashes. In particular, when bubbles happen in these models they usually explode, which is not the case in the model by Follmer, Horst and Kirman (2005). In their paper, Follmer, Horst and Kirman (2005) present a model where agents have heterogeneous expectations and choose the expected price for the next period by comparing a performance measure given by some financial experts. To be more precise, as mentioned by the authors: "The aim of their paper is to analyze a model in which: • expectations can be heterogeneous, consistent with empirical observations, 2 For a good review of the empirical tests and implications of the C C P A M we refer the reader to Campbell, Lo, and MacKinlar (199G) and Cochrane (2001). 3 A precise explanation of these extensions as well as listing of references can be found in a combination of books on financial economics. In particular, we suggest: Merton (1992), Campbell, Lo, and MacKinlar (1996), Collier (2001), Duffle (2001), Cvitanic and Zapatero (2004). 2 Chapter 1. Introduction • where agents learn from their experience of using different rules, how to form their expectations, • where agents are not systematically wrong, • and where significant departures from fundamentals can occur but where there is al-ways a return to fundamentals." Our model shares a considerable part of the model of Follmer, Horst and Kirman (2005) and for this reason, we explain in more details in the section 1.2 the results of their paper and give a similar presentation of their model in chapter 3. In fact, this thesis constitutes an extension of Follmer, Horst and Kirman (2005) where we consider a different market organization. The market organization constitutes a subdivision of a wider topic called market mi-crostructure. Definition 1.1. The market microstructure is the study of the process by which invertors demands are ultimately translated into prices and volumes. A central idea of theory of market microstructure is that prices do not need to be equal full-information expectations of values. Important literature about market microstructure is surveyed in a paper by Madhavan (2000). The particular market organization considered in this thesis is the continuous double auction. An introduction to such market organization is given by Luckock (2003). Indeed, one could resume the principal aim of this thesis as being the same as Follmer, Horst and Kirman (2005) but considered in the double auction market organization instead of the Walrasian temporary equilibrium framework. Obviously the current work is less ambitious because we consider numerical simulations instead of rigorous mathematical analysis. We have presented in this section a broader view of the position of this thesis with respect to some of the relevant literature. In the next section we will present in more detail some previous work that is considered particularly relevant for this thesis. 1.2 Details of the Most Relevant Literature In this section we review in more detail a select portion of the literature that we consider as particularly relevant for the current work. To be more precise, we review the papers of Follmer, Horst and Kirman (2005), Chiarella and Iori (2004) and Luckock(2003). It is an important section because it will allow the reader to understand clearly the next section where we explain the relevance of this thesis. 3 Chapter 1. Introduction 1.2.1 Models of Continuous Double Auction In this section we present two particular models of continuous double auction. The model of Chiarella and Iori (2002 and 2004) and the model of Luckock(2003) because they both share similarity with our model. The model introduced by Chiarella and Iori (2002 and 2004) is to some extent very similar to the model introduced here. They introduce an order based market model with heterogeneous agents that submit market or limit orders according to exogenously fixed rules. We give here a brief description of their model. The orders arrive sequentially at random times and have a finite lifetime r. The asset is assumed to have a fundamental value pi which is constant and known by all the agents. The agents can submit limit orders at any price on a prespecified grid. The demand of each agent consists of three components, a fundamentalist component, a chartist component and a noise component. At time t, the agent, makes an expectation about the spot return, fI t + T that will prevail on the interval (t, t + r) during which her order will be active. Mathematically, f\ t + T is given by: 1 •g{L(pLzP*l + ^ L i + niet (1.2) where rLi is an average of past returns, g\ is the weight given to the fundamentalist, g\ is the weight given to the chartists and n ~ A/"(0, crn) and Ct ~ A/"(0, o~c). The agent can choose between holding cash or stock. The authors assume the agents to have exponential utility function given by: U{W) = -e-°w (1.3) where W is the wealth of the agent. Then, the optimal composition of the portfolio is given by: if \ log(pi i + T0 - log(p) alatp where at is the variance of returns. Restrictions are added on 7r(p) to avoid short selling. Discussion 1.5. One of the differences with our model is that their model does not include a self-reinforcing term. The weight given to the fundamentalist g\ and the weight given to the chartist g\ vary randomly with time. This implies that the choice of the agent to use more a fundamentalist rule or a chartist rule is independent of the performance of the rules. As a result, an agent can decide randomly to use a more fundamentalist rule even if this rule performed poorly in the past. This assumption is relaxed in our model presented in section 3. Another problem, as mentioned by the authors themselves, is that the model abstracts from important informational issues by assuming that agents have full knowledge of the 4 Chapter 1. Introduction market fundamental. Not only do the agents have full knowledge of this value but it is also considered as constant. As noted by De Long et al. (1990) different types of risks are present in financial markets, in particular, there is risk coming from the uncertainty of the fundamental value and there is risk coming from noise trading. Our model relaxes these different assumptions of the model developed in Chiarella and lori (2002 and 2004) by assuming that the agents do not know the fundamental value and that this value is not a constant. The paper by Luckock (2003) is important for the presentation of the continuous double auction market organization and for some similar results than the one obtain in this thesis. In particular, the author found steady state distributions for the best ask, the best bid and the transaction prices and under fairly general assumptions that the prices are confined to a clearly defined window. Discussion 1.6. Even if the results obtained in this paper are interesting, there are some problems with some of the assumptions used. In particular, the author assumes: • All orders are for a single unit, • the underlying supply and demand functions are time independent during the period of interest, • the cancellation rate of unexecuted orders is negligible during the period of interest It is obvious that the first two assumptions are not true in reality. The third assumption is not good because as mentioned by several authors order cancellation is wide spread in financial markets.4 We have decided to relax these three assumptions in our model. Finally, it is worth mentioning that while the model by Chiarella and lori (2002 and 2004) rnay seems more complete than the one of Luckock (2003), their model is based on numerical simulation while the one of Luckock (2003) is based on rigorous mathematical analysis. This completes the presentation of the two other models of continuous double auction. In the next section we present a more theoretical part of the literature. 1.2.2 Financial Market with Heterogeneous Agents We present here a brief description of the model presented by Follmer, Horst and Kirman (2005) and a part of the theory related to this model. These authors analyze a model with many heterogeneous agents acting on a financial market with one single asset. The model is considered in the Walrasian temporary equilibrium framework. At time t, in reaction to a price p, the agents form their random excess demand, e"(p, ui). The excess demand can be divided in two parts, the first part consists of a comparison, on ''See Bouehaud and Potters (2003), Coppcjans and Domowithz (1999), Challet and Stichcombe(2001). 5 Chapter 1. Introduction a logarithmic level, of the difference between the the suggested price p and a reference level price St(ui) the second part consists of a random liquidity demand r)t(w). The reference level is given to the agent by a financial expert i el. Each agent chooses this financial expert evaluating a discounted sum of past profits their recommendation would have produced in the past. The recommendation of the financial expert depends on the expert type. They distinguish two types of experts, fundamentalist and chartist. The fundamentalist believes that the price will eventually revert to a fundamental value while the chartists are using extrapolatory rules to make their recommendation. The actual asset price at time i, denoted Pt, is then determined via the market clearing condition of zero net excess demand: £ e ? ( P t M , w ) = 0 (1.7) agA where A is a finite set of economic agents. At this point, we will ignore some details and notation in order to arrive to the more theoretical results. Having this in mind, the dynamic sequence of temporary logarithmic price equilibria is governed by an equation of the following form: St = F(St-i,St-2,Tt) := [1 - at + pt]St-i - PtSt-2 + Ft + m (1.8) in a random environment described by the sequence n ••= (xt,it,vt) (1-9) where 7t := ((c")aeAi (ah Pt)i€h (-F?)iel)- This environment summarizes the stochastic evo-lution °f the agents' choices, the experts' and the agents' profiles as described by the process {7t}teNi a n d t n e noise trading {?7t}teN-After introducing the definition of the performance process { £ / t } t e N we can view the logarithmic price process as the first component of the Markov chain: Zt:=(St-i,St-2,Ut) (1.10) with state space E := K M + 2 . Now the goal of the rest of their paper is to prove the existence and uniqueness of a stationary distribution of the Markov chain As mentioned by the authors, the uniqueness of this distribution will imply that the Markov chain is ergodic. To conclude this section, we recall the definition of stationary distribution and of er-godicity given by the authors and then we state the two main results from this paper. Definition 1.11. A probability measure p. is a stationary distribution for the price-performance process if ^ ^1 = p. In this case, the sequence { £ } t e N is stationary under the law P„(-) := / PC(>(#)- (1-12) JE 6 Chapter 1. Introduction Definition 1.13. A Markov chain {£,}tefi is ergodic if time averages converge to expecta-tions under the unique stationary distribution fi, i.e., T—i lim i £ = I f(OlM(d£), ^ - (1-14) and hence — a.s. for /v, — a.e. initial state £ S E. Theorem 1.15. Under some technical assumptions, 5 the Markov chain {Qtzn has an invariant distribution. While the detail assumption can be found in the paper directly, we still want to point out that the theorem 1.15 holds under the assumption that the proportion of chartists is bounded from above. It is this particular assumption that insured that the bubbles and crashes that occur do not explode. Theorem 1.16. Under some technical assumptions, 6 the Markov chain {£}teN r i a s a unique stationary distribution n, and T—l T~*°° T ^ J for all bounded continuous functions f and each initial state £ € E. The proof of the theorem 1.15 relies on a contraction property while the proof of theorem 1.16 is much more involved and requires the comparison of the price-performance process with a process whose convergence can be established using standard argument of the theory of iterated function systems. 7 This completes the short presentation of the results obtained by Follmer, Horst and Kirman (2005). At this point, we want to bring to attention the fact that this presentation is far from complete and that the interested reader should consult the paper for more details. In the next section, we present the reasons why we believe that this thesis is relevant. 1.3 Relevance of this Thesis We present here the reasons why we believe that this thesis constitutes a relevant work. ''The precise assumptions are given in Follmer, Horst and Kirman (2005) by assumption 2.9, 2,10 and 3.1 respectively. In particular, the assumption 3.1 imposes a quantitative bound on the impact of the chartist. f'The precise assumptions are given in Follmer, Horst and Kirman (2005) in assumption 2.9, 3.1 and 3.5 respectively. ' A part of the theory of iterated function systems is presented in the paper by Steinsaltz (1999). 7 Chapter 1. Introduction First, we have presented in the section 1.2 some of the limitations of models consider-ing a representative agent. We have also discussed the problems occurring in some models where agents have heterogeneous expectations. In particular, we recall that most of the models need to assume irrationality from the agents to obtain interesting results. The model of Follmer, Horst and Kirman (2005) resolved most of these limitations and prob-lems. Nevertheless, these authors consider a model in the Walrasian temporary equilibrium framework and as they mention themselves, it would be interesting to consider different market organizations. Second, to some extent, this is done by the two models of Chiarella and Iori (2002 and 2004) and Luckock (2003) by considering heterogeneous agents in a continuous double auction market organization. On the other hand, these models use different assumptions than our model, as mentioned in discussions 1.5 and 1.6 respectively. This is where the present work becomes important. In here, we consider an application of the model of Follmer, Horst and Kirman (2005) to the continuous double auction framework that use different assumptions that the one given in discussions 1.5 and 1.6. Third, this thesis does not only apply the model of Follmer, Horst and Kirman (2005) to the continuous double auction framework but also extends greatly the numerical simulation of such a model. In particular, we provide a wider range of numerical results than the one given by these authors. We also try to compare these results with some of the empirical results of the literature. Finally, we believe that the presentation of the continuous double auction and order book dynamics given in the chapter 2 constitutes by itself a good reason for the relevance of this thesis. To our knowledge, the graphical approach used makes the explanations more clear than in the previous works on the subject. 1.4 Outline of the Thesis The structure of the thesis is as follow. In chapter 2 we introduce the different concepts related to the continuous double auction and the order book dynamics. Several definitions are first presented in section 2.1 and then the different rules governing the order book are illustrated through numerous graphical examples in section 2.2. Chapter 3 is the core of the thesis and explains in details the financial market model considered. Section 3.2 presents how the different agents presented in this market take their decisions. Section 3.3 presents the three types of financial experts and shows how these experts choose their recommen-dation level. Section 3.4 presents the link between the agents and the financial experts through the performance measure process. This process is usedby the agents to determine from which expert they will choose their reference level. Finally, section 3.5 presents a short algorithm to understand the different steps done by the market participants. In chapter 4 we present the different details related with the computer simulation. Section 4.1 presents the setting of the different parameters for the simulation. Section 4.2 presents the different 8 Chapter 1. Introduction results obtained by the computer simulations. Finally, chapter 5 presents the conclusion of the thesis. Section 5.1 presents a summary of our model, the different assumptions, the goals and the techniques used in this thesis. Section 5.2 presents the conclusions of the thesis. Finally, section 5.3 presents the different directions further research on this topic can take. 9 Chapter 2 Order Book Dynamics In this chapter, we explain how the continuous double auction and the order book work. This is a really important chapter because it will explain how the prices are determined in these sort of market mechanisms. It is also relevant because all the concepts presented here are necessary for the creation of the computer simulation. In section 2.1 we introduce the concept of continuous double auction and other important definitions. In the section 2.2 we present the different rules governing the order book dynamics. In all the situations, we have decided to use graphical examples to illustrate clearly the different rules and mechanisms that occurs in these markets. 2.1 Continuous Double Auction and Definitions In this section, we first introduce the concept of continuous double auction, referred as (CDA) and some definitions closely related to this concept. The next definition is from Luckock (2003). Definition 2.1. A continuous double auction, denoted (CDA), is a continously operating market for goods in which both buyers and sellers can announce offers to trade specified quantities at specified prices, a,nd can also initiate trades by accepting such offers. Here are the main differences between the CDA and a normal auction. First, in a CDA, both the buyers and sellers can announce offers and this is where the terminology double comes from. Second, the term continuous refers to the fact that this system allows trading at any point in time while the market is open. Some markets only allow trading at specific points in time and accordingly, they are not considered as being continuous. As mentioned by Luckock (2003), the importance of the CDA mechanism relies on the fact that it is the basis of nearly all the automated trading systems that have been implemented in modern financial markets over the last 2 decades. For example, Paris, Tokyo, Toronto, Hong Kong, Sydney, Mumbai and Stockholm exchanges function as a continuous double auction. Another important point is that the CDA has been found in laboratory experiments to give a very rapid convergence to a competitive equilibrium and also to yield extremely efficient allocation as noted by Smith (1962), Smith et al. (1982) and Friedman (1993).8 8 F o r morn details about the theory on competitive equil ibrium and efficient allocations, wo refer the reader to Mas-Cole l l , Whins ton and Green (1995). 10 Chapter 2. Order Book Dynamics Definition 2.2. Any buyers or sellers that operate in the CDA will be called an agent. Definition 2.3. An order is a request given to someone or to an electronic system, to execute a certain task. Definition 2.4. The order size is the number of units contained in the order request. The most common example of a task to be executed is a request to buy or to sell a specified quantity of a specified good at a specified price. For example, we can think of a buy order of size four for an IBM stock. This is a request to buy four stocks of IBM. These definitions will become clear after the introduction of more precise examples. There are many different versions of CDA and each of them is characterize by the types of orders that may be submitted: market order, limit order, stop-loss order, stop-limit order, market-if-touch order, etc. 9 The interesting reader can consult the chapter 2 of Hull (2006) for a full description of all these types of order. In practice, most of the automated systems operate as limit order markets and accepts both market and limit orders. These are the two types of order that we consider in our model. Definition 2.5. A market order is a request that a trade be executed at the best price available. There are two types of market orders, a buy market order and a sell market order. Definition 2.6. A buy market order of size n is a request to buy the specified quantity n of a specified good at the best sell price available. Definition 2.7. A sell market order of size n is a request to sell the specified quantity n of a specified good at the best buy price available. Definition 2.8. A limit order is a request that a trade be executed at a specified or a more favorable price. The meaning of a more favorable price will become clear in the next two definitions. There are two types of limit orders, buy limit order and sell limit order. Definition 2.9. A buy limit order of size n is a request to buy the specified quantity n of a specified good at a specified price b or at a lower price than b, in which case this price is considered as being a more favorable price. Definition 2.10. A sell limit order of size n is a request to sell the specified quantity n of a specified good at a specified price a or at a higher price than a, in which case this is considered as being a more favorable price. 9 The interested reader can consult the chapter 2 of Hull (2006) for a complete description of all these types of orders. 11 Chapter 2. Order Book Dynamics While the market orders are generally executed immediately, there is nothing that guar-antees that it is the case for the limit orders. As an example, a buy limit order of price 4 cannot be executed if the best sell price available is 6. As a consequence, the limit orders need to be stored in an order book. For the market orders, any unexecuted part may be converted in a limit order at the same price (Paris bourse) or else executed at the next best available price (as on the Australian Stock Exchange). 1 0 Indeed formally we have the following definition. Definition 2.11. An order book is a system in which unexecuted or partially executed orders are stored and sometime displayed until their execution or their cancellation. Discussion 2.12. We note that the question about which part of the order book or if the order book should be displayed is in itself of entire field of research. We also want to point out the difference between the CDA and the order book. The CD A is a type of market organization or market microstructure while the order book is a system used to store the unexecuted or partially executed orders. In the next few paragraphs we start using a more graphical approach that will help clarify the different concepts. In particular, we can use a graphical approach to represent and get some intuition about the order book. This is done in Figure 2.1. Discussion 2.13. At this point, it is important to note that the different graphics presented in this section are only to make easier the exposition of the different concepts. The graphics presenting the simulation results will be more realistic in term of the different values of the parameters. l 0Thc interested reader is referred to Luckock (2003) for a more precise discussion about the difference between these two exchange platforms. 12 Chapter 2. Order Book Dynamics Order Book Representation S2 4 o e 2 2 buy limit orders sell limit orders 7 Price 10 11 12 13 Figure 2.1: Order book representation A less natural but more useful way to represent the order book is to place the buy limit orders on the negative part of the y axis. This technique allows us to see clearly the difference between the buy and sell limit orders as shown in Figure 2.2. 13 Chapter 2. Order Book Dynamics Order Book Representation buy limit orders i n " . u u -1 sell limit orders i i • i • i • 1 2 3 4 5 6 7 8 9 10 11 12 13 Figure 2.2: Second order book representation We are now ready for the introduction of other important concepts. Definition 2.14. The best bid price at time t, denoted bt, is the higher price for which there is buy limit orders currently stored in the order book. Definition 2.15. The best ask price at time t, denoted at, is the lowest price for which there are sell limit orders currently stored in the order book. Definition 2.16. The bid and ask spread at time t, denoted qt, is the difference between the best, ask price and the best bid price when they are both different from zero or is set to zero otherwise. Mathematically, it is given by the following formula: _ ( at-bt ifat^0 and bt ^ 0 , . ^ \ 0 otherwise Definition 2.18. The middle point of the order book at time t, denoted mt, is given by: mt = {at + bt)/2. (2.19) These different concepts are shown in Figure 2.3. 14 Chapter 2. Order Book Dynamics Figure 2.3: Best bid, best ask, spread and middle Discussion 2 . 2 0 . Here it is interesting to note that most of the mathematical finance theories assume that the bid and ask spread is actually zero, meaning that you can always buy and sell at the same price (see Shreve (2000a) , Shreve (2000b), Duffie (2001) and Cvitanic and Zapatero (2004))- This assumption is never true in reality and can even be totally wrong for some particular stock. It is these types of frictions that are usually taken into account in the study of market microstructure. Definition 2 . 2 1 . Two orders of different sign, i.e. a sell order and a buy order, are executed against each other when they have the same price. This simply means that one person wants to buy at the same price that another one wants to sell and so the two orders cancel each other and a transaction occurs. For this reason, we say that the orders are executed with orders of opposite signs. This complete the section about the CDA. In the next section we present the details of order book dynamics. 2.2 Order Book Dynamics In this section we present and explain the different rules that governed the order book. At the same time, because in a limit order market, the price is determined by the interaction of the incoming orders with the orders already in the book we also explain the price 15 Chapter 2. Order Book Dynamics modification mechanism. We have separated this section in several subsections each of them explaining properly a particular case. 2.2.1 Case 1 The first situation is when a market order of size n is received and that the number of orders available at the best price p is m > n. In this case, the number of orders available at the price p simply becomes m — n and the current price pt is set to the price of the last transaction p, i.e, pt = p. We present an example of this case in Figure 2.4. Order Book Before the Modification Order Book After the Modification -1 1 1 r-A buy market v order of size 2 \ arrives b =6 t-1 best ^available price p = 8 1 2 3 4 5 6 7 8 9 10111213 Price 1 2 3 4 5 6 7 8 9 10111213 Price Figure 2.4: Receiving some market orders. The best ask price is at-\ = 8. There are 6 sell limit orders available at this price. A buy market order of size 2 arrives. It is executed against sell limit orders at the best ask cit-i = 8. The number of limit orders available at this price becomes 6 — 2 = 4. A transaction have occurred and the current price is modified accordingly, pt = 8. The best bid price and best ask price remain unchanged. 16 Chapter 2. Order Book Dynamics 2.2.2 Case 2 A market order of size n is received and the number of orders available at the best price p is m < n. In this case, we follow the Australian Stock Exchange mechanism, the unexecuted part will be executed at the next best available price. If there is not enough orders stored at this new best price, the reminder are executed at the next best available price and so on until the market order is completely executed. The current price will be the price of the last transaction. We present an example of this case in Figure 2.5. Order Book Before the Modification 7 I 1 1 i i 1 1 1 1 1 1 1 r Order Book After the Modification A sell market order of size 4 arrives last transaction price is 5 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 Price b M = 6 b=5 p( = price of the last transaction = 5 1 2 3 4 5 6 7 8 9 10111213 Price Figure 2.5: Receiving some market orders. The best bid price is bt-i = 6. There are 3 buy limit orders available at this price. A sell market order of size 4 arrives. Three orders are executed against buy limit orders at the best bid bt-i = 6. The number of limit orders available at this price becomes 3 — 3 = 0. The rest of the order is executed at the next best price available 5. A transaction have occurred and the current price is modified to the price of the last transaction, p< = 5. The best bid price is modified from bt-\ = 6 to bt = 5. The best ask price remain unchanged. 17 Chapter 2. Order Book Dynamics 2.2.3 Case 3 A buy limit order of size n and a price b < at (best ask price) is submitted. In this case, these buy orders are stored in the book at the price b and the price does not change because there is no transaction, i.e., pt = Pt-i- We present an example of this case in Figure 2.6. Order Book Before the Modification Order Book After the Modification — i — i — i — i — i — a M = 8 _J I I I I I 1 I I I I L_ 2 3 4 5 6 7 8 9 10111213 Price l 3 •Q A •o S 5 t-1 \ A buy limit ' o r d e r of size 4 and price 6 arrives 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 Price Figure 2.6: Receiving some buy limit orders. A buy limit order of size 4 and price 6 arrives. The number of order at this price becomes 0 + 4 = 4. The best bid price is modified from bt-i = 5 to bi. = 6. Discussion 2.22. It is important to note that, as in the previous example, the best bid price or the best ask price can change even when no transaction occurs. Because the best bid and best ask are usually displayed, this conveys some information to the agents. 18 Chapter 2, Order Book Dynamics 2.2.4 Case 4 A sell limit order of size n and a price a > bt (best bid price) is received. In this case, these sell limit orders are stored in the book at the price a and the price does not change, i.e., pt = pt-i- We present an example of this case in Figure 2.7. Order Book Before the Modification 6 5 4 3r 2 11 0 1 2 3 4 5 6 7 b,-r 6 -_j i i i i i i i i i i_ a) 6 "p 2 3 4 5 6 7 8 9 10111213 Price Order Book After the Modification — i — — i 1 1 r — i 1 1 1 1 1 1 1— A sell limit order of size 2 I and <^ J price N. I 7 arrives -b = 6 1 2 3 4 5 6 7 8 9 10111213 Price Figure 2.7: Receiving some sell limit orders. A sell limit order of size 2 and price 7 arrives. The number of orders at this price becomes 3 + 2 = 5. The best bid price and best ask price remain unchanged. 19 Chapter 2. Order Book Dynamics 2.2.5 Case 5 A buy limit order of size n and price b > at is received. If the number of sell limit order at price at, denoted m, is bigger or equal to n (if m > n) then the buy limit orders are executed against the sell limit orders as if they were buy market orders and the price becomes pt = at- We present an example of this case in Figure 2.8. Order Book Before the Modification Order Book After the Modification 1 2 3 4 5 6 7 8 9 10111213 Price 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 Price Figure 2.8: Matching buy limit orders. A buy limit order of size 4 and price b = 9 > at.-\ = 7 arrives. The number of order at the price at-i = 8 becomes 5 — 4 = 1. A transaction has occurred and the current price is modified accordingly, p/, = 7. The best bid price and best ask price remain unchanged. Discussion 2.23. It is important to note that the buy limit order of price b is not executed against sell limit order at this price. This is the meaning of best available price in the definition of limit order. Now if we are in the other situation, i.e., m < n then m buy limit orders are executed against sell limit orders at price at and the remaining (n — m) buy limit orders are either executed at the next best available price a if b > a (case A) or they are stored in the book 20 Chapter 2. Order Book Dynamics at the price b if b < a (case B ) . If b > a the price becomes pt = a. If b < at the price is the price of the last transaction. Once again, all this is made more clear wi th a graphical representation. W e present the case A in F igure 2.9 and the case B in Figure 2.10. F igure 2.9: M a t c h i n g b u y l imit orders, case A . T h e best ask price is at-i — 7. T h e r e are 2 sell l imit orders available at this price. A buy l imit order of size 5 and price 6 = 8 arrives. T w o orders are executed against sell l imit orders at the best ask a j _ i = 7. T h e number of l imit orders available at this price becomes 2 — 2 = 0. Because b > a the next best available price, the rest of the order is executed at the next best price available 8. A transaction has occurred and the current price is modified to the price of the last transaction, pt = 8. T h e best ask price is modified from at-i = 7 to at = 8. T h e best b id price remain unchanged. 21 Chapter 2. Order Book Dynamics Order Book Before the Modification Order Book After the Modification * 3 A buy limit order of size 5 and price b arrives o 2 3^ -Q 5 The part of the order not executed is placed in the book at price b 1 2 3 4 5 6 7 8 9 10111213 Price 1 2 3 4 5 6 7 8 9 10111213 Price Figure 2.10: Matching buy limit orders, case B. The best ask price is at-i = 8. There are 3 sell limit orders available at this price. A buy limit order of size 5 and price 6 = 8 arrives. Three orders are executed against sell limit orders at the best ask at~i = 8. The number of limit, orders available at this price becomes 3 — 3 = 0. A transaction has occurred and the current price is modified to the price of the last transaction, pt = 8. Because b < a, a buy limit order of size 5 — 3 = 2 and price b = 8 is placed. The best ask price is modified from at_i = 8 to at = 9. The best bid price is modified from bt-\ = 5 to bt = 8. 22 Chapter 2. Order Book Dynamics By symmetry we obtain the same situation for the sell order. A sell limit order of size n and price a < bt is received. If the number of buy limit orders at price bt, denoted m, is bigger or equal to n (if m > n) then the sell limit orders are executed against the buy limit orders as if they were sell market orders and the price becomes pt = h. We present an example of this case in Figure 2.11. Order Book Before the Modification Order Book After the Modification 1 2 3 4 5 6 7 8 9 10111213 Price 6 7 8 9 10111213 Price Figure 2.11: Matching sell limit orders. A sell limit order of size 3 and price a = 6 < 6^-1 = 6 arrives. The number of orders at the price bt-\ = 6 becomes 4 — 3 = 1. A transaction has occurred and the current price is modified accordingly, pt = 6. The best bid price and best ask price remain unchanged. 23 Chapter 2. Order Book Dynamics The earlier discussion about the best available price is also applied in the present case. Now if the number of buy limit orders at price bt is smaller than n (if m < n), then m sell limit orders are executed against buy limit orders at price bt and the remaining (n — m) sell limit orders are either executed at the next best available price b if a < b (case A) in which case the price is set to the price of the last transaction. Or they are stored in the book if a > b (case B) and the price becomes pt = b. We present the case A in Figure 2.12 and the case B in Figure 2.13. Order Book Before the Modification 1 2 3 4 5 6 7 8 9 10111213 Price Order Book After the Modification 1 2 3 4 5 6 7 8 9 10111213 Price Figure 2.12: Matching sell limit orders, case A. The best bid price is bt-\ = 6. There are 4 buy limit orders available at this price. A sell limit order of size 6 and price a = 4 arrives. Four orders are executed against buy limit orders at the best bid bt-i = 6. The number of limit orders available at this price becomes 4 — 4 = 0. Because a < b the next best available price, the rest of the order is executed at the next best price available 5. A transaction has occurred and the current price is modified to the price of the last transaction, pt = 5. The best bid price is modified from bt-i = 6 to bt = 5. The best ask price remain unchanged. 24 Chapter 2. Order Book Dynamics Order Book Before the Modification Order Book After the Modification A sell limit order of size 6 and price a arrives 1 2 3 4 5 6 7 8 9 10111213 Price —i—i—i—i—i—i—i—i—i—i—i—i—i— The part of the order not executed is placed in the book at price a b = 5^ p = b = 6 ' • ' I • 1 I ' 1 I I I 1_ 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 Price Figure 2.13: Matching sell limit orders, case B. The bid ask price is bt-i = 6. There are 4 buy limit orders available at this price. A sell limit order of size 6 and price a = 6 arrives. Four orders are executed against sell limit orders at the best bid bt-i = 6. The number of limit orders available at this price becomes 4 — 4 = 0. A transaction has occurred and the current price is modified to the price of the last transaction, pt = 6. Because a > b, a sell limit order of size 5 — 4 = 2 and price a = 6 is placed. The best, bid price is modified from bt-i = 6 to bt = 5. The best ask price is modified from oi_i = 7 to at = 6. Discussion 2.24. The attentive reader will have noticed that we have avoided speaking about a particular case so far and it is the case when some market orders of size n arrived and n is bigger than the number of limit orders fn of the opposite type in the book. This case is really important because it will require us to be really careful in the construction of the numerical simulation. Moreover, other authors usually avoid clear explanation of what happens in this case, (see Luckock (2003), Chiarella and Iori (2002) and Chiarella and Iori (200^)). We present this case in the next two subsections. 25 Chapter 2. Order Book Dynamics 2.2.6 Case 6 A buy market order of size n is received and the total number of sell limit order in the book rh is smaller (m < n). In this case, m buy market orders are executed against the m sell limit orders. The (n — m) remaining buy market orders are converted in a buy limit order of size (n — m) at the last price for which sell limit orders were available a. The price is set to the price of the last transaction, pt = a. This case is shown in Figure 2.14. Order Book Before the Modification Order Book After the Modification 1 2 3 4 5 6 7 8 9 10111213 Price 2 3 4 5 6 7 8 9 10111213 Price Figure 2.14: Right side of the order book is empty. A buy market order of size 9 arrives. The total number of sell limit order available in the book m = 7. Seven buy market orders are executed against the sell limit orders in the book and the total number of sell limit orders in the book becomes rh — 0. The price is modified to the price of the last transaction pt = 9. The remaining market order are converted in a buy limit order of size 9 — 7 = 2 at the last transaction price 5 = 9. The best ask price at = 0 and using equation 2.17 the spread becomes qt = 0. 26 Chapter 2. Order Book Dynamics 2.2.7 Case 7. A sell market order of size n is received and the total number of buy limit orders in the book TO is smaller than n (TO < n). In this case, TO sell market orders are executed against the TO buy limit orders. The (n — m) remaining sell market orders are converted in a sell limit order of size (n — TO) at the last price for which buy limit orders were available 6. The price is set to the price of the last transaction, pt = 6. This case is shown in Figure 2.15 Order Book Before the Modification Order Book After the Modification A sell market order of size 9 arrives _J I I I I I I I I L_ 1 2 3 4 5 6 7 8 9 10111213 Price o 2 -Q A <s> 5 1 = —i—i—i— The part of the order not executed is place in the book_at price b n = a = 4 Kt t The spread q ( is set to zero 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 Price Figure 2.15: Left side of the order book is empty. A sell market order of size 9 arrives. The total number of buy limit order available in the book m = 6. Six sell market orders arc executed against the buy limit orders in the book and the total number of buy limit orders in the book becomes TO = 0. The price is modified to the price of the last transaction Pt = 4. The remaining market order are converted in a sell limit order of size 9 — 6 = 3 at the last transaction price 6 = 4. The best bid price becomes bt = 0 and using equation 2.17 the spread becomes qt =0. This concludes the chapter on the continuous double auction and the order book dy-namics. In this chapter we have introduced the different important concepts related to the C D A microstructure and explained through numerous graphics and examples the different 27 Chapter 2. Order Book Dynamics rules governing the order book dynamics. In the next chapter, we present the detailed description of our model. 28 C h a p t e r 3 The Model In this chapter we give a presentation of our model with the different market participants. While in the chapter 2 we gave the different rules that governed the order flow, we have omitted any explanations about who were submitting these orders and why. This is done in this chapter. The section 3.1 gives a concise description of our model without all the details. The section 3.2 explains how the agents take their decisions in our model and how we need to adjust the rules of the order book presented in the chapter 2 to fit our model. In section 3.3 we introduce the three types of financial experts and we explain how they choose their reference level at each period. Section 3.4 makes the link between the agents and the financial experts through the concept of performance measure. Finally, in section 3.5 we present a short algorithm to make the understanding of the whole model easier. 3.1 The Model in Brief In this section we present a concise description of our model without all the details. We consider a financial market with a single risky asset. There is a finite set A of economic agents trading on this market. The agents submit orders according to Poisson dynamics with constant rate /J,. The choice of the agent to submit buy or sell orders will be determined using her excess demand. The excess demand of each agent is based on two components, the comparison of the last price with a reference level and a exogenous random liquidity demand. There is a finite set I of financial expert each proposing a reference level for the next period. The agent's choice of a particular reference level will depend on a measure of the performance of the expert recommendation. Finally, the price is not a equilibrium price determined using a market clearing condition like in Follmer, Horst and Kirman (2005). The price is determined using the different rules that governed the order book as explained in chapter 2. This complete the brief and concise presentation of our model. In the next section we will explain in more details the different components of the agents excess demand and how the agent chooses between placing market or limit orders. 29 Chapter 3. The Model 3.2 The Agents This section follows closely the theoretical model given in Follmer, Horst and Kirman (2005). We consider the usual probability space framework, (fi, T, P). We consider a finite set of economic agents A = { 1 , 2 , N } . The financial market consist of a single risky asset with price at time t given by pt- At time t, each agent a G A forms an excess demand for the risky asset, denoted e"(pt_,w), where to represents a particular element of fl and where t— represents the time of the last transaction. 1 1 This excess demand will depend on an endogenous component which compares, on a logarithmic basis, the last price pt- and some reference level St and an exogenous component which consists of a random liquidity demand r^. The agents submit orders according to Poisson dynamics with constant rate \±. The excess demand of agent a G A is then determined via the following formula: e?(pt-,w) := c f M I ^ V ) - \og(pt-)) + V?H (3-1) where: • cf(u>) is non-negative, i.e., cf (w) > 0. This parameter represents the speed perceived by agent a G A at which the price will go back to the reference level, • St(u>) is the logarithmic reference level chosen for the time interval [£,*+]. This reference level is based on the recommendation ip\ of an expert i G I = {1,2,..., M} s t « H € { v ! M , ^ M , . . . , ^ H } (3.2) and • rft(w) is a exogenously determined random liquidity demand of agent a. Discussion 3.3. For the moment, we do not explain where the logarithmic reference level 5f(w) comes from nor how it is chosen by the agent. This will be done in Sections 3.3 with the description of the experts and 3-4 with the introduction of the concept of performance measure. Now after an agent is chosen and this agent a G A has determined the reference level she will follow, she needs to determine the sign of order she wants to place, a buy or a sell order, and the order size. These two decisions are determined directly using the excess demand ef(pt-,oj). The type of order depends on the sign of the excess demand, if ef(pt-,ijj) > 0 the agent submits a buy order while if ef(pt-, u) < 0 the agent submits a sell order. In the "Following this notation, t will represent the time of the second last transaction and t+ will represent the time of the next transaction. 30 Chapter 3. The Model case e"(pt_,w) = 0 the agent does not submit any order. The size of the order is simply given by the absolute value of the excess demand, which we denote £, i.e., C= \ ei(pt-,w) \ . (3.4) Discussion 3.5. There are two reasons why the random liquidity demand r)f(oj) is impor-tant. First, it serves as a sort of budget constraint for the agent when she is taking her investment decisions. Suppose for example that the term S"(w) — log(pj_) is positive which implies that the agent expects a price increase. Following this logic, the agent wants to buy some stock to profit from this expected price increase. Now suppose that the random liquidity demand is negative and that: I t fMI >c?( W )[S t a M-log( P i _)] (3.6) then the excess demand will be negative and the agent will sell some stock. Indeed, we are in a situation where the agent expects a price increase but still wants to sell the stock. It is for this reason that the random liquidity demand constitutes a sort of budget constraint. Second, as we will see later the random liquidity demand is also useful to represent the fact that an agent can follow a noise trader advice. This will happen when the reference level S"(w) and the price of the last time interval pt-(u>) are the same. This last statement will become clear in the next section where we describe the experts. Discussion 3.7. It is important to note that our model assumes implicitly that the agents are allowed to short sell the stock and that the agent does not have a borrowing constraint (other than the random liquidity demand). By short selling the stock, we mean selling the stock even if they do not hold it. This is another difference between our model and the model by Chiarella and Iori (2004) where the authors consider a model where short selling is not allowed. Which one of these two assumptions is the best is not clear, both assumptions can be considered as being unrealistic. At this point, the agent needs to decide if she will submit a market or a limit order. This is accomplished by comparing the best ask at or the best bid bt with the reserve price of the agent. This implicitly assumes that all the agents of our model always know the best bid price and the best ask price. In order to define the concept of reserve price properly we first need to introduce the following definition. Definition 3.8. The time horizon of an agent a S A, denoted ha, is the amount of time an agent will wait until she decides to cancel her unexecuted limit orders still in the order book. It is given by the following formula: h* + £ (3.9) where va > 0 is a constant and 7 A is the discount factor of agent a. 31 Chapter 3. The Model This means that at each time t, every agent that is active on this market will verify if she should cancel her limit orders in the order book or keep waiting. For this reason, the time horizon of an agent can be interpreted as her level of patience. We also note that if the discount factor of an agent 7" is increasing then the time horizon of this agent ha is decreasing which is consistent from an economic point of view. For simplicity of notation, we introduce the following variable: 5 t a := eS? (3.10) We recall that Sf is the logarithmic reference level chosen by the agent a € A for the time interval \t,t+] then, es° represent the actual price reference level for this time interval. Definition 3.11. The reserve price of an agent a £ A at time t, denoted Rf, is the price at which the agent is ready to sell or to buy the stock directly for the time interval [t,t+\. In other words, at this price, the agent submits a market order. It is mathematically given by the following formula: Ra,sell ga + for & ^ Q r d e r a n ( J Ra,buy ._ ga _ £ha fo]. & b u y o r d e r (3 where £ > 0 is constant. Discussion 3.14. The reserve price also influences how far from the middle of the order book the agent will place her limit order. This parameter needs to be related to the time horizon because as noted by Bouchaud and Potters (2003) the more patient agent will place her limit order further from the middle of the book because she is willing to wait a long time for her order to be executed.12 Indeed, if you are impatient it will not make sense to place a limit order far from the middle unless you are expecting a large price movement. Consequently, the position where the agents are placing their limit orders gives important information about the level of patience of the agents and their expected level of variability of the price process. It is important to note another difference with Chiarella and Iori (2004). In o u r model the reserve price Rf depends on the discount factor of agent a via the time horizon pa-rameter ha. This is not the case in the model of Chiarella and Iori (2004). In fact> these authors do not consider any discount factor in their model. Now we divide this section in two symmetrical sections where we take time to explain the mechanism of decision between market and limit orders for both the case of buy order and sell order. liA relation between order placement and patience is also discussed in Farmer and Zovko (2002). 32 Chapter 3. The Model 3.2.1 The Case of Buy Orders In this case, to decide which type of order the agent will submit we need to compare the value of the best ask at with the reserve price of the agent R^'buy. If R^'buy > at the agent is willing to pay more than at to obtain the stock and so she is submitting a buy market order. This order will be executed against the sell limit order at the price at as long as the size of the order ( ^ 0 or that R^'buy > at. If it happens that in the process of executing the order from the agent, i?"' b u y < at then because the best ask become bigger than the agent reserve price, the agent will submit the rest of her order as limit buy order at the price Rl'huy. We represent these two situations in Figure 3.1 and Figure 3.2 respectively. Order Book Before the Modification A buy limit order of size 5 and price , R: a,buy iI b =6 t-1 I 3 l e Order Book After the Modification —i—r—i—i—i—i—i—i—i—i—i—i—i— Da,buy Q a U a = 8R< S< _i I I I I I I I I I I I L_ 1 2 3 4 5 6 7 8 9 10111213 Price 1 2 3 4 5 6 7 8 9 10111213 Price Figure 3.1: Submitting some buy market orders. The best ask price is at-i = 7. There are 2 sell limit orders available at this price. The reference level given by the expert is 5" = 10. A buy limit order of size ( — 5 and price Rf'huy = 9 arrives. Two orders are executed at the price 7 and then because R'fbay = 9 > at = 8, the rest of the order is executed at the price 8. 33 Chapter 3. The Model Order Book Before the Modification A buy limit order of size 5 and price Ra'buy b . - r 5 U : R3'13^ = 8 1 2 3 4 5 6 7 8 9 10111213 Price 3 s 2 *= 3 •Q A 3 2 Order Book After the Modification —i—i—i—i—i—i—i—i—i—i—i—i—i— b . = Rf-buy = 8 The part of the order not executed is placed in the book at price R( a,buy 1 2 3 4 5 6 7 8 9 10111213 Price Figure 3.2: Submitting some buy market and limit orders. The best ask price is at-i = 8. There are 3 sell limit orders available at this price. The reference level given by the expert is S" = 9. A buy limit order of size ( = 5 and price R"'huy = 8 arrives. Two orders are executed at the price 8 and then because Rl'buy = 8 < at = 9, the rest of the order is converted to a buy limit order of size 2 and price 8. 3.2.2 The Case of Sell Orders In this case, to decide which type of order the agent will submit we need to compare the value of the best bid bt with the reserve price of the agent R^'sel1. If R^>seU < bt someone is willing to pay more than the reserve price of the agent to obtain the stock and so she is submitting a sell market order. This order will be executed against the buy limit order at the price bt as long as the size of the order £ ^ 0 or that R^'sdl < bt. If it happens that in the process of executing the order from the agent, Jl^'sel1 > 0 t then because the best bid has become smaller than the agent reserve price, the agent will submit the rest of her order as limit sell order at the price Rl'sel1. We present these two situations in Figure 3.3 and Figure 3.4 respectively. 34 Chapter 3. The Model Order Book Before the Modification Order Book After the Modification A sell limit order of size 3 and price _l I L 1 2 3 4 5 6 7 8 9 10111213 Price 1 2 3 4 5 6 7 8 9 10111213 Price Figure 3.3: Submit t ing some sell market orders. T h e best b id price is bt-i — 6. There are 4 buy limit orders available at this price. T h e reference level given by the expert is Sf = 3. A sell l imit order of size ( = 3 and price J i " ' i e H — 5 arrives. It is executed at the price 6. 35 Chapter 3. The Model Order Book Before the Modification Order Book After the Modification -1 1 1 1 1 1 1 1 1 1 r-b M = R^sell= 6 A sell limit order of size 6 and price R: a,sell 1 2 3 4 5 6 7 8 9 10111213 Price —i—i—i—i—i—i—i—i—i—i—i—i— The part of the order not n executed is placed in the book at price a^.seil a = R* 'se"= 6 1 2 3 4 5 6 7 8 9 10111213 Price Figure 3.4: Submitting some sell market and limit orders. The best bid price is bt-\ = 8. There arc 4 buy limit orders available at this price. The reference level given by the expert is S" = 5. A sell limit order of size £ = 6 and price R^'seU = Q arrives. Four orders are executed at the price 6 and then because i?*' s c = 6 > bt = 5, the rest of the order is converted to a sell limit order of size 2 and price 6. Discussion 3.15. It is important to note that in fact in our model there is no pure market order. The reason is that the agents always have a reserve price and will not be willing to buy at a price higher or sell at a price lower than this reserve price. This means that in our model all the market orders can be viewed as a limit order for which R^'buy > at in the case of a buy order and R^'se < bt in the case of sell order. This completes the section describing the decision mechanism of the agent. In the next section, we will explain where the reference level <p comes from by describing the financial experts. 36 Chapter 3. The Model 3.3 The Experts In this section we describe the role of the financial experts present in our model. The agent of our model takes the expected price for the next time interval [t, t+], called the reference level, from a financial expert. Indeed, we need to describe how these experts choose this reference level. We consider a finite set of financial experts I = {1, 2 , M } . Each expert i S I of our model has her own personal perception of the fundamental value of the stock price. To be more precise: Definition 3.16. The fundamental value or benchmark of expert i 6 I, denoted Fl(u>), is the value, on a logarithmic scale, at which this expert expects the price to return in the long run. Discussion 3.17. We note that the fundamental value of our model F}(UJ) is different from expert to expert and it is not constant because of the dependence on ui. This is one of the differences with the model of Chiarella and lori (2002 and 2004) mentioned in the introduction. In practice, the fundamental value is usually a discounted sum of future earnings. As mentioned by Lux and Marchesi (1999) the most commonly used value represents a dis-counted sum of future dividends payments. Each expert t £ I determines their reference level for the next time interval using the following equation: <p\{w) : = + a i ( w ) t f ? M - + # M [ & _ M - (pt—(oj)} (3.18) where <^_(iv) , <pt-- represent the price in logarithmic scale at time t— and t respectively, i.e., <£t(w) := log(ptM). Discussion 3.19. The coefficients a\ and 01 represent the expert estimate of the speed of price adjustment. These quantities can be negative, for example PI < 0 means that the expert follows a contrarian strategy. This as been noted by Brock and Hommes (1997) and Follmer, Horst and Kirman (2005). The determination of <p\(u)) through the formula 3.18 is general enough to allow us to consider the three usual types of traders: noise traders, fundamentalist traders and chartist traders. Their precise definition is given below. Definition 3.20. A fundamentalist is an expert for which (3\(ui) = 0. Definition 3.21. A chartist is an expert for which a\(u>) = 0. Definition 3.22. A noise trader is an expert for which both o/zt(u>) = 0 and (3\(w) = 0. 37 Chapter 3. The Model Discussion 3.23. As mentioned by Bouchaud et al. (2003) and De Long et al. (1990) it is well known in the literature that these three types of traders need to be present in a model if we want to reproduce realistic financial market data. It is important to understand where the term noise trader comes from. For this purpose, we recall the discussion 3.5 where we pointed out the importance of the random liquidity demand r]f(u). If agent a £ A follows the advice from a noise trader expert i 6 I then using equation 3.18 she obtains the following reference level: V*t(w) = ^_(w) (3.24) Now using this reference level with the fact that Sf(ui) = </>t_(w) = \og(pt_) and the equation 3.1 we obtain the agent excess demand which is simply given by: e?tpt-,w) = Ti?(u) (3.25) In other words, when an agent follows the advice from a noise trader her excess demand becomes simply her random liquidity demand. This complete the section on the description of the financial experts. In the next section we explain the process by which the agents decide from which expert they should follow advice. 3.4 The performance measure The performance measure defined in this section links the agents and the experts. Each agent a € A associates a performance measure to each expert i £ 1. The probability to follow the reference level of expert i € I will depend on this performance measure. We first introduce the notion of conditional profit realized by expert i € I and than we define the performance measure. Definition 3.26. We define the immediate conditional profit associated with the expert i El, noted TX\, as the profit that an agent will have realized between the time interval [t—, t] if she had followed expert i recommendation. More precisely, 7 r ^ = ( Y > j - S t - ) ( e * - C * - ) . (3.27) We note that using equation 3.18 ir\ can be rewritten as follow: TTJ = [a\(Lj)(Ft(w) - & _ M ) - &__(W))](pt -pt_) (3.28) Now we can define the performance measure. 38 Chapter 3. The Model Definition 3.29. The performance measure an agent a £ A associates to the expert i G I at time t, denoted U^'1, is the discounted sum of the past profit the expert i £ I recommendation would have generate. Mathematically, it is given by: 1 i U?'* = y -. (3.30) ~ Q (1 + 7A)T _? Discussion 3.31. We note that if an agent has a smaller discount factor 7, and then a longer time horizon h (using equation 3.9), she will give more weight to past profit than an agent with a higher discount factor 7. This is totally consistent. The agent with a shorter time horizon is less interested in the profits realized long ago because they will not wait for very long to cancel their orders from the book and so for them these profits will never be realized. Discussion 3.32. At this time, we want to bring the reader's attention to the importance of the discount factor 7. Each agent a G A has a discount factor, denoted 7°. This discount factor enters in three different equations: • First, it enters in the determination of the agent time horizon ha through equation 3.9. • Second, it enters in the calculation of the reserve prices R^'huy and R^'sel1 through equations 3.12 and 3.13 respectively. • Finally, it is used to discount the past profit in the calculation of the performance measure of the experts through equation 3.28. Finally, we use the performance measure of each expert as the parameter of an expo-nential distribution. We then draw a number from these distributions for each expert and the agent will choose the expert with the highest number. This completes the section linking the agents and the financial experts. In the next section we present a short algorithm to help understanding the complete model. 3.5 Order Submission Mechanism In this section we present an easy algorithm to explain the complete model step by step. This section is particularly relevant for understanding how the computer simulation is created. The first thing that need to consider a discrete version of our model. We then take t = 0 as the first time and the subsequent times are simply t = 1, t = 2, etc. In particular, this will change the notation of t— for t — 1, t for t — 2 and t+ for t + I. 39 Chapter 3. The Model 1. For each agent a G A we draw a number from a Poisson distribution with constant parameter 11. If we let, 9a(u) be the result of such a drawing for each agent a € A, then we chose the agent a with the highest 6. a = a r g m a x { 0 n ( » } . (3.33) 2. Now that we have determined which agent will be trading for the next period we need to determine from which financial expert this agent will pick up the reference level for this period. This is done by calculating the performance measure C/"'1 of every expert i g I given by the equation 3.30: 4 i n a , i = >p Th Then, we draw a number for each expert from an exponential distribution with pa-rameter and choose the expert with the highest draw. 3. Now that we have determined our expert i we can calculate her recommendation ip\ for this period using equation 3.18: ¥>!(«,) := <Pt-i(oj) + a|(w)[F/(w) - <k-iW] + / j fM[&-i(w) - &-2M] 4. At this point, we let Sf (w) = <p\(w) and we are able determine the agent's excess demand using the equation 3.1: ef (p t _ 1 } w) = <£M[5 t a M - log(pt-i)] + r/f (w) 5. As explained in the previous sections, the choice of buy or sell order is then determined by considering the sign of the excess demand ef (pt-i, w): • if ef(pt-i,u>) > 0 the agent submits a buy order and • if e°(pt_i,o)) < 0 the agent submits a sell order. 6. Then the agent submits her orders using the absolute value of her excess demand £ and her reserve price Rf. • In case of a buy order, the agent submits a buy limit order of size ( and price Ra,buy • In case of a sell order, the agent submits a sell limit order of size ( and price 40 Chapter 3. The Model 7. Finally the process of order submission is completed. The modification of the order book, the best bid price bt, the best ask price at, the spread qt and the price pt will is accomplished according to the different rules presented in chapter 2. Then, at time t + 1 we redo step 1 to 7. This completes the chapter presenting our complete model. In this chapter, we have presented in detail a description of the participants present in our model; the agents and the experts, how these participants are linked to each other via the performance measure and finally, an easy algorithm to clarify the model. In the next chapter we will present the results from the computer simulation of our model. 41 C h a p t e r 4 Simulation and Results In this chapter we present the different results obtained by a computer simulation of the model presented in the previous chapters. 1 3 Section 4.1 give a description of the different parameters that we use for the simulation and section 4.2 presents the results as a series of graphics and tables. 4.1 Setting the parameters In this section we present the choice of the different parameters for the simulation. In all of the simulations, the parameters mentioned here keep the same value unless it is otherwise mentioned. The only reasons why we do change these parameters are: • We want to analyze the effect of this particular parameter on the model or • one parameter is modified to allow a faster execution of the program after we already know what influence this parameter can have on the results. This remark is important because this allows us to claim that even if the model seems to have an enormous amount of parameters it is still relevant. The different parameters are given in table 4.1 as a quick reference. If needed, these parameters will be explained throughout the chapter after they have been introduced. 1 J The main function of our program is given in appendix A. In appendix B, we give a list and a short description of the other functions of the program. 42 Chapter 4. Simulation and Results Table 4.1: Setting the parameters Parameters Symbol Parameters Value Number of agent N N = 100 Number of expert M M = 20 Excess demand coefficient cf (w) = ca a constant on W(110,120) Random liquidity demand follows a normal law N(0, ca) Discount factor <y<l a constant on W(0.05, 0.1) Time horizon parameter va = 30 Vo e A Reserve price parameter € = o.i Expert fundamentalist coefficient a\(w) = a1 a constant on U(\, 2) Expert chartist coefficient PI(UJ) = [3l a constant on A/"(0,1) Tick size A A = 0.1 lowest price Pinin Pmin - 500 highest price Pmax Pmax = 1500 Initial price Po po = 1000 Initial fundamental value 1 0 F0> = 1000 Vi G I fundamental value volatility 6l a constant on W(10,18) Interval to compute trading volume T r = 10 Market liquidity A A = 1 In all of the cases where we say a constant on U(a,b) we mean that at the beginning of the program we chose a number uniformly on the interval [a, b] for the concerned par-ticipants. For example, ca a constant on U(110,120) means that for each a G A we choose a value ca uniformly on the interval [110,120] and this value stays the same for this entire simulation. The same comment applies for the constant on M(a, b) but we choose the number from a normal law with parameters (a, b). The parameters N, M, c"(w), nf (w), ja, va, £, a\(uj) and P\(UJ) were introduced in the previous chapters. The parameters, A , p m j n , p m a x , Po, and 5l are needed for the computer simulation and are explained below. The parameter r is related to the calculation of certain results and is explained in the subsection 4.2.2. Finally, the parameter A is an artificial parameter introduced and explained in the subsection 4.2.3. The parameters A , p m j n and pmax a r e used to create a price grid on which the agents will submit their orders. This grid is simply a vector taking values between 500 and 1500 by increment of 0.10. The parameter po simply gives the initial value of the stock price and the parameter FQ gives the initial fundamental value of expert i G I. The parameter Sl is used to model the evolution of the fundamental value of the expert i G I. For the simulation, we model the evolution of the fundamental value as follow: Ft = FU + 0.05(m t - FU) + 6AT(0,1) (4.1) 43 Chapter 4. Simulation and Results where we recall that mt is the middle of the order book defined by equation 2.19. The initial fundamental value is given by FQ = 1000 Vi £ I. We present in Figure 4.1 a typical path for the fundamental value using equation 4.1. Fundamental Value Path 11001 1 1 1 1 —T— 900' ' ' 1 ' 1 1 1 ' 1 0 2000 4000 6000 8000 10000 12000 14000 16000 Time Figure 4.1: Typical fundamental value path This completes the section 4.1. In the next section, we present the different results. 4.2 Results In this section we present the different results obtained by the simulation of our model. When this is possible, we compare some of them with empirical studies or with other simulation models. 4.2.1 Shape of the Order Book In the first series of graphics we are interested in the shape of the order book. The Figure 4.2 represents a typical order book at the end of the simulation. At this point, it is important to note that the book attains two maxima away from the best bid and best ask price which is just below a thousand and just over a thousand respectively. Moreover, we also note that there are orders far away from the best bid and the best ask, 44 Chapter 4. Simulation and Results some as low as 800 and some as high as 1200. Finally, we note a certain symmetry of the book. These three facts have been found also for real stock market empirically by Bouchaud, Mezard and Potters (2002) and by Bouchaud and Potters (2003). As noted by these authors, the long tail of the book suggest that some agents expect a large variation in the price or have a very long time horizon. Contrarily to what Luckock (2003) suggests, we do not see a price window at the end of which orders accumulate in the order book. This is normal and it is because in our model the agents have a finite time horizon at the end of which they cancel the unexecuted part of their orders. All the orders that are placed too far from the best bid and ask prices are eventually cancelled by the agent that place them. Order Book at the End 601 . 1 1 - 8 0 1 1 1 1 ' ' 1 400 600 800 1000 1200 1400 1600 Price Figure 4.2: A typical representation of the order book at the end of the simulation. We see from this figure that the order book attains two maxima away from the best bid and best ask price. We also note that there are some orders far away from the best bid and best ask price. Because the Figure 4.2 is only a representation of the order book at the end of the simulation, we cannot confirm that the shape of the order book is similar during the simulation itself. In order to speak about the shape of the order book for the entire simulation we introduce the concept of average order book. Definition 4.2. The average order book is simply an average of all the order books rep-resented during the entire simulation. 45 Chapter 4. Simulation and Results We show in Figure 4.3 that the average order book has in fact the same shape than the order book at the end of the simulation and indeed our conclusions about the shape of the book still hold. We have not yet verified but we claim in fact that the shape of the average order book converges to a unique order book configuration for a specific set of parameters. Average order book Figure 4.3: We see from this figure that the order book attains two maxima away from the best bid and best ask price. We also note that there are some orders far away from the best bid and best ask price. This completes the section presenting the results related to the shape of the order book. 4.2.2 The Volatility in the Asset Prices The second series of graphics and tables explain a part of the asset price volatility by using other parameters of the model. Several authors have argued that the high volatility in the price is associated with large trading volume (see Gabaix et al. (2003)) or large gap in the book, i.e., large bid and ask spread (see Farmer et al. (2004)) and small number of orders in the book (see Weber and Rosenow(2006)). In order to verify these three affirmations we need to introduce the following definitions. D e f i n i t i o n 4.3. The trading volume between time t and t — T, denoted V}_T, is given by: t v}_T = Y . y i (4-4) i—t—r 46 Chapter 4. Simulation and Results where V1 is the trading volume at time i. Definition 4.5. The volatility between time t and t — r, denoted o\_T, is simply the price variance between period t — r and t. Definition 4.6. The cumulative bid and ask spread between time t and t — r, denoted q\_T, is given by: t E (4-7) i—i—T rf-where ql is the bid and ask spread at time i. Definition 4.8. The returns between time t — r and t, denoted Xt-r> a r e Qiven by: t Pt - Pt-T Xt-T = ~ Pt-T (4.9) The Figure 4.4 illustrates the relation between the trading volume and the price volatil-ity. Trading volume 0 500 1000 1500 2000 2500 3000 3500 4000 Time x ,0" Volatility 0 500 1000 1500 2000 2500 3000 3500 4000 Time Figure 4.4: Volatility and trading volume. We note a positive correlation between the price volatility and the trading volume. Each big spike from the volatility figure seems to be accompanied by spike from the trading volume figure. As it is easy to see from the figure, there is a clear positive correlation between the trading volume and the price volatility. More precisely, we found a correlation of 0.4375 47 Chapter 4. Simulation and Results between these two variables. We present this result differently in Figure 4.5 by showing the price evolution and the trading volume on the same graphic. Trading Volume c 1000 500 500 1000 1500 2000 2500 3000 3500 4000 7/me Evolution of the Price 2 Time 2.5 x 10 Figure 4.5: The relation between the price and the volume. We can see from this figure that large price movements are usually accompanied with high trading volume. The two last figures and the correlation found suggest that the periods of high price volatility are usually accompanied by periods of large trading volume. The figure 4.6 illustrates the relation between the spread and the price volatility. 48 Chapter 4. Simulation and Results Cummulative Bid and Ask Spread 60001 1 1 . 1 1 1 •5 0 500 1000 1500 2000 2500 3000 3500 4000 Time x 10< Volatility 0 500 1000 1500 2000 2500 3000 3500 4000 Time Figure 4.6: Volatility and cumulative bid and ask spread. We note a positive correlation between the price volatility and the cumulative bid and ask spread. The figure suggests a positive correlation between the spread and the price volatility. More precisely, we found a correlation of 0.4099 between these two variables. We present this result differently in Figure 4.7 by showing the price evolution and cumulative bid and ask spread on the same graphic. 49 Chapter 4. Simulation and Results Evolution of the Price c 1000 500 800 8 600 r 2 400 h Figure 4.7: The relation between the price and the bid and ask spread. The figure illustrates that the large price movements and large values of the bid and ask spread usually happen at the same time. The two last figures and the correlation found suggest that the periods of high price volatility are usually accompanied by periods with a large cumulative bid and ask spread. This is absolutely coherent. When the bid and ask spread is large, the price will vary significantly every time the orders change sign. If the order is a buy order the given price will be the best ask price and if the next order is a sell order than the given price will be the best bid price. If the bid and ask spread is large it means that the difference between the best bid and best ask price is large and consequently there are large price variations each time the order change sign. This means that we could use the bid and ask spread to partially predict the price volatility. In Figure 4.8 we present the relation between the returns and the price volatility. The figure suggests a positive correlation between these two variables. More precisely, we found a correlation of 0.4876 between the absolute value of the returns and the price volatility. This result is nothing surprising because large absolute returns arrive only when there are large price fluctuations. Indeed, an investor who is seeking large returns over a short period of time should choose to invest in a stocks with large volatility. One has to be careful with this statement because large returns in absolute value also means large losses. 50 Chapter 4. Simulation and Results Evolution of the Returns 0 500 1000 1500 2000 2500 3000 3500 4000 Time Figure 4 .8: Volatility and the return. We note a positive correlation between the variability of the returns and the volatility of the price. Finally, we present in Figure 4.9 the relation between the number of orders in the order book and the asset price volatility. 51 Chapter 4. Simulation and Results Number of Orders in the Book 2000 I 1 1 1 1 r 0 1000 2000 3000 4000 5000 6000 7000 Time Figure 4.9: Volatility and Number of Orders. We note a clear negative correlation between the number of orders in the book and the price volatility. The figure suggests a negative correlation between these two variables. More precisely, we found a correlation of —0.4613. The negative sign is coherent with the study of Weber and Rosenow (2006). In this paper, the authors suggest that we can not explain large price movements only with the trading volume but we also need to consider the number of orders in the book. When the number of orders in the book is small than large orders can make the price vary greatly because we need to move further in the book to execute these orders entirely. This result is important because it contributes to the debate of how much information about the order book should be displayed to the different economic agents. An agent who knows in addition to the best bid and best ask price the number of orders in the book has an obvious advantage than the agent who only knows the best bid and best ask price. This is particularly relevant in the case of large order size. Knowing that the number of orders in the book is low when someone wants to place a very large order is relevant because this agent can anticipate that her order might creates large price movements. At this point, the agent can decide to submit her order anyway or to divide her order in several small orders to minimize her impact on the price. This completes the results section related with the different possible explanations about the stock price volatility. In summary, we can say that periods of high price volatility are usually accompanied by periods of large trading volume, large bid and ask spread and relatively small number of orders in the book. In the next section we are interested in the effects of some important parameters. 52 Chapter 4. Simulation and Results 4.2.3 S o m e R e l e v a n t P a r a m e t e r s The third series of graphics tries to verify the importance of three specific parameters on the trading volume, the volatility, the spread and the number of bids and asks in the book. The three parameters of interest are the market liquidity A, the tick size A and the time horizon h by varying the value of va. For each of these parameters we are considering four different dependent variables: the trading volume given as the average trading volume for the entire simulation, the volatility given as the price variance for the entire simulation, the spread given as an average for the entire simulation and the number of bids and asks also as an average for the entire simulation. We present and comment on the three different graphics obtained and we give the correlation between the different variables in table 4.2. The market, liquidity is an artificial parameter that represents the level of market activ-ity. It represents the probability that the chosen agent will trade at time t. This parameter was also considered in other models (in particular see Chiarella and lori (2002)). For all other simulation its value is set to one, which means that once an agent is chosen this agent will always trade. For the first graphic of this section, figure 4.10, we vary the value of A between 0 and 1. In Figure 4.10 we show the dependence on the market activity A. For the market activity A, it seems completely natural to obtain a quasi perfect correlation between A and the trading volume. It is the same thing for the number of bids and asks. The correlations with the number of bids and asks in the book are strong and positive, 0.8749 and 0.8574 respectively. This is also perfectly coherent, when the market is more active, the agents submit more limit orders and so the number of bids and asks will increase. The correlation with the volatility is not terribly strong but still positive 0.3967 which is also coherent. If once chosen, the probability that an agent submits an order is higher then we can expect the price volatility to be higher as well. The number that needs some more explanation is the negative correlation with the spread. The important concept to understand here is that when the market becomes more active, the agents are submitting more orders of both types. Because the limit orders will generally reduces the spread it is not incoherent to obtain a negative correlation between the market activity A and the spread q. The results about the dependence on the market activity are important in the applications of our model to reality. In particular, the relation between A and the number of bids and asks can be use as an indication of the number of orders in the book even if this information is not directly displayed to the agents. 53 Chapter 4. Simulation and Results Volume as a Function of Lambda Volatility as a Function of Lambda 10 8 CD I 6 ^ 4 2 0 0.2 0.4 0.6 0.8 lambda Spread as a function ofLlambda 60 g 40 0.2 0.4 0.6 lambda 0.8 5 § 1000 0 0.2 0.4 0.6 0.8 1 lambda Bid and Ask as a Function of Lambda 2000 Figure 4.10: Dependence on the market activity A. We note a strong positive correlation between A and the trading volume and A and the number of bids and asks in the book. We also note a positive correlation between A and the price volatility. Finally, we note a negative correlation between A and the bid and ask spread which we explain further above. 54 Chapter 4. Simulation and Results In figure 4.11 we show the dependence on the tick size A. For the tick size, in this case, most of the correlation are almost irrelevant (see table 4.2). A priori, this seems to be wrong but it is coherent with other studies for these values of the tick size (see Chiarella and lori (2002)). These results are really important in terms of market design. It suggests that when the market designers decide the tick size for a particular stock, they can choose a value between 0.01% and 0.5% of the initial value of the stock without significantly affecting the trading volume, the price volatility, the bid and ask spread and the number of bids and asks in the book. Volume as a Funct ion of the Tick Size 11.5 11 CD •lum 10.5 10 9.5 9 0 1 2 3 4 5 tick size Spread as a Funct ion of the T ick Size 35 30 g 25 Q. 1 / 5 20 15 10 2 3 tick size Volatility as a Funct ion of the Tick Size 2000 f 1500 | 1000 500 0 1 2 3 4 5 tick size Bid and A s k as a Funct ion of the T ick Size „ 2000 to c 1500 CO •8 <3 1000 * * * * * * ** ^ -* * • • •* * * Bids * * Asks 2 3 tick size Figure 4.11; Dependence on the tick size A Table 4.2: The Different Correlations Volume Volatility Spread Bid Ask A 0.9903 0.3967 -0.1469 0.8749 0.8574 A 0.1495 0.1807 0.1747 -0.0592 -0.0395 h -0.1007 -0.3141 -0.1068 0.8592 0.8744 55 Chapter 4. Simulation and Results Finally, in figure 4.12 we show the dependence on the time horizon h. The modification of h is made through an increase of the constant parameter v (see equation 3.9). For the time horizon, we ignore the correlation with the trading volume and the spread because they are too weak. Nevertheless, one can note that at least the correlation with the spread has the correct sign, i.e., the spread is decreasing in h. This is coherent if we consider that if all agents have a longer horizon then the number of limit orders in the book should increase. The correlation with the volatility -0.3141 is not really strong but is also in the right direction. When the agents have a longer time horizon more limit orders are placed by these agents and the price volatility is reduced. For the correlation with the number of bids and asks, it is natural to obtain a positive correlation because if the agents are waiting longer before canceling their limit orders than there are more orders in the order book. Volume as a Function of the Time Horizon Volatility as a Function of the Time Horizon 1 1 r \ 1 0 0 0 S 1 0 . 5 1 ' . . . -I £ • 8 0 0 3 > 10 9.5 § 6 0 0 4 0 0 2 0 0 0 2 0 0 4 0 0 6 0 0 8 0 0 0 2 0 0 4 0 0 6 0 0 8 0 0 Time horizon Time horizon Spread as a Function of the Time Horizon Bid and Ask as a Function of the Time Horizon 5 0 f ' ' ' ~ ~ * — 4 0 •o ro 8 3 0 2 0 1 0 6 0 0 0 .3 to 5 0 0 0 T. 73 C ro 4 0 0 0 to "O 63 3 0 0 0 2 0 0 0 Bids * Asks -* * 0 2 0 0 4 0 0 6 0 0 8 0 0 Time horizon 2 0 0 4 0 0 6 0 0 8 0 0 Time horizon Figure 4.12: Dependence on the time horizon h. We note a strong positive correlation between the time horizon h and the number of bids and asks in the book. There is also a negative correlation between the time horizon and the volatility. The other correlations are explained in more details above. This completes the section about the influence of some relevant parameters. We recall 56 Chapter 4. Simulation and Results here the most important findings of this section. First, the results about the dependence on the market activity are similar to results from other studies (see Chiarella and lori (2002 and 2004)) and have important applications in reality. In particular, the relation between the market activity A and the number of bids and asks in the book can be used as a proxy of the number of orders in the order book. Second, the results about the tick size are also consistent with other studies (see Chiarella and lori (2002 and 2004)) and are relevant for market designer. Finally, the results about the time horizon are different from other studies. Once again the relation between the time horizon and the number of bids and asks in the book can be used to estimate the number of orders in the order book. In the next section we study the importance of chartists in our model. 4.2.4 The Effects of the Chartists This series of graphics attempts to demonstrate the important effects of the presence of chartists in the model. The results found in this section are similar to the one found by other studies (see Chiarella and lori (2002), Chiarella and lori (2004), De Long et al. (1990) and Follmer, Horst and Kirman (2005)). 1 4 In Figure 4.13 we show the differences in the evolution of the returns and the evolution of the price in a model with fundamentalists and noise traders only and in a model with fundamentalists, noise traders and chartists. It, is easy to see from the figure that the chartists create an increase in the variability of the returns and of the asset price. M W e need to warn the reader that DeLong et al. (1990) used the term noise trader for what we consider as chartist trader. 57 Chapter 4. Simulation and Results a .c 5 3 a> OC S 20 10 0 -10 -20 20 10 0 -10 -20 Evolution of the Returns 50 100 150 200 Time Evolution of the Returns 50 100 Time 150 200 1200 1100 c 1000 900 800 1200 1100 c 1000 900 800 Evolution of the Price 2000 4000 6000 8000 10000 Time Evolution of the Price 2000 4000 6000 8000 10000 Time Figure 4.13: Evolution of the price and the returns. The top figure shows a model where there is no chartist present and the bottom figure shows a model where the chartists are present. For the returns we choose r = 50. We note that the presence of chartists increases the variability of the returns and the price processes. 58 Chapter 4. Simulation and Results In Figure 4.14 and Figure 4.15 we look at the returns more closely. Figure 4.14 shows the distribution of the returns of the model without chartists, the model with chartists and a normal distribution with the same mean and variance than the model without chartists. We see that the presence of chartists definitively fattens the tail of the returns distribution. This result was also found in the more theoretical model of Follmer, Horst and Kirman (2005). Returns Distribution 0.25 r Noise and fundamentalist Normal distribution — Noise, fundamentatlist and Chartist 0.21 g 0.151 Q 0.1 0.051 0 1 — - 3 0 - 20 -10 0 10 Returns in Percentage 20 30 Figure 4.14: Return distributions. On the same graphic we represent the model without chartist, the model with chartists as well as a normal distribution with the same mean and variance than the model without chartist. For the returns we choose r = 10. We note that the presence of chartists fattens the tails of the returns distribution. 59 Chapter 4. Simulation and Results In Figure 4.15 we compare the returns distribution of the model with chartist and a normal distribution with the same mean and variance. Once again, we see that the distribution of the model has a fatter tail than the normal distribution. Returns Distribution 0.35 1 1 1 1 1 1 - - Noise, fundamentatlist and Chartist Normal distribution 0.3 r Returns in Percentage Figure 4.15: Return distribution. On the same graphic we represent a normal distribution with the same mean and variance than the return distribution of our complete model. For the returns we choose r = 10. Once again, it is easy to note that the return distribution of our model has a fatter tail than a normal distribution. The two last figures suggest that in the presence of chartists, the returns are not nor-mally distributed. Empirical studies have demonstrated that the returns are not normally distributed in reality. This is why the presence of chartists is essential in the modeliza-tion of financial market. To confirm the fact that our return distribution is not a normal distribution we present a normal plot of our returns in the figure 4.16. 60 Chapter 4. Simulation and Results Figure 4.16: Normal plot of the returns distribution for r = 10. The dashed line represent the theoretical distribution while the + signs represent our data. It is easy to see from this figure that our returns are not normally distributed. If it were the case, the + signs would all be on the dashed straight line. At this point, maybe one can think that this is true for the particular value of r = 10. We prove that it is not the case in figure 4.17 showing another normal plot but this time with r = 1. In fact, we have verified that our returns distributions are not normal for r 6 [1,1000]. This result is important because empirical studies also found that the returns are not normally distributed for a wide range of r (see Plerou et al. (2002)). 61 Chapter 4. Simulation a.nd Results Figure 4.17: Normal plot of the returns distribution for r = 1. The dashed line represent the theoretical distribution while the + signs represent our data. It is easy to see from this figure that our returns are not normally distributed. If it were the case, the + signs would all be on the dashed straight line. This completes the subsection about the effects of chartists. In the next subsection we want to make more precise comparison of the tail of our returns distributions to some theoretical distribution. 4.2.5 Power-law Distribution In this subsection, we are interested to compare the tail of our returns distributions to the tail of a power-law distribution. Some empirical studies have found precise expressions for the tail of the returns distri-bution. In particular, Gabaix et al. (2003) have found empirically that the tail of the return distributions follows a power-law with an exponent £ r = 3. Another study by Plerou et al. (2002) found similar results with an exponent between (r = 2 and ( r = 4. The precise statement is as follow. We first introduce the following definition. Definit ion 4.10. The log returns between period t and t — r, denoted r\_T, are given by 7> = \n(pt) - ln(pt_T) (4.11) 62 Chapter 4. Simulation and Results Then these authors found that the probability that a return has an absolute value larger than x is P(|r t'_T| >x) ~ c a T C r (4.12) where c is a constant. This result is found to be quite robust as it is holding for up to 80 standard deviations for some stocks in the market and it is holding for values of T that range between one minute up to one month. 1 5 The actual reason of such phenomenon is a subject of disagreement between the different researchers. 1 6 Our goal for the moment is not to explain such phenomenon but verify if our model can reproduce it. We present in Figure 4.18 a representation of the tail of our distribution and the tail of a distribution given by equation 4.12 with C = 3. , n W e refer the reader to Plerou et al. (1999) for more details. l 6 Sce Plerou at al. (2002), Gabaix et al. (2003), Farmer, Lillo and Mantegna (2003), Bouchaud and Potters (2003) and Farmer and Lillo (2004). 63 Chapter 4. Simulation and Results Figure 4.18: Tail of the return distribution compared to a power law with C = 3 and T = 50. The solid line represents the power tail with c = 1, the dashed line represents a translation of the power tail by modifying the value of c and the curve represents the tail of our model. The axis are in a logarithmic scale and as a consequence the power law is represented by a straight line with slope -3. We note from this figure that there is a non trivial set of parameters for which the tail of our distribution agree with the tail of a power law distribution. We present on Figure 4.19 the set of parameters for which the power law and our distribution agrees. 64 Chapter 4. Simulation and Results Log Return Distribution Returns in Percentage Figure 4.19: Tail of the return distribution compared to a power law with ( r = 3 and T = 50. The x axis values arc between 5 and 15. The thick gray line represents the power tail with c = 1, the black dashed line represents a translation of the power tail by modifying the value of c and the thin black solid line represent the tail of our model. The axis are in a logarithmic scale and as a consequence the power law is represented by a straight line with slope -3. We see easily with this figure that our distribution agree almost perfectly, after a translation, with a power law for these values of returns. We are now interested to verify if the tail of our return distribution agree with a power-law for a wider range of values of r. We verify the robustness of our result in Figure 4.20 where we show the tail of the returns distributions for different choice of r. 65 Chapter 4. Simulation and Results 1 0 - 5 | 10"" 10~3 10"2 10"1 10° 101 102 Returns in Percentage Figure 4.20: Tail of the return distribution for different values of r G [1,1000]. The solid line represents the power tail with ( r = 3 and c = 1, the dashed line represent a translation of the power tail by modifying the value of c and the curve represent the tails of our model for different values of r. The axis are in a logarithmic scale and as a consequence the power law is represented by a straight line with slope -3. Once again, we note from this figure that there is a non trivial set of parameters for which the tail of our distribution agree with the tail of a power law distribution. Moreover, we note this result seems to be robust to the variation of r. Once again, this confirm that the tail of our return distributions agree with a power law with exponent ( r = 3 for a non trivial set of parameters (see figure 4.21). Finally, this figure also suggest that the result is independent of r fo r r 6 [1,1000]. This is consistent with the empirical literature, as noted by Plerou et al. (1999). 66 Chapter 4. Simulation and Results Log Return Distribution 10° r c .o Returns in Percentage Figure 4.21: Tail of the return distribution for different values of r € [1,1000]. The solid gray line represents the power tail with C = 3 and c = 1, the dashed gray line represents a translation of the power tail by modifying the value of c and the black curves represent the tails of our model for different values of r. The axis are in a logarithmic scale and as a consequence the power law is represented by a straight line with slope -3. Once again, we note from this figure that there is a non trivial set of parameters for which the tail of our distribution agree with the tail of a power law distribution. Moreover, we note this result seems to be robust to the variation of r. Discuss ion 4.13. It is important to note that even if the tails of the returns distributions are similar for different values of T, the actual returns distributions can look quite different. We illustrate this idea in figure 4-22 where we present two returns distributions for two different values of T . 67 Chapter 4. Simulation and Results 0.2 0.18h 0.16 0.14 g 0.12 CO Q ^ 0.1 3 CO 8 0.08 0.06 0.04 0.02 Returns in Percentage -60 -40. -20 0 20 Returns in Percentage 40 • Step Size = 1 Step Size = 10 60 80 Figure 4.22: Returns distribution with different values of r. The solid line represents the returns distribution for r = 1 and the dashed line represents the returns distribution for r = 10. The strange shape of the distribution with T = 10 is due to the adjustment made by putting the two distributions on the same figure. This completes the subsection related to the comparison with a power-law distribution. In summary, we can say that the tails of our returns distributions agree with the tail of a power law for a non trivial set of returns values. Moreover, this result is independent of the value of r at least for r £ [1,1000]. In the next subsection we present the results related with the stationary distributions for the price and the returns processes. 4.2.6 In Search of the Stationary Distribution In this section we present the main result of this project. We are interested in finding the unique and stationary distribution for the price process. As mentioned in the introduction, this result has be found analytically in a Walrasian market framework by Follmer, Horst and Kirman (2005). The goal is to verify numerically if this result can also be found in the continuous double auction framework. One of the problems of such verification is that we can not let the time go to infinity in our simulation because the computation will never finish. In our context, letting the time 68 Chapter 4. Simulation and Results go to infinity means repeating the steps 1 to 7 given in the section 3.5 forever. Instead, to test the stationarity of our price and returns time series we use a statistical test.17 The usual method used for testing the stationarity of a time series data is the Kwiatkowski, Phillips, Schmidt and Shin test, short to KPSS test, as explained in Kwiatkowski, Phillips, Schmidt and Shin (1992). D i s c u s s i o n 4 .14 . It is important to note that the KPSS test is better than the Dickey-Fuller (DF) or the Phillips and Perron (PP) tests. These two tests use the series follows a unit root process as their null hypothesis Ha. The KPSS test uses the series is stationary as the null hypothesis H0 and it then constitutes a better method to test stationarity. 18 We have performed the KPSS test for the price and the returns using the free statistical software R. In both cases, we cannot reject the null hypothesis that our time series is stationary. 1 9 This confirms our intuition that changing the market organization from the Walrasian framework to the continuous double auction does not change the stationarity of the price process. Unfortunately, verifying the uniqueness of the two distributions causes some problems. We present here an idea of how this could be done correctly. First, we need to choose the number of time we want to repeat the steps 1 to 7 presented in section 3.5. We have decided to choose 50000 which already require approximately 4 hours of computation. There is no a priori indication of how big this number should be. In fact, this particular choice is related to the computation time more than any other reasons. Second, we need to repeat this computation several times in order to create a sample of stationary distributions. Third, once this sample is complete, we could build a statistical test to verify the true mean, variance and higher order moments of the potential stationary distribution. Unfortunately, this is not necessarily feasible. In order to obtain a good statistical test we would need a relatively large sample because the size of the sample is inversely proportional to the square of the margin error of the test (see McCabe and Moore 1999, chapter 6). This causes a problem with the computation time of our model. As an example, obtaining a sample size of 1000 would require approximately 166 days of computation. This does not seem to be easily feasible. Instead, we decide to present a graphic on which we plot the price distribution every 1000 steps of our 50 000 iteration to show that the distribution of the price become closer and closer to the distribution at the very end of the simulation. This is done in the Figure 4.23. ' 'For a review about statistical test in general we refer the reader to McCabe and Moore (1999) and Wooldridge (2008). 1 8Sce Dickey and Fuller (1979). Phillips and Perron (1988) and Kwiatkowski, Phillips, Schmidt and Shin (1992). 1 9 The complete details of our tests is given in appendix C. 69 Chapter 4. Simulation and Results Figure 4.23: The Price Stationary Distribution. The solid line represents the price distri-bution at the end of the simulation while the dotted lines represent the price distribution every 1000 steps. We see that the distributions gradually approaches the distribution at the end of the simulation with less significant differences each time. We present the same type of graphic in Figure 4.24 for the price returns. 70 Chapter 4. Simulation and Results Returns Distribution 0.18r Returns in Percentage Figure 4.24: Returns stationary distribution. The circles represent the price distribution at the end of the simulation while the dotted lines represent the price distribution every 1000 steps. We see that the distributions gradually approach the distribution at the end of the simulation with smaller differences each time. We choose r = 1. One would obtain an other distribution with a different r but it will still be unique for each choice of r. For this reason the price distribution is more interesting because it does not require us to precise the choice of r. These two graphics obviously do not constitute a rigorous statistical test nor than a rigorous mathematical proof. On the other hand, they confirm the intuition that even in a continuous double auction market model there seems to exist a unique stationary distribution for the price process which justifies further analytical research in this direction. This completes the chapter on the computer simulation and the numerical results. In the next chapter, we present the conclusion of this thesis. 71 C h a p t e r 5 Discussion and Conclusions 5.1 Discussion In this section we recall the model developed in this thesis, some of the main important assumptions made, the main goals and the different techniques used to achieved these goals. We have presented in the previous chapters a model of a financial market with many heterogeneous agents in a continuous double auction market organization. We have intro-duced the different concepts related to continuous double auction and electronic limit order book. We have constructed a financial market model with heterogeneous agents that are using this electronic order book to trade. Agents submit orders according to a Poisson dy-namics with constant parameter p,. Each agent decides to buy or to sell the stock according to the recommendation of a financial expert. These recommendations represent the expert, expected price of the stock for the next, period. There are three types of financial experts: the noise traders, the fundamentalist traders and the chartist traders. The recommen-dation from the noise traders are random, the recommendation from the fundamentalists are based on some fundamental value of the stock price while the recommendation of the chartists are based on some extrapolatory or contrarian rules. The agents are choosing the financial expert by comparing each of them using a performance measure. In our case, they compare a discounted sum of past profits their recommendations would have generated. Once the financial expert, is determined, the agent forms her excess demand and then exe-cutes her trade according to the sign of her excess demand. The price is then determined using the different rules governing the order book dynamics. One of the most important assumption is related with the information available to the agents. Each agent has a full knowledge of the past history of the price process and all the past recommendation of every experts present in the market. Moreover, our model makes the assumption that the agents are able to use this information properly to calculate the performance measure of each expert. This represents a limitation of our model. Our principal goal was to verify numerically the existence and uniqueness of a stationary distribution for the price process. We also verify that our model can reproduce some of the phenomena found in financial time series. Finally, to attain these goals we have used computer simulation, statistical techniques (correlation, tests, KPSS, etc.) and lots of graphical representation of our results. In the next section, we recall the results obtained. 72 Chapter 5. Discussion and Conclusions 5.2 Conclusion We present in this section the main results obtained by the computer simulation. First, we recall the interesting results about the shape of the order book. The order book has two local maximums away from the best bid and best ask price which was also found in empirical studies (see Bouchaud and Potters (2003)). Second, we have found a positive correlation between the stock price volatility and trading volume and cumulative bid and ask spread (0.4375 and 0.4099 respectively). We also found a negative correlation (-0.4613) between the price volatility and the number of order in the book. This negative correlation is consistent with the explanation of Weber and Rosenow (2006) that the price volatility cannot be entirely explained by the trading volume but that the number of orders in the book is also important. Third, we have found interesting relationships between the market activity, the tick size and the time horizon of the agents and other important variables. In particular, we recall the strong positive relations between the market activity and the trading volume and the number of bids and asks in the book. We also recall the positive relation between the agent time horizon and the number of bids and asks in the book. Fourth, we have illustrated using graphics the important effects of the presence of chartists in our model. In particular, the presence of chartists increases the variability of the price and the returns processes and as a consequence fattens the tail of the returns distribution compare to a model without chartists. Fifth, we compare our return distribution with a power law and found that the tail of our distribution agree with a power law for a non trivial set of parameters. This is an important result because empirical studies have shown that the tail of returns distribution usually follow a power law (see Plerou et al. (2002) and Gabaix et al. (2003)). Finally, we have verified that the price distribution is stationary using the KPSS statistical test. We claim that the this distribution is unique even if the numerical verification was not make here because of the computing time it requires. In conclusion, we want to point out the importance of heterogeneity, the effects of the presence of chartists and the existence of a stationary distribution for the price process. This last result is essential because it justifies that further efforts should be done to prove analytically the existence of such distribution for the continuous double auction market organization. We present in the next section other directions that further research on this topics can take. 5.3 Further Research Even if at the first glance the model presented in this thesis seems complete and the results numerous, there are many ways one can do further research related to this thesis. We separate them in two categories: statistical and simulation researches and theoretical research. For the statistical and simulation research, we suggest the following extensions. 73 Chapter 5. Discussion and Conclusions • Try to find predictive power of certain variables by verifying correlation with variables at different times. • Try to compute the market impact function (found in the model of Gabaix et al. (2003) and also mentioned in Farmer and Lillo (2003)). • We need further comparison of the model and the results found in the empirical literature. • There is also a need for a calibration exercise to be able to use the model for predic-tions. • One could consider more types of orders: stop loss order, stop limit orders, etc. • There are many relations found in financial data that have not been analyzed in the current project and indeed many other graphic results could be created. • The excess demand could come from a optimization problem as in Chiarella and lori (2004) . • The dependence of the results on other parameters should also be verified. For the theoretical research, we suggest the following extensions. • Analyze an optimal order type choice (between market and limit orders) as it is done in Luckock (2003). • Do the mathematical analysis for the existence and the uniqueness of the stationary distribution for this market organization as it is done by Follmer, Horst and Kirman (2005) for the temporary Walrasian equilibrium framework. This completes this thesis. We hope that the reader enjoyed the presentation of "A Study of Financial Markets with Heterogeneous Agents: A Numerical Approach." 74 Bibliography Bacchetta, P., van Wincoop, E. , 2005. Can information heterogeneity explain the ex-change rate determination puzzle? Preprint. Bouchaud, J-P. and Potters, M., 2003. More statistical properties of order books and price impact. Physica A 324, 133-140. Breeden, D.T., 1979. An intertemporal asset pricing model with stochastic consumption and investment opportunities. Journal of Financial Economics 7(3), 265-296. Brock, W. and Hommes, C , 1997. A rational route to randomness. Econometrica 65 (5), 1059-1096. Campbell, J., Lo, A. and MacKinlay, G., 1996. The Econometrics of Financial Mar-kets. Princeton University Press, Princeton, New Jersey. Challet, D. and Stinchcombe, R., 2001. Analyzing and modelling 1 + Id markets. Physica A 300, 285-299. Cheung., Y.-W., Chinn, M.D., Pascual, A.G. , 2002. Empirical exchange rate models in the nineties: are they fit to survive?. NBER Working Paper No 9393. Chiarella, C. and Iori, G., 2002. A simulation analysis of the microstructure of double auction markets. Quantitative Finance 2, 346-353. Chiarella, C. and Iori, G., 2004. The Impact of Heterogeneous Trading Rules on the Limit Order Book and Order Flows. Quantitative Finance Research Centre Research Paper No. 152 Chionis, D., MacDonald, R., 2002. Aggregate and disaggregate measures of the foreign exchange risk premium. International Review of Economics and Finance 11, 57-84. Cochrane, J., 2001. Asset Pricing. Princeton University Press, Princeton, New Jersey. Coppejans, B. and Domowithz, I., 1999. Screen information, trader activity and bid-ask spreads in a limit order market. Preprint. [13] Cvitanic, J. and Fernando, Z., 2004. Introduction to the Economics and Mathematics of Financial Markets. The MIT Press, Massachusetts. 75 Bibliography J.B., Shleifer, A., Summers, L.H. and Waldmann, R.J., 1989. The size and incidence from noise trading. Journal of Finance 44(3), 681-699. De Long, J.B., Shleifer, A., Summers, L.H. and Waldmann R.J., 1990. Noise Trader Risk in Fiancial Markets. Journal of Political Economy 98 (4), 703-738. Dickey, D.A. and Fuller W.A., 1979. Distribution of the estimators for autoregressive time series with a unit root. Journal of the American Statistical Association 74, 427-431. Duffie, D., 2001. Dynamic Asset Pricing Theory 3rd edition. Princeton University Press, Princeton, New Jersey. Farmer, D., Guillemot, L., Lillo, F. and Mike, S., 2004. What really causes large price changes? Quantitative Finance 4, 383-397. Farmer, J.D. and Lillo, F., 2004. On the origin of power law tails in price fluctuations. Quantitative Finance 4, C7C11. Farmer, J.D., Lillo, F. and Mantegna, R.N., 2003. Master curve for price-impact function. Nature 421, 129-130. Farmer, J.D. and Zovko, I., 2002. The power of patience: a benavioural regularity in limit-order placement. Quantitative Finance 2, 387-392. Follmer, H., Horst, U. and Kirman, A., 2005. Equilibria in financial markets with heterogeneous agents: a probabilistic perspective. Journal of Mathematical Economics 41, 123-155. Frankel, J.A. and Rose, A.K., 1995. Empirical research on nominal exchange rates. In Grossman, G.M. and Rogoff, K. (eds) Handbook of International Economics, vol III. North-Holland, Amsterdam. Friedman, D., 1993. The double auction market institution: a survey. The Double Auction Market: Institutions, Theories and Evidence ed D. Friedman and J Rust (Reading, MA: Addison-Welsey). Gabaix, X., Gopikrishnan, P., Plerou, V. and Stanley H. E. , 2003. A theory of power-law distributions in financial marek fluctuations. Nature 423, 267-270. Gollier, C., 2001. The Economics of Risk and Time. MIT Press, Massachusetts. Hull, J.C., 2006. Options, Futures and Other Derivatives, 6th edition. Perason Prentice Hall, New Jersey. 76 Bibliography Kurz, M., 1994a. On the structure and diversity of rational beliefs. Economic Theory 4, 877-900. Kurz, M., 1994b. On rational belief equilibria. Economic Theory 4, 859-876. Kwiatkowski, D., Phillips, P.C.B, Schmidt, P. and Shin, Y., 1992. Testing the null hypothesis of stationarity against the alternative of a unit root: How sure are we that economic time series have a unit root? Journal of Econometrics 54, 159-178. Lucas, Jr.R.E., 1978. Asset prices in an exhange economy. Econometrica, 46(6), 1429-1445. Luckock, H., 2003. A steady state model of the continuous double auction. Quantitative Finance 3, 385-404. Lux, T. and Marchesi, M., 1999. Scaling and criticality in a stocastic multi-agent model of a financial market. Nature 397, 498-500. Mas-Colell, A., Whinston, M.D. and Green, J.R., 1995. Microeconomic Theory. Oxford University Press, New York. McCabe G.P. and Moore D.S., 1999. Introduction to the practice of statistics 3rd edition. W.H. Freeman and Company, New York. Meese, R.A., Rogoff,K. 1983. Empirical exchange rate models of the seventies: do they fit out-of-sample. Journal of International Economics 14, 3-24. Merton, R.C., 1973. An intertemporal capital asset pricing model. Econometrica 41(5), 867-887. Merton, R.C., 1992. Continuous-Time Finance, Blackwell, Massachusetts. Phillips, P.C.B. and Perron, P., 1988. Testing for a unit root in time series regression. Biometrika 75, 335-346. Plerou, V., Parameswaran, G., Gabaix, X., and Stanley, H.E., 2002. Quantifying stock price response to demand fluctuations. Physical Review E66, 1-4. V., Gopikrishnan, P., Nunes Amaral, L.A., Meyer, M. and Stanley, H.E., 1999. Scaling of the distribution of price fluctuations of individual companies. Physical Review E 60, 6519-6529. Shreve, S.E., 2004. Stochastic Calculus for Finance II: Continuous-Time Models. Springer, New York. Shreve, S.E., 2005. Stochastic Calculus for Finance I: The Binomial Asset Pricing Model. Springer, New York. 77 Bibliography [44] Smith, V.L. , 1962. An experimental study of competitive market behaviour. Journal of Political Economy 70, 111-137. [45] Smith, V.L. , Williams, A., Bratton, W.K., and Venoni, M. , 1982. Competitive market institutions: double auctions versus sealed bid offers. Journal of American Review 72, 58-77. [46] Steinsaltz, D., 1999. Locally contractive iterated function systems. Annals of Probabil-ity 4, 546-588. [47] Townsend, R.M., 1983. Forecasting and forecast of others. Journal of Political Economy 91, 546-588. [48] Weber, P. and Rosenow, B., 2006. Large stock price changes: volume or liquidity? Quantitative Finance 6, 7-14. [49] Wooldridge, J.M., 2003. Introductory Econometrics: A modern approach 2ed. South-western, Mason, Ohio. 78 A p p e n d i x A M a i n Function of the Program In this chapter, we present the main function of the our program made with Matlab®. This does not constitute the entire program but it does give a good idea to the reader of how the program works. We remind the reader that text following the % is a comment in the Matlab® environment. function order_book_new_graphl(repetition); 7, This function i s the main function of the project. t i c '/, This function i s used to calculate the computation time. '/, Throughout the entire code, the matrices have name i n c a p i t a l l e t t e r s and the vectors name always start with a "v_". 7.7.7.7.7.7.7.7.7.7. INITIALIZATION OF THE MOST IMPORTANT PARAMETERS 7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. N = 100; '/, - Place: In the main '/, - Explanation: This i s the number of agents that w i l l be trading i n the 7, market. '/, - Ef f e c t s : see explanation '/. - Suggested values: [10,10000] M = 20; 7, - Place: In the main 7, - Explanation: This i s the number of experts f o r which the agents w i l l be 7, able f i n d a suggested value for the price the next period. '/, - E f f e c t s : see explanation 7o - Suggested values: [10;N] nu = 30; 7. - Place: In the function i n i t i a l i z a t i o n 79 Appendix A. Main Function of the Program 7. - Explanation: This parameter i s related to the horizon h of each agent. 7, - E f f e c t s : An increase of nu w i l l increase the time horizon of every '/, agent i n the model. '/, - Suggested values: [1,10] lambda = 1; 7. - Place: In the main 7. - Explanation: This parameter i s related to the rate at which orders are 7o submitted. 7. - E f f e c t s : see explanation 7o - Suggested values: [0,1] low_c = 10; 7. - Place: In the function i n i t i a l i z a t i o n 7 . - Explanation: This parameter i s the lower bound for the excess demand 7 0 parameter c. 7, - E f f e c t s : An increase of low_c w i l l increase the excess demand for every '/, agents and w i l l probably create more a c t i v i t i e s i n the market. 7o - Suggested values: [10,50] high_c = 15; 7. - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the higher bound f o r the excess demand '/, parameter c. 7o - E f f e c t s : An increase of high_c w i l l increase the excess demand for every % agents and w i l l probably create more a c t i v i t i e s i n the market. 7. - Suggested values: [low_c+5,100] low_gamma = 0.05; 7. - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the lower bound for the discount factor 7o of each agent. 7. - E f f e c t s : An increase of low_gamma w i l l increase the time horizon of the 7o agents. 7. - Suggested values: [0.01,0.5] high_gamma = 0.1; '/, - Place: In the function i n i t i a l i z a t i o n 7, - Explanation: This parameter i s the higher bound for the discount factor 7. of each agent. 7. - E f f e c t s : An increase of higfi_gamma w i l l increase the time horizon of the 80 Appendix A. Alain Function of the Program 7, agents. 7. - Suggested values: [low_gamma+0,0.99] 7. NOTE: The 2 parameters low_gamma and high_gamma have to be s t r i c t l y less 7. than 1. low_delta = 10; 7. - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the lower bound for the v o l a t i l i t y of 7, the benchmark value of every experts. 7o - E f f e c t s : An increase of low_delta w i l l increase the v o l a t i l i t y of the 7, benchmark value for each experts and w i l l probably create more 7. noise i n the model. 7. - Suggested values: [10,20] high_delta = 18; 7, - Place: In the function i n i t i a l i z a t i o n 7, - Explanation: This parameter i s the higher bound for the v o l a t i l i t y of 7, the benchmark value of every experts. 7o - E f f e c t s : An increase of high_delta w i l l increase the v o l a t i l i t y of the 7, benchmark value for each experts and w i l l probably create more 7, noise i n the model. 7o - Suggested values: [low_delta+0.5,30] low_alpha = 1; 7o - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the lower bound for the strength or the 7. speed at which the expert expect the price to go back to 7. his fundamental value. 7, - E f f e c t s : An increase of low_alpha w i l l create higher v a r i a t i o n from the 7. v a r i a t i o n between the price and the fundamental value of the 7, expert i n the c a l c u l a t i o n of the expert's recommendation. 7. - Suggested values: [1,5] high_alpha = 2; '/, - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the higher bound for the strength or the 7, speed at which the expert expect the price to go back to '/, his fundamental value. 7. - E f f e c t s : An increase of high_alpha w i l l create higher v a r i a t i o n from the 81 Appendix A. Main Function of the Program °h v a r i a t i o n between the price and the fundamental value of the '/, expert i n the ca l c u l a t i o n of the expert's recommendation. 7, - Suggested values: [low_alpha+l, 10] beta_parameter = 1; 7. - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter i s the strength of the trend chasing i n the 7. c a l c u l a t i o n of the expert performance measure. 7, - Ef f e c t s : An increase of parameter_beta w i l l create higher v a r i a t i o n from 7. the price difference i n the expert's recommendation. 70 - Suggested values: [1,5] expert_horizonl = 10; 7. - Place: In the function i n i t i a l i z a t i o n 7. - Explanation: This parameter enter i n the ca l c u l a t i o n of the expert 71 horizon and his not related to the type of the expert. 7. _ E f f e c t s : An increase of expert_horizonl w i l l make a l l the experts to 7o change t h e i r fundamental values less often. 7. - Suggested values: [5,25] expert_horizon2 = 10; 7. - Place: In the function i n i t i a l i z a t i o n 7o - Explanation: This parameter enter i n the ca l c u l a t i o n of the expert's 7. horizon and his related with fundamentalist experts. 7« - E f f e c t s : An increase of expert_horizon2 w i l l make experts with a 7, fundamentalist part to increase t h e i r time horizon, and make 7. them change t h e i r fundamental value less often. 7. - Suggested values: [1,15] expert_horizon3 = 10; 7. - Place: In the function i n i t i a l i z a t i o n '/, - Explanation: This parameter enter i n the ca l c u l a t i o n of the expert's 7. horizon and his related with c h a r t i s t experts. 7o - Ef f e c t s : An increase of expert_horizon3 w i l l make experts with a 7. c h a r t i s t part to increase t h e i r time horizon, and make 7o them change t h e i r fundamental value less often. 7o - Suggested values: [1,15] prop_fund = 0.5; 7, - Place: In the function i n i t i a l i z a t i o n 7 - Explanation: This parameter represent the proportion of pure 8 2 Appendix A. Main Function of the Program 7, fundamentalist (beta=0) within the experts. 7, - E f f e c t s : An increase of prop_fund w i l l increase the number of experts '/, that follow only fundamentalist rules. This should probably '/, reduce the appearance of bubbles and crashes. '/. - Suggested values: [0.1,0.8] prop_chart = 0.2; '/, - Place: In the function i n i t i a l i z a t i o n °/0 - Explanation: This parameter represent the proportion of pure c h a r t i s t (alpha=0) within the experts. 7, - E f f e c t s : An increase of prop_chart w i l l increase the number of experts '/, that follow only c h a r t i s t rules. This should probably '/, increase the appearance of bubbles and crashes. 7, - Suggested values: [0.1,0.5] prop_noise =0.3; % - Place: In the function i n i t i a l i z a t i o n 7, - Explanation: This parameter represent the proportion of noise trader 7, ( alpha=0 and beta=0) within the experts. 7. - E f f e c t s : An increase of prop_noise w i l l increase the noise i n the '/, model. Most l i k e l y that w i l l get the return d i s t r i b u t i o n 7 0 closer to a normal d i s t r i b u t i o n . 7. - Suggested values: [0.1,0.3] 7. NOTE: The l a s t 3 parameters are not independent of each other. In '/, p a r t i c u l a r t h e i r sum must never be higher than 1 but i t can be s t r i c k l y 7, less than one without problem. low_performance = 0.01; '/, - Place: In the function performance_measure2 7. - Explanation: This parameter i s the lowest bound at which we stop adding 7. the p r o f i t when we are c a l c u l a t i n g the performance measure 7, of each expert. The goal of t h i s parameter i s to make the '/, code faster. 7. - E f f e c t s : An increase of low_performance w i l l eventually make the code 7 . f a s t e r . 7, - Suggested values: [0.0001,1] lowest_price = 500; 7o - Place: In the function i n i t i a l i z a t i o n 7o - Explanation: This parameter represents the lowest bound for the pric e . 83 Appendix A. Main Function of the Program '/, - E f f e c t s : see explanation */, - Suggested values: [50, ??] highest_price = 1500; '/, - Place: In the function i n i t i a l i z a t i o n 7, - Explanation: This parameter represents the highest bound for the price. 7c - Ef f e c t s : see explanation 7 . - Suggested values: [lowest_price + 1000, ??] t i c k _ s i z e = 0.5; 7o - Place: In the function i n i t i a l i z a t i o n '/, - Explanation: This parameter represents the t i c k s i z e . 7. - E f f e c t s : W i l l create a bigger v a r i a t i o n i n the price and a bigger value 7o for the gap i n the order book. 7. - Suggested values: [0.5,2] st e p _ s i z e l = 1000; 7o - Place: In the main 7. - Explanation: This parameter i s related with the creation of the 7. vector_return. In a certain way these returns represent the 7« returns of agent with a long time horizon 7o - E f f e c t s : Raising i t w i l l c e r t a i n l y change the f i r s t returns graphic at 7. the end of the code. 7. - Suggested values: [50,1000] step_size2 = 1; 7. - Place: In the main 7o - Explanation: This parameter i s r e l a t i o n with the creation of the 7, vector_return. In a certain way these returns represent the 7o returns of agent with a short time horizon. '/, - E f f e c t s : Raising i t w i l l c e r t a i n l y change the f i r s t returns graphics at '/, the end of the code. '/. - Suggested values: [1,200] i n t e r v a l = 10; '/, - Place: In the main "/, - Explanation: This parameter determines on which i n t e r v a l the v o l a t i l i t y and '/, the volume w i l l be computed. '/, - E f f e c t s : Unknown - Suggested values: [5,100] 84 Appendix A. Main Function of the Program ./0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/ / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / o / ^ lag = max(step_sizel,step_size2) + 1; [AGENTS,CANCEL,EXPERTS,v_x,middle] = initialization(N,M,lowest_price,... highest.price.tick.size.nu.low.c.high.c.low.delta.high.delta,... prop_fund,prop_chart,prop_noise,low_alpha,high_alpha,beta_parameter,... expert_horizonl,expert_horizon2,expert_horizon3,low_gamma,... high_gamma); 7. The function i n i t i a l i z a t i o n i n i t i a l i z e s the matrices AGENTS,CANCEL and 7o EXPERTS as well as the value of c and the vector v_x. For more 7o information about these 3 matrices ref e r to the respective legends below. 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . LEGEND MATRIX AGENTS 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7. 7 . 7o AGENTS(a,l) = c excess demand parameter of agent a 7 . 7. AGENTS (a, 2) = gamma discount factor of agent a 7 . 7. AGENTS (a, 3) = h time horizon of agent a 7 . 7. 7. 7. AGENTS(a,4) = nu excess demand random parameter 7. 7. AGENTS(a,5) = teta rate of market p a r t i c i p a t i o n 7. 7. AGENTS(a,6) = tau timer for the cancelation i n case the agent a 7 . 7. has some l i m i t orders i n the book 7 . 7. 7. 7. NOTE: The three parameters nu, te t a and tau are time dependent and they 7 . To w i l l need to be change at every step of the main loop. 7 . 7. 7. 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 , 7 . 7 . LEGEND MATRIX CANCEL 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7. 7. 7. CANCEL(i,l) = i give the posi t i o n i n the matrix CANCEL 7 . 7. CANCEL(i,2) = n give the posi t i o n i n the order book 7 . 7. CANCEL(i,3) = n give the number of order at that p o s i t i o n 7 . 7. 7. 7. CANCEL(i,4) = 1 type of l i m i t order: buy 7 . 7. CANCEL(i,4) = 2 type of l i m i t order: s e l l 7. 7. 7. 85 Appendix A. Main Function of the Program 7. CANCEL(i,5) = a give which agent submit the order '/. •/. */. '/, CANCEL(i,6) = tau give the time l e f t before cancelation '/, y. y. '/, NOTE: The l a s t parameter tau i s time dependent and need to be modified '/, '/, at every step of the main loop. V. 7. 7:i:m:m:i:i^^ v:mm:amM:aum.v:aw. LEGEND MATRIX EXPERTS v.um:mv^:mv:am:/.,/.n •/. v. '/, EXPERTS(i.l) = d e l t a benchmark " v o l a t i l i t y " parameter '/, '/, EXPERTS(i,2) = alpha fundamentalist strength parameter '/, '/, EXPERTS(i,3) = beta c h a r t i s t strength parameter */. '/, EXPERTS(i,4) = g time horizon for the expert i '/, y. •/. '/. EXPERTS(i,5) = t timer for the modification of the benchmark '/, V. */. '/, NOTE: The l a s t parameter t i s time dependent and need to be modified at '/. 7, every step of the main loop. '/, fflfflfflfflmmfflnmfflramnmnmmfflfflfflfflxfflfflfflffln l_x = length(v_x); '/, Keep i n trac the length of the vector x v_y = translation(CANCEL,l_x,middle); '/, This function make the conversion between the matrix CANCEL and the 7, vector y. The vector y i s the vector that gives you the number of orders '/, i n the order book for each prices given by the vector x. */. FIGURE OF THE ORDER BOOK AT THE BEGINNING figure; bar(v_x,v_y,0.5); '/, Create a bar plot to represent the order book with the price on the x axis '/, and the number or order on the y axis x l a b e K'Price','FontAngle','italic'); ylabel('Number of order at each p r i c e ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; t i t l e ( ' O r d e r book at the beginning','FontWeight','bold'); p_mean = v_x(middle); p_var = 6*tick_size; v_price = p_mean + p_var*randn(l,lag); 86 Appendix A. Main Function of the Program '/, Create the i n i t i a l condition for the vector price l _ p r i c e = length(v_price); '/, Keep i n trac the length of the vector price that comes from the i n i t i a l '/, conditions. [BENCHMARK,EXPERTS] = initialization2(EXPERTS,M,lag,v_x(middle)); I n i t i a l i s a t i o n of the matrix BENCHMARK to allow a lag i n the c a l c u l of the expert p r o f i t measure. For more information about the matrix BENCHMARK '/, see the legend below. yx/x/.mnr/x/.m.yx/x/.y. LEGEND MATRIX BENCHMARK mranmmxmmmm •/. y. '/, BENCHMARK ( i , j ) This represent the benchmark of the expert i at time j */, y. y. yx/x/x/x/.y.y.yx/x/x/x/x/x/xm v_volume = zer o s ( 1 . r e p e t i t i o n ) ; '/, Vector to compute the volume of trading at each time t v_best_ask = zer o s ( 1 . r e p e t i t i o n ) ; '/, Vector to keep i n track the best ask at each time t v_best_bid = zer o s ( 1 . r e p e t i t i o n ) ; "/, Vector to keep i n track the best bid at each time t v_total_order = z e r o s ( l . r e p e t i t i o n ) ; '/, Vector to keep i n track the t o t a l number of order i n the book at each */, t ime t. average_book = zeros ( 1,length(v_y)); '/, Vector to keep i n track the average order book. AGENTS EXPERTS '/.Show the matrices AGENTS and EXPERTS at the beginning of the code. l_x = length(v_x); '/, Keep the length of the vector x. for i = 1 : 1 : r e p e t i t i o n 87 Appendix A. Main Function of the Program 7. This i s the main loop of the code v_to t a l _ o r d e r ( i ) = sum(abs(v_y)); 7. Compute the number of orders i n the book. average_book = average_book + v_y; 7« This i s used for computing the average order book. v_best_ask(i) = best_ask(v_x,v_y); */, Put the value of the best ask i n the vector best_ask v_best_bid(i) = best_bid(v_x,v_y); 7. Put the value of the best b i d i n the vector best_bid time = lag + i ; 7. Update the time value [AGENTS,CANCEL,v_y] = update.matrices(AGENTS,CANCEL,v_y,... best_bid(v_x,v_y)); '/, Update time dependent information for the matrices AGENTS and CANCEL. 7. In p a r t i c u l a r , t h i s function w i l l cancel the order that are i n the '/, order book since too long. [max_value,agent] = max(AGENTS(:,5)); */, Determine who w i l l be the next agent to submit orders [BENCHMARK,EXPERTS] = update_matrices2(BENCHMARK,EXPERTS,v_x(middle)); 7. Update the time dependent information for the matrices BENCHMARK and 7. EXPERTS. [expert.reference] = performance_measure2(AGENTS(agent,2).EXPERTS,... BENCHMARK,v_price,low_performance); '/, Return the expert with the highest performance measure and her '/, recommendation. l_p = length(v_price); 7, Give the length of vector price order_type = AGENTS(agent,1)*(reference - log(v_price(l_p))) +... sqrt(AGENTS(agent,1))*randn; 7, Determine the order sign. 88 Appendix A. Main Function of the Program 7. Creation of the excess demand for the chosen agent using the '/, reference l e v e l given by the chosen expert, if(order_type "= 0 ) excess_demand = round(AGENTS(agent,l)*(reference -log(v_price(l_p))) +... sqrt(AGENTS(agent,l))*randn); else excess_demand = round(sqrt(AGENTS(agent,1))*randn); end v_volume(i) = abs(excess_demand); 7, Put the information i n the vector volume. if(excess_demand>0) reference = exp(reference); "/, Transform the reference value i n a price value '/, Following the advice from the chosen expert, the agent expects the 7, price to goes up so she wants to submit some buy orders. [AGENTS,CANCEL,v_y,v_price] = submit_buy_order(AGENTS,CANCEL,... agent,v_x,v_y,time,excess_demand,reference,v_price,tick_size); 7, Modify AGENTS, EXPERTS, CANCEL, v_y and v_price when buy orders 7. a r r i v e . elseif(excess_demand< 0 ) reference = exp(reference); '/, Transform the reference value i n a price value 7o Following the advice from the chosen expert, the agent expects the 7, price to goes down so she wants to submit some s e l l orders. [AGENTS,CANCEL,v_y,v_price] = submit_sell_order(AGENTS,CANCEL,... agent,v_x,v_y,time,excess_demand,reference,v_price,tick_size); 7, Modify AGENTS, EXPERTS, CANCEL, v_y and v_price when s e l l orders 7. a r r i v e . else 89 Appendix A. Main Function of the Program 7, In t h i s case the agent random l i q u i d i t y demand most l i k e l y cancel 7, his demand for s e l l i n g or buying the security. It i s a b i t l i k e 7, the agent changes idea and f i n a l l y do not do anything. We s t i l l 7. need to modify the price vector. if(best_ask(v_x,v_y) ~=0 & best_bid(v_x,v_y) ~= 0) v_price = [v_price,... (v_x(best_ask(v_x,v_y)) + v_x(best_bid(v_x,v_y)))/2]; else v_price = [v_price,v_price(length(v_price))]; end end end 7 . 7 . 7 , 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . END OF THE MAIN LOOP 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . THE NEXT SECTION IS THE CREATION OF ALL THE INTERESTING GRAPHICS TL'LTL'L vxmmwayxmvtmvxaw:/. ORDER BOOK AT THE END 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . figure; bar(v_x,v_y,0.5); 7. Create a bar plot to represent the order book with the price on the x axis 7. and the number or order on the y axis x l a b e l ( ' P r i c e ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; ylabel('Number of order at each p r i c e ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; t i t l e ( ' O r d e r book at the end','FontWeight','bold'); V V V V V V V"/ V V "I "IV V V V V V V V °/ V V V V V V V V V V °/ V V V °/ V V V V V V V V V V V V V V V V"/ V V V V V vvv V"/ V V V V V V"/ °/ V V V V 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 , FIRST LOG RETURN 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 , 7 , 7 , 7 . 7 . v_log_return(l) = lo g ( v _ p r i c e ( l _ p r i c e ) ) - lo g ( v _ p r i c e ( l _ p r i c e -s t e p _ s i z e l ) ) ; f or i = l _ p r i c e + s t e p _ s i z e l : s t e p _ s i z e l : length(v_price) retur = lo g ( v _ p r i c e ( i ) ) - l o g ( v _ p r i c e ( i - s t e p _ s i z e l ) ) ; retur = retur*100; 90 Appendix A. Main Function of the Program v_log_return = [v_log_return,retur]; '/, Put the value retur in the vector return end step_sizel_str = num2str(step_sizel); mu = mean(v_log_return); va = var (v_log_return) ; k = kurtosis(v_log_return); mu_str = num2str(mu); va_str = num2str(va); k_str = num2str(k); v_log_return = abs(v_log_return); figure; [f,xi] = ecdf(v_log_return); loglog(xi,1-f); hold on; coccin = max(xi); xi2 = 1:0.01:coccin; Ioglog(xi2,power_law(xi2,3)); xlabeK'Returns in percentage','FontAngle',' italic'); ylabeK'Proportion' , 'FontAngle' , ' i tal ic ' ) ; t i t l e ( ' l og return distribution','FontWeight','bold'); hold off; f igure; normplot(v_log_return); yx/x/x/x/x/x/x/x/x/:/xm'/x/.y. SECOND LOG RETURN yxmyx/x/x/:/x/x/x/:myx/x/:/. v_log_return(l) = log(v_price(l_price)) - log(v_price(l_price -step_size2)); for i = l_price + step_size2 : step_size2 : length(v_price) retur = log(v_price(i)) - log(v_price(i - step_size2)); retur = retur*100; v_log_return = [v_log_return,retur]; '/, Put the value retur in the vector return end step_sizel_str = num2str(step_size2); mu = mean(v_log_return); va = var(v_log_return); k = kurtosis(v_log_return); mu_str = num2str(mu); va_str = num2str(va); k_str = num2str(k); 91 Appendix A. Main Function of the Program v_log_return = abs(v_log_return); figure; [ f , x i ] = ecdf(v_log_return); l o g l o g ( x i , 1 - f ) ; hold on; coccin = max(xi); xi2 = 1:0.01:coccin; loglog(xi2,power_law(xi2,3)); xlabel('Returns i n percentage','FontAngle','italic'); ylabel('Proportion','FontAngle','italic'); t i t l e ( ' l o g return distribution','FontWeight','bold'); hold o f f ; f igure; normplot(v_log_return); m m m n n n r a n m m m m f f l m f f l m r a f f l f f l f f l f f l f f l x f f l f f l f f l f f l m f f l n n n f f l f f l x r a r a n LOG RETURNS DIFFERENT STEP m m n m n n r a x x number_of_step = 1000; step = 50; figure; hold on; for j = 1 : step : number_of_step v_log_return(l) = lo g ( v _ p r i c e ( l _ p r i c e ) ) - l o g ( v _ p r i c e ( l _ p r i c e - j ) ) ; for i = l _ p r i c e + j : j : length(v_price) retur = l o g ( v _ p r i c e ( i ) ) - l o g ( v _ p r i c e ( i - j ) ) ; retur = retur*100; v_log_return = [v_log_return,retur]; end v_log_return = abs(v_log_return); [f, x i ] = ecdf(v_log_return); l o g l o g ( x i , l - f ) ; coccin = max(xi); xi2 = 1:0.01:coccin; loglog(xi2,power_law(xi2,3),'.r'); xlabel('Returns i n percentage','FontAngle','italic'); ylabel('Proportion','FontAngle','italic'); t i t l e ( ' l o g return distribution','FontWeight','bold'); end x r a m x r , r a m r a r a n n r a m r a r a r a x m r a m m r a x n r a y . x n f f l f f i x n m m m m m x m x m m FIRST RETURN GRAPHICS m m m m m m m m n v_return(l) = ((v_price(l_price) - v _ p r i c e ( l _ p r i c e - ste p _ s i z e l ) ) /.. . 92 Appendix A. Main Function of the Program v_price(l_price - step_sizel))*100; 7. Init ial isat ion of the vector return for i = l_price + step_sizel : step_sizel : length(v_price) 7. Creation of the vector return retur = (v_price(i) - v_price(i - step_sizel)) / v_price( l , i -step_sizel) ; retur = retur*100; v_return = [v_return,retur]; 7. Put the value retur in the vector return end figure; plot(v_return); x l a b e K ' T i m e ' F o n t A n g l e ' , ' i t a l i c ' ) ; ylabel('Returns in percentage','FontAngle',' italic'); step_sizel_str = num2str(step_sizel); txt = ['Evolution of the returns' blanks(2) 'Step size = ' step_sizel_str]; title(txt, 'FontWeight', 'bold'); mu = mean(v_return); va = var(v_return); k = kurtosis(v_return); mu_str = num2str(mu); va_str = num2str(va); k_str = num2str(k); figure; [f,xi] = ksdensity(v_return); 7. Create a density for the vector return p l o t ( x i , f , ' : r ' ) ; hold on; max_re = max(xi); min_re = min(xi); x = min_re-l:0.01:max_re+l; plot(x,l/sqrt((2*pi*va)).*exp((-(x-mu).~2)./(2*va))); legend('Returns distribution','Normal distribution' ,2); xlabeK'Returns in percentage','FontAngle',' italic'); ylabel( 'Proportion' , 'FontAngle' , ' i tal ic'); txt = ['Returns distribution' blanks(2) 'Step size = ' step_sizel_str blanks(2) 'mean = ' mu_str blanks(2) 'variance = ' va_str blanks(2) 'kurtosis = ' k_str]; title(txt,'FontWeight', 'bold'); hold off; Of Of Of Of 01 01 Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of Of 7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. SECOND RETURNS GRAPHICS 7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. v_return2(l) = ((v_price(l_price) - v_price(l_price - step_size2)) / . . . v_price(l_price - step_size2))*100; 7. Init ial isat ion of the vector return for i = l_price + step_size2 : step_size2 : length(v_price) 93 Appendix A. Main Function of the Program 7. Creation of the vector .return retur = ( v _ p r i c e ( i ) - v _ p r i c e ( i - step_ s i z e 2 ) ) / v _ p r i c e ( i - step_ s i z e 2 ) ; retur = retur* 1 0 0 ; v_ r e t u r n 2 = [v_ r e t u r n 2 , r e t u r ] ; 7. Put the value retur i n the vector_return end figure; p l o t ( v_ r e t u r n 2 ) ; x l a b e l ( 1 Time','FontAngle','italic'); ylabel('Returns i n percentage','FontAngle','italic'); step_ s i z e 2_str = n u m 2 s t r(step_ s i z e 2 ); txt = ['Evolution of the returns' blanks ( 2 ) 'Step size = ' s t e p_ s i z e 2 _ s t r ] ; title(txt,'FontWeight','bold'); mu = mean(v_return2); va = var(v_ r e t u r n 2 ); k = k u r t o s i s ( v_ r e t u r n 2 ) ; mu_str = num2str(mu); va_str = n u m 2 s t r(va); k_str = n u m 2 s t r(k); figure; [f,xi] = ksdensity(v_ r e t u r n 2 ) ; 7o Create a density f or the vector r e t u r n 2 p l o t ( x i , f , ' : r ' ) ; hold on; max_re = max(xi); min_re = min(xi); x = min_re-l:0.01:max_re+l; plot(x,l/sqrt ( ( 2*pi*va)).*exp((-(x-mu). ~ 2 ) . / ( 2 * v a ) ) ) ; legend('Returns distribution','Normal d i s t r i b u t i o n ' , 2 ) ; xlabel('Returns i n percentage','FontAngle','italic'); ylabel('Proportion','FontAngle','italic'); t x t = ['Returns d i s t r i b u t i o n ' blanks ( 2 ) 'Step size = ' step_ s i z e 2_str blanks ( 2 ) 'mean = ' mu_str blanks ( 2 ) 'variance = ' va_str blanks ( 2 ) 'kurtosis = ' k _ s t r ] ; title(txt,'FontWeight','bold'); hold off; V V V V V */ V */ V V */ V °/ V V V */ °/ V V V V */ */ °/ V V V V V V V */ •/ */ V V V V V V V V °/V V V V V V V V V V V V V V V V V V V V V V °/ V V V °/ V V V V 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . RETURNS OF DIFFERENT STEPS 7 . 7 . 7 . 7 , 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 . 7 , 7 . 7 . figure; [f,xi] = ksdensity(v_ r e t u r n 2 ) ; 7. Create a density f or the vector r e t u r n 2 p l o t ( x i . f ) ; hold on; [f,xi] = ksdensity(v_return); 7, Create a density f or the vector return p l o t ( x i , f , ' :r') ; legendCStep Size = 1 ' , 'Step Size = 2 0 ' ) ; xlabel('Returns i n percentage','FontAngle','italic'); ylabeK'Proportion','FontAngle','italic'); t i t l e ( ' R e t u r n s i n Percentage','FontWeight','bold'); 94 Appendix A. Main Function of the Program y.r/////.7.7.7.7.1/.7.7,7.'/.t/.'/.7.7.y.t/.7.7.7.n7.1/.7. PRICE GRAPHIC 7.7.7.7.7.7.7.7.7,7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. v_price_graph = v_pri c e ( l _ p r i c e : l e n g t h ( v . p r i c e ) ) ; figure; 7. Open a new graphic window plot(v_price_graph); 7. Make the plot of the price process t i t l e ( ' E v o l u t i o n of the price','FontWeight','bold'); 7. Put a t i t l e on a graphic xlabel('"Time"','FontAngle','italic'); y l a b e l ( ' P r i c e ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; a x i s ( [ - i n f inf 500 1500]); box off; hold off; lXIXIXIXIXIXI'l'lil'l*l>l<l'l'l>lsl'l*l*l'L BENCHMARK PATH 7XIXIXIXIXIXIXIXI'l>ltl'l'l'l>l>l>l'l>l>l'l'l> figure; plot(BENCHMARK(1,:)); t i t l e ( ' T y p i c a l fundamental value path for a fundamentalist','FontWeight','bold'); x l a b e K'Time','FontAngle','italic'); ylabel('Fundamental value','FontAngle','italic'); 7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. VOLATILITY AND VOLUME 7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7.7. v a r l = r e p e t i t i o n / i n t e r v a l ; v_volume2 = zeros(1,varl); v _ v o l a t i l i t y = zeros(1,varl); for i = 1 : 1 : varl-1 v_volume2(i) = sum(v_volume(i*interval:i*interval+interval)); v _ v o l a t i l i t y ( i ) = var ( v _ p r i c e ( l _ p r i c e + i * i n t e r v a l : l _ p r i c e + i * i n t e r v a l + . . . i n t e r v a l ) ) ; end figure; subplot(2,1,1); plot(v_volume2); t i t l e ( ' T r a d i n g volume','FontWeight','bold'); x l a b e K'Time','FontAngle','italic'); ylabel('Trading volume','FontAngle','italic'); subplot(2,1,2); p l o t ( v _ v o l a t i l i t y ) ; t i t l e ( ' V o l a t i l i t y ' , ' F o n t W e i g h t ' , ' b o l d ' ) ; xlabel('Time','FontAngle','italic'); y l a b e K ' V o l a t i l i t y ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; t e s t l = 95 Appendix A. Main Function of the Program corrcoef(v_volume2',v_volatility') fflfflramxfflfflmnmm BID AND ASK SPREAD yx/x/.y.y.yx/x/.y.yx/x/x/.yx/x/. v_spread = v_best_ask - v_best_bid; v_spread_graph = v_spread(1:interval:length(v_spread)); figure; subplot(2,1,1); plot(v_spread_graph); t i t l e ( ' B i d and Ask Spread','FontWeight','bold'); xlabeK'Time','FontAngle','italic'); ylabeK'Bid and Ask Spread','FontAngle','italic'); subplot(2,1,2); p l o t ( v _ v o l a t i l i t y ) ; t i t l e ( ' V o l a t i l i t y ' , ' F o n t W e i g h t ' , ' b o l d ' ) ; xlabeK'Time','FontAngle','italic'); y l a b e K ' V o l a t i l i t y ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; test2 = corrcoef(v_spread_graph',v_volatility') v_spread_graph2 = zeros(1,varl); f or i = 1 : 1 : varl-1 v_spread_graph2(i) = sum(v_spread(i*interval:i*interval+interval)); end figure; subplot(2,1,1); plot(v_spread_graph2); title('Cummulative Bid and Ask Spread','FontWeight','bold'); x l a b e K'Time','FontAngle','italic' ) ; y l a b e K'Bid and Ask Spread','FontAngle','italic'); subplot(2,1,2); p l o t ( v _ v o l a t i l i t y ) ; t i t l e C V o l a t i l i t y ' , 'FontWeight', 'bold'); xlabel('Time','FontAngle','italic'); y l a b e K ' V o l a t i l i t y ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; test3 = corrcoef(v_spread_graph2',v_volatility') test4 = corrcoef(v_spread_graph2 ( l:length(v_spread_graph2)-l)',... v _ v o l a t i l i t y ( 2 : l e n g t h ( v _ v o l a t i l i t y ) ) ' ) y.y.y.y.y.y/.y;/.y.y:/.y.y.y,y.y.y,y,y.y.y.y.y.y.y.y.y.y.y.y. RETURN AND VOLATILITY y.y.yx/x/x/.y.yx/x/x/x/x/. figure; subplot(2,1,1); plot(v_return); xlabeK'Time','FontAngle','italic'); ylabeK'Returns i n percentage','FontAngle','italic'); step_size2_str = num2str(step_size2); tx t = ['Evolution of the returns' blanks(2) 'Step size = ' s t e p _ s i z e l _ s t r ] ; title ( t x t,'FontWeight','bold'); subplot(2,1,2); p l o t ( v _ v o l a t i l i t y ) ; t i t l e C V o l a t i l i t y ' , 'FontWeight' , 'bold') ; 96 Appendix A. Main Function of the Program x l a b e K ' Time','FontAngle','italic'); y l a b e K ' V o l a t i l i t y ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; v_return_spec = v_return(l:length(v_return)-1); r e t u r n _ v o l a t i l i t y = corrcoef ( a b s(v_return_spec),v_volatility) nyx/x/x/.r/.my.ny.m rannranrarafflramxra VOLUME AND PRICE mmmmmy.mnmn figure; subplot(2,1,1); plot(v_volume2); t i t l e ( ' T r a d i n g volume','FontWeight','bold'); xlabel('Time','FontAngle','italic'); y l a b e K'Trading volume','FontAngle','italic'); subplot(2,1,2); plot(v_price_graph); t i t l e ('Evolution of the price','FontWeight','bold'); '/, Put a t i t l e on a graphic xlabel('"Time"','FontAngle','italic'); y l a b e K'Price','FontAngle','italic'); a x i s ( [ - i n f inf 500 1500]); box off; hold off; v_price_graph_spec = v_price_graph(l:interval:length(v_price_graph)); v_volume_spec = v_volume2(1:length(v_volume2)-1); volume_price = corrcoef(v_volume_spec,v_price_graph_spec) y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y.y. SPREAD AND PRICE yx/x/.yx/.yx/x/.y.yx/x/.y.y.y.y.y.y//. figure; subplot(2,1,1) ; plot (v_price_graph); Make the plot of the price process t i t l e ('Evolution of the price','FontWeight','bold'); '/, Put a t i t l e on a graphic x l a b e K'"Time"','FontAngle','italic'); y l a b e K'Price','FontAngle','italic'); a x i s ( [ - i n f inf 500 1500]); box off; hold off; subplot(2,1,2); plot(v_spread); t i t l e ( ' B i d and Ask Spread','FontWeight','bold'); xlabel('Time','FontAngle','italic'); y l a b e K'Bid and Ask Spread','FontAngle','italic'); v_spread_spec = v_spread(l:length(v_spread)-10); price_spread = corrcoef(v_price_graph,v_spread_spec) ot ot 0/ ot oi ot ot 01 ot ot 01 ot 01 0101 01 ot ot 01 01 ot01 01ot 01 ot 0/ 0/ 0/ 0/ 0/ 0/ HI OI 010101 ot 01010101010101010101010101010101010101010101 ot 01 ot ot ot ot ot 01 ot 010101010101 to 10 lo to lo lo to to lo lo to lo to lo lo lo lo to /o/o lo 10 lo lo to /o/o 10 to to 1010 loloh 10 to 1010 to to 10 to 10/o/o 101010/o/o to 10/ 97 Appendix A. Main Function of the Program fflranramfflfflfflfflnm AVERAGE ORDER BOOK nmxraxmmmmn average_book = average_book./repetition; figure; plot(v_x,average_book); title('Average order book','FontWeight','bold'); x l a b e l ( ' P r i c e ' , ' F o n t A n g l e ' , ' i t a l i c ' ) ; ylabel('Order book','FontAngle','italic'); °/ V V V V V V"/ V V V V V V V V V V V °/ V °/ V V V V V V V V °/ °/ V V V V V V V V V V °/ V VVV V V V V V V V V V V V"/ V "/ V V V V V V V V V V V */ V V /o A/o/o/o/o/fl/o/o/o/o/o/o/o/o/o/o/o/o/o/o/o^ ^ yx/x/x/x/x/x/x/x/,yx/x/. VOLATILITY AND NUMBER OF ORDERS yx/x/x/x/x/x/x/x/x/.y. figure; hold on; subplot(2,1,1); plot(v_total_order(1000:length(v_total_order))); subplot(2,1,2); p l o t ( v _ v o l a t i l i t y ( 1 0 0 : l e n g t h ( v _ v o l a t i l i t y ) ) ) ; v_total_order2 = z e r o s ( l , v a r l ) ; for i = 1 : 1 : varl-1 v_total_order2(i) = sum(v_total_order(i*interval:i*interval+interval)); end v_total_order2_special = v_total_order2(100:length(v_total_order2)); v _ v o l a t i l i t y _ s p e c i a l = v _ v o l a t i l i t y ( 1 0 0 : l e n g t h ( v _ v o l a t i l i t y ) ) ; number_volatility = corr c o e f ( v _ t o t a l _ o r d e r 2 _ s p e c i a l , v _ v o l a t i l i t y _ s p e c i a l ) toe "/, End of the time counter vx/x/x/x/x/x/x/x/x/x/.y, RESULTS FROM THE CORRELATION yx/x/x/x/x/x/x/x/x/x/x/. '/. t e s t l = •/. '/, 1.0000 0.4375 '/. 0 .4375 1. 0000 y. '/. test2 = y. '/. 1.0000 0.2151 */. 0.2151 1.0000 98 Appendix A. Main Function of the Program 7. 7. test3 = 7. */. 1.0000 0.4099 •/. 0.4099 1.0000 y. y. */. test4 = y. '/. 1.0000 0.3261 */, 0.3261 1.0000 y. '/, return_volatility = •/. */. 1.0000 0.4876 '/, 0.4876 1.0000 '/. '/. '/, volume_price = y. '/. 1.0000 -0.0043 */. -0 .0043 1.0000 •/. y. */, price_spread = y. y. I.OOOO - 0 . 0 0 6 1 y. - 0 . 0 0 6 1 i.oooo •/. 7 number_volatility = •/. '/. 1.0000 -0.4613 '/. -0.4613 1.0000 99 A p p e n d i x B List of Other Functions In this appendix, we present a list and a brief description of the different functions. In section B . l we present the functions that are used to produce the different figures of this thesis. In the section B.2 we present the other functions used by the main function presented in A. B . l How to Produce the Figures . Figures 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.10, 2.11, 2.12, 2.13, 2.14, 2.15, 3.1, 3.2, 3.3 and 3.4 were created using the function graphique. • Figures 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8, 4.9, 4.16, 4.17, 4.18, ??, 4.20 and 4.22 were created using the function order book new graphl. • Figure 4.10 was created using the function dependence lambda. • Figure 4.11 was created using the function dependence tick size. • Figure 4.12 was created using the function dependence time horizon. • Figures 4.13, 4.14 and 4.15 were created using the function stationary distribution 1. • Figures 4.23 and 4.24 were created using the function stationary distribution final. B.2 Other Functions • Function best ask: This function uses the vector x and y to return the indices of the best ask price. • Function best bid: This function uses the vector x and y to return the indices of the best bid price. • Function initialization: This function initialize the matrices AGENTS,CANCEL and EXPERTS as well as the value of middle and the vector x. • Function initialization: This function create some initial condition for the vector benchmark. 100 Appendix B. List of Other Functions • Function matrix search: This function search for which line in the matrix CANCEL there are some orders that correspond to the number position in book. • Function order book newl: This function is a faster version of the main function order book new graphl that do not reproduce the figures of the main function. It is used by the functions dependence lambda, dependence tick size, dependence time horizon and stationary distribution 1. • Function order book new graphl: This is the main function of the program. • Function performance measure2: This function calculate the performance measure for each expert using the discount factor of the agent that will trade in the next period. • Function submit buy order: This function is the modification of the order book when the agent submit some buy orders. It can be either some market buy orders or some limit buy orders. • Function submit sell order: This function is the modification of the order book when the agent submit some sell orders. It can be either some market sell orders or some limit sell orders. • Function translation: This function find back the vector y when you give it the matrix CANCEL. • Function update matrices: This is the function that update all the time dependent information for the matrix AGENTS and for the matrix CANCEL. • Function update matrices2: This is the function that update all the time dependent information for the matrices BENCHMARK and EXPERTS. 101 Appendix C Statistical Tests In this appendix, we present in more details the results of our statistical tests. C l Converting the Data Unfortunately, Matlab® does not provide any function to perform the KPSS test. The first thing we need to do is then to save the our results in Matlab® and then load them in R to perform the KPSS test. Here are the necessary commands to execute perform these tasks. IN MATLAB: save filename -asc i i v_price '/, This command save the vector v_price in a filename in ASCII format IN R: price <- scan("filename") 7. Load the data from filename price <- as.ts(price) 7, Transform the price data for the application of the KPSS test test <- KPSS.test(price) 7. Perform the KPSS test test 7. Show the results of the KPSS test C.2 Results Here are the presentation of the results we obtain from the tests. For the price: KPSS test Null hypotheses: Level stationarity and stationarity. 102 Appendix C. Statistical Tests Alternative hypothesis: Unit root. Statistic for the null hypothesis of level stationarity: 0.301 p-value: 0.10 0.05 0.025 0.01 C r i t i c a l values: 0.347 0.463 0.574 0.739 For the returns: KPSS test Null hypotheses: Level stationarity and stationarity. Alternative hypothesis: Unit root. Statistic for the null hypothesis of level stationarity: 0.097 p-value: 0.10 0.05 0.025 0.01 C r i t i c a l values: 0.347 0.463 0.574 0.739 In both cases, we cannot reject the null hypothesis HQ because the test statistic is smaller than all the critical values. We do note a significant difference between the test statistic for the price 0.301 and the test statistic for the returns 0.097. This means that it is harder to not reject H0 for the price than for the returns. In fact, while the returns do not fail the test of stationarity for a very small number of iterations of our program (around 5000), we need to do at least 50 000 iterations to obtain a valid test for the price. 103
- Library Home /
- Search Collections /
- Open Collections /
- Browse Collections /
- UBC Theses and Dissertations /
- A study of financial markets with heterogeneous agents
Open Collections
UBC Theses and Dissertations
Featured Collection
UBC Theses and Dissertations
A study of financial markets with heterogeneous agents L'Espérance, Bruno 2007
pdf
Notice for Google Chrome users:
If you are having trouble viewing or searching the PDF with Google Chrome, please download it here instead.
If you are having trouble viewing or searching the PDF with Google Chrome, please download it here instead.
Page Metadata
Item Metadata
Title | A study of financial markets with heterogeneous agents |
Creator |
L'Espérance, Bruno |
Publisher | University of British Columbia |
Date Issued | 2007 |
Description | In this thesis, we present a model of a financial market with many heterogeneous agents in a continuous double auction market organization. We introduce the different concepts related to continuous double auction and electronic limit order book. We then construct a financial market model with heterogeneous agents that are using this electronic order book to trade. At each time, the next agent to trade is chosen independently of others according to a Poisson process. Each agent will decide to buy or to sell the stock according to the recommendation of a financial expert. These recommendations represent the expert expected price of the stock for the next period. There are three types of financial experts: the noise traders, the fundamentalist traders and the chartist traders. The recommendations from the noise traders are random, the recommendations from the fundamentalists are based on some fundamental value of the stock price while the recommendations of the chartists are form using some extrapolatory or contrarian rules. The agents are choosing the financial expert by comparing each of them using a performance measure. In our case, they compare a discounted sum of past profits their recommendation would have generated. Once the financial expert is determined, the agent forms her excess demand and then executes her trade according to the sign of her excess demand. Finally, we present numerical results from the simulation of this model and compare them with previously found empirical results. Some interesting results include the relation between the volatility of the stock and the trading volume, the bid and ask spread and the stock returns, the analysis of the effects of the variation of some important parameters like the tick size, the market activity and the level of patience of the agents, the analysis of the effects of the chartist traders on the return and price distributions and the comparison of the tail of the return distribution with a power-law distribution. The most important result is the suggestion of the existence and uniqueness of a unique stationary distribution for the price process. |
Genre |
Thesis/Dissertation |
Type |
Text |
Language | eng |
Date Available | 2011-03-02 |
Provider | Vancouver : University of British Columbia Library |
Rights | For non-commercial purposes only, such as research, private study and education. Additional conditions apply, see Terms of Use https://open.library.ubc.ca/terms_of_use. |
DOI | 10.14288/1.0080446 |
URI | http://hdl.handle.net/2429/31885 |
Degree |
Master of Science - MSc |
Program |
Mathematics |
Affiliation |
Science, Faculty of Mathematics, Department of |
Degree Grantor | University of British Columbia |
Campus |
UBCV |
Scholarly Level | Graduate |
AggregatedSourceRepository | DSpace |
Download
- Media
- 831-ubc_2007-0477.pdf [ 4.2MB ]
- Metadata
- JSON: 831-1.0080446.json
- JSON-LD: 831-1.0080446-ld.json
- RDF/XML (Pretty): 831-1.0080446-rdf.xml
- RDF/JSON: 831-1.0080446-rdf.json
- Turtle: 831-1.0080446-turtle.txt
- N-Triples: 831-1.0080446-rdf-ntriples.txt
- Original Record: 831-1.0080446-source.json
- Full Text
- 831-1.0080446-fulltext.txt
- Citation
- 831-1.0080446.ris
Full Text
Cite
Citation Scheme:
Usage Statistics
Share
Embed
Customize your widget with the following options, then copy and paste the code below into the HTML
of your page to embed this item in your website.
<div id="ubcOpenCollectionsWidgetDisplay">
<script id="ubcOpenCollectionsWidget"
src="{[{embed.src}]}"
data-item="{[{embed.item}]}"
data-collection="{[{embed.collection}]}"
data-metadata="{[{embed.showMetadata}]}"
data-width="{[{embed.width}]}"
data-media="{[{embed.selectedMedia}]}"
async >
</script>
</div>
Our image viewer uses the IIIF 2.0 standard.
To load this item in other compatible viewers, use this url:
https://iiif.library.ubc.ca/presentation/dsp.831.1-0080446/manifest