University of Amsterdam Faculty of Economics and Business

Master’s thesis

Boids Algorithm in Economics and Finance A Lesson from Computational Biology

Author: Pavel Dvoˇr´ak Supervisor: Cars Hommes Second reader: Isabelle Salle Academic Year: 2013/2014 Declaration of Authorship

The author hereby declares that he compiled this thesis independently, using only the listed resources and literature. The author also declares that he has not used this thesis to acquire another academic degree.

The author grants permission to University of Amsterdam to reproduce and to distribute copies of this thesis document in whole or in part.

Amsterdam, July 18, 2014 Signature Bibliographic entry

Dvorˇak´ , P. (2014): “Boids Algorithm in Economics and Finance: A Les- son from Computational Biology.” (Unpublished master’s thesis). Uni- versity of Amsterdam. Supervisor: Cars Hommes.

Abstract

The main objective of this thesis is to introduce an ABM that would contribute to the existing ABM literature on modelling expectations and decision making of economic agents. We propose three different models that are based on the boids model, which was originally designed in biology to model flocking be- haviour of . We measure the performance of our models by their ability to replicate selected stylized facts of the financial markets, especially those of the stock returns: no autocorrelation, fat tails and negative skewness, non- Gaussian distribution, volatility clustering, and long-range dependence of the returns. We conclude that our boids-derived models can replicate most of the listed stylized facts but, in some cases, are more complicated than other peer ABMs. Nevertheless, the flexibility and spatial dimension of the boids model can be advantageous in economic modelling in other fields, namely in ecological or urban economics.

JEL Classification C15, C51, C52, C63, Keywords ABM, heterogeneous agents, behavioural mod- els, herding, boids model, stylized facts

Author’s e-mail [email protected] Supervisor’s e-mail [email protected] Contents

List of Figures vi

1 Introduction1 1.1 Perfect rationality paradigm...... 1 1.2 Literature review...... 3 1.3 Stylized facts...... 4 1.4 Research questions...... 8

2 The original boids model 10 2.1 Agent interaction in the boids model...... 10

3 The baseline model 12 3.1 Description of the baseline model...... 12 3.1.1 Forecasting rules...... 12 3.1.2 Price updating mechanism...... 13 3.2 Merging the asset-pricing and boids model...... 14 3.3 Simulation of the baseline model...... 16 3.4 The baseline model and the stylized facts...... 19 3.5 Sensitivity analysis...... 22

4 The extended model 27 4.1 Description of the extended model...... 27 4.1.1 Forecasting rules...... 27 4.1.2 Price updating mechanism...... 27 4.1.3 Roulette selection of the forecasting rules...... 28 4.2 Simulation of the extended model...... 29 4.3 The extended model and the stylized facts...... 31

5 The limit-order model 35 5.1 Description of the limit-order model...... 35 Contents v

5.1.1 Forecasting rules...... 35 5.1.2 Pricing mechanism...... 36 5.2 Simulation of the limit-order model...... 38 5.3 Limit-order model and the stylized facts...... 40

6 Concluding discussion 44

Bibliography 54

A AppendixI List of Figures

1.1 NASDAQ price and log-returns...... 5 1.2 Autocorrelation in NASDAQ log-returns...... 6 1.3 Semi-log plot of NASDAQ autocorrelation of absolute log-returns7

2.1 Three main forces governing agents’ behaviour...... 11 2.2 Decision tree of an agent in the boids model...... 11

3.1 Decision tree of an agent in the baseline model...... 16 3.2 The baseline model under the default parameter values..... 17 3.3 Example of agents scattered in the space...... 18 3.4 ACF and PACF of returns, baseline model...... 20 3.5 Power law and exponential decay fits for autocorrelation in ab- solute returns, baseline model...... 21 3.6 Returns and fractions of trend followers under different C .... 24 3.7 Fraction of trend followers under different crit. probability... 25 3.8 Repuls. ratios for different observable distances...... 25 3.9 Ratio of trend followers for different herding thresholds..... 26

4.1 The extended model under the default parameter values.... 30 4.2 ACF and PACF of returns, extended model...... 32 4.3 Power law and exponential decay fits for autocorrelation in ab- solute returns, extended model...... 33

5.1 The limit-order model under the default parameter values.... 39 5.2 ACF and PACF of returns, extended model...... 41 5.3 Power law and exponential decay fits for autocorrelation in abs. returns, limit-order model...... 42

A.1 Gaussian kernel density estimate of NASDAQ log-returns.....I A.2 The probability function for various values of beta...... II List of Figures vii

A.3 Kernel density estimate of the returns, all models...... III A.4 Fitnesses under different C, baseline model...... III A.5 Decay speed of the lagged returns in the extended model....IV Chapter 1

Introduction

1.1 Perfect rationality paradigm

Until recently, the mainstream microeconomic theory was based on a repre- sentative, perfectly rational agent. Under this assumption, the behaviour of the whole population is easily deducible from the behaviour of an individual. Furthermore, the mainstream microeconomic theory assumes that agents have access to all relevant information and are endowed with strong enough compu- tational and intellectual skills to be able to evaluate this information and make an economic decision. Intuitively, these assumptions are too strong to hold in reality. Not only agents are not homogeneous in their preferences (so that the idea of a representative agent is misleading) but, more importantly, they do not have the necessary skills to process and evaluate all the information. In other words, agents are only boundedly rational (Simon, 1962). Fama(1970) translated the full rationality paradigm into financial markets via the Efficient Market Hypothesis (EMH). Under EMH, the asset prices already reflect all relevant information and there is no room for cost-free arbitrage. In other words, under EMH, the only possible observable price is the fundamental price of the asset, otherwise any difference would be exploited by the rational traders, driving the price back to its fundamental value. However, as already pointed out by Keynes(1936, p. 147) in the early days, if one is aware that the rest of market participants do not behave rationally, there is no need to look for the fundamental value of an investment or an asset in question. The fundamental value is not important if it is unknown or not accounted for by the irrational market participants. It is more important to outwit these irrational traders (often called noise traders, after Kyle 1985) by 1. Introduction 2 better forecasting the future market sentiment. The presence of irrational agents contributed to a new wave of literature on the heterogeneity of agents that also accounts for their limited intellectual capabilities, as opposed to the sacred assumption of full rationality. Eventually, this gave rise to the behavioural, agent-based approach of modelling preferences, expectations and decision making of agents. A common thread through the whole agent-based model (ABM) literature is the focus on simple heuristics rules on behalf of the agents. Unlike in the utility- maximisation problem, agents follow simple decision-making rules that require less knowledge and intellectual ability. As elaborated in Section 1.2, there is strong experimental evidence that real subjects do follow such simple heuristics. Inclination towards unsophisticated rules was also confirmed by psychological experiments – see, for example, the widely cited paper of Kahneman & Tversky (1973). However simplistic the behavioural rules are, they often lead to surprisingly rich and complex macroscopic dynamics. The interaction in the behavioural agent-based model can thus be viewed as a complex system, in the sense of Simon(1978), in which the sum of individual particles of the system does not give a correct picture of the behaviour at the global scale. There is a myriad of applications of ABMs in economics. As we shall see below, most ABMs focus on one particular segment of the economy – financial markets, modelling macroeconomic variables, banking sector, industrial pro- duction or foreign trade flows. The ultimate goal, at least according to Farmer & Foley(2009), is to design a broad agent-based model that would simulate behaviour of the complete economy, including government sector (taxes, so- cial transfers, expenditures), private sector (household consumption, savings), financial and banking sector (lending and borrowing, investments), and in- ternational trade flows. Such model could theoretically replace the outdated DSGE models and historical data fitting to better predict the movements in the economy and yield more relevant policy measures. As of now, however, such holistic, integrated models do not yet exist. The measurable advantage of many ABMs is that they, unlike the perfect rationality models, are able to replicate many of the so-called stylized facts – frequently recurring statistical properties that are common to various markets and economic processes such as financial markets, foreign exchange markets or time series of macroeconomic variables. In the following section, we review the literature on the ability of ABMs to replicate stylized facts common to some 1. Introduction 3 of these markets while, in this thesis, we mainly focus on stylized facts of the financial markets.

1.2 Literature review

In this section we discuss the core literature on ABMs and replication of the stylized facts. In particular, we first discuss the stylized facts in finance (as their replication is the main point of this thesis) and then proceed to ABMs and stylized facts in experimental economics, microeconomics and macroeconomics. Bollerslev et al. (1992); Brock & De Lima(1995); Gopikrishnan et al. (2000) describe some of the stylized facts in finance while Cont(2001) presents a coherent list and discussion of all the main stylized facts found in financial markets. There have been various attempts to design an ABM that would consistently replicate stylized facts in financial markets. Hommes(2006) and LeBaron(2006) provide thorough surveys of (heterogeneous) ABMs in economics and finance, showing the models as complex adaptive systems with highly non- linear dynamics. We are also witnessing growing popularity of the Genetic Algorithm (GA) models, first introduced by Holland(1975). Genetic algorithms are different from the usual strategy selection processes in that they allow for creation of new strategies that were not part of the initial strategy set. Duffy(2006) gives a solid introduction to theory behind and programming of genetic algorithms in economics. GA examples include Lux & Schornstein(2003), who seek to explain stylized facts of the exchange markets with a genetic algorithm model, while Arifovic(1995) studies the GA-based decision rules in the overlapping generations model and compares the results with the experiments with human subjects. At last, Arifovic(2000) applies the genetic algorithms to investigate stability of equilibria in macroeconomics and explains equilibrium selection and non-rational evolutionary dynamics. There is also a branch of the experimental literature based on ABMs. Heemei- jer et al. (2009) report on forecasting rules of participants in a decision making experiment and clearly identify the difference between price forecasting in mar- kets with negative feedback (e.g. market for non-storable commodities) and positive feedback (e.g. any speculative market). As an extension, Bao et al. (2014) analyse the difference in price dynamics when participants used succes- sively three different forecasting rules – forecasting price only, quantity only or both at the same time. Arifovic & Ledyard(2012) also design an evolutionary 1. Introduction 4 learning model that would replicate five most recurrent stylized facts found in the experimental data on Voluntary Contributions Mechanism (VCM) and also provide economic theory to support these stylized facts. There are also numerous examples of ABM application in macroeconomics. De Grauwe(2012) introduces a macroeconomic agent-based model with im- perfect information that would account, contrary to standard DSGE baseline models, for the recurrent booms and busts – or of extreme upward or downward movements in the economy – leading to highly peaked and non- normal distributions of macro variables. Dosi et al. (2013) present a Keynesian ABM that models relation between the income distribution and fiscal policies. The model is designed to account for some macroeconomic commonly observed phenomena – long periods of un- employment during recessions or incessant output fluctuations – and has direct policy implications. In this thesis we present an agent-based model, called the boids model, that, we believe, will make a solid contribution to the family of ABMs in finance. From the outset, the boids model, originated in biology, has the desirable properties of an ABM for financial application – herding tendencies of the agents, phase transitions upon reaching a certain threshold, and many possibilities for setting the behavioural rules.

1.3 Stylized facts

As mentioned above, we are mainly interested in financial stylized facts – statis- tical properties of price variations that are common to a wide range of financial markets. Before attempting to replicate the stylized facts by our model, we illustrate their presence on the National Association of Securities Dealers Au- tomated Quotations (NASDAQ) financial index.1 Cont(2001) lists 11 most flagrant stylized facts including fat tails and neg- ative skewness of the return distribution, no or negligible autocorrelation in the levels of returns, volatility clustering, and slow decay of autocorrelation in absolute returns. The main benchmark for evaluating performance of our models is based on how well they are able to replicate the selected stylized facts in the returns generated by the models themselves.

1The choice of NASDAQ is not critical, other indexes such as S&P 500 or Nikkei exhibit similar features, as we have confirmed ourselves. 1. Introduction 5

Before presenting the boids model in more detail, we first illustrate the presence of the stylized facts in real financial data. We have chosen NASDAQ stock log-returns over last 30 years, plotted in Figure 1.1 and summarized in Table 1.1.

5000

4000 0.10 0.05 3000 0.00 2000 -0.05 1000 -0.10 0 1990 2000 2010 1990 2000 2010

(a) NASDAQ stock prices (b) NASDAQ log returns

Figure 1.1: NASDAQ price and log-returns rt development

Var Mean Stdev Min Max Skewn. Kurt. nobs prices 1583.203 1065.742 225.3 5048.62 0.524 2.483 7654 log rets 0.000 0.014 −0.120 0.133 −0.237 11.135 7653

Table 1.1: Summary statistics for NASDAQ stock prices and log re- turns

Kurtosis and skewness The summary statistics in Table 1.1 already suggest asymmetry in gain/losses distribution (negative skewness, i.e. extreme negative values are more likely than the positive ones) and high proba- bility of extreme returns in general (excess kurtosis of 8.135).

Non-normality The non-normality of the return distribution can be formally tested by the Jarque-Bera skewness-kurtosis test (see Jarque & Bera, 1980; D’agostino et al., 1990). In case of the NASDAQ log-returns, nor- mality is strongly rejected with p-value 0.0000. The Gaussian kernel density estimate of the empirical density with the plugin of Silverman (1986) bandwidth plug-in estimate is plotted in Figure A.1. For com- pleteness, the formula for Silverman’s plug-in estimate is also included in the appendix (see Equation A.1). 1. Introduction 6

Autocorrelation in rt The financial returns usually show no or little sign of day-to-day dependence. In presence of autocorrelation, the returns would

be easily predicted and exploited. The autocorrelation in rt is plotted in Figure 1.2. Even though some lags appear to be significant, there is no clear rapidly decaying autocorrelation pattern and, as a whole, the autocorrelations seem to be disorderly. The 95% confidence intervals were computed using the Bartlett’s formula for MA(q) processes (see Brockwell & Davis(2002) for details).

0.05

0.00

-0.05

0 50 100 150 lag

Figure 1.2: Autocorrelation in NASDAQ log-returns rt

Autocorrelation in |rt| Similarly, it was observed (Cont et al., 1997) that the financial returns exhibit signs of long-range dependency, measured by the slow decay of autocorrelation in absolute returns. In particular, the autocorrelation in absolute returns can be roughly fitted by a power-law function in the presence of long-range dependency. For comparison, we also estimate the exponential decay fit function to see whether it provides better fit than the power-law function (exponential decay is only a sign of short-term dependency). Following notation of Kantelhardt(2009), we define the power-law and exponential fit functions as in Equation 1.1.

A B C (l) = C (l) = (1.1) P lα E exp(lβ) where A, α, B and β are parameters to be estimated, l is the lag of the autocorrelation, and subscripts P and E stand for power-law and 1. Introduction 7

exponential fits, respectively. For a more formal definition of the long- range dependency, see Cont(2005, p. 4).

Figure 1.3 shows the autocorrelation function of NASDAQ absolute log- returns for l = 150 lags and corresponding power-law and exponential fit parameters. We see that for lower lags the autocorrelation decays rather at exponential rate but seems to decay slower for lags l ' 120.

0.30

0.20 A = 0.378, Α = 0.141 B = 0.311, Β = 0.00454 l 20 40 60 80 100 120 140

Figure 1.3: Semi-log plot of NASDAQ autocorrelation of absolute log- returns for 150 lags with power-law (dashed) and expo- nential (dot-dashed) fit functions, parameter values in- cluded

Volatility clustering underlies the observation that time periods with high volatility tend to cluster together. We try to uncover this phenomenon via estimating Generalized Autoregressive Conditional Heteroskedastic- ity (GARCH) effect (Engle, 1982; Bollerslev, 1986), for which we also spec- ify the mean equation. The Autoregressive Moving Average (ARMA)(1,1)- Threshold GARCH (TGARCH)(1,1) results are summarized in Table 1.2. We see that there is a strong statistical evidence for the effect of past squared returns (the Autoregressive Conditional Heteroskedasticity (ARCH) term L.arch) and for autoregressive volatility term L.garch. The mean of the log-returns follows the ARMA(1,1) process, suggesting correlation between today and yesterday’s returns.2

2The GARCH effect was only present in the first lag, ARCH up to the second lag. In the mean equation, the AR and MA terms are significant only in the first lag. The threshold term is significant for any number of (G)ARCH lags. 1. Introduction 8

ARMA(1, 1)-TGARCH(1, 1)

dep var: NASDAQ log-rets rt cons 0.000415∗∗ (2.34) ARMA L.ar 0.952∗∗∗ (30.91) L.ma −0.950∗∗∗ (−32.87) ARCH L.arch 0.0850∗∗∗ (3.84) L.tarch −0.125∗∗∗ (−5.58) L.garch 0.886∗∗∗ (44.09) cons 0.00000284∗∗∗ (3.70) t-statistics in parentheses. Heteroskedasticity-robust standard errors used * p < .1, ** p < .05, *** p < .01

Table 1.2: ARMA(1, 1)-TGARCH(1, 1) model for NASDAQ log-rets

1.4 Research questions

The point of this thesis is to introduce a behavioural model, called the boids model, originally conceived in biology for the purposes of computer simulation of flocking. The original biological model is described in more detail in Chapter 2. In Chapter 3 we present the first application of the boids model in economics and finance, the baseline model, and we evaluate its performance by how well it reproduces the stylized facts in finance. In Chapter 4, we describe the first extension of the baseline model, allowing for much more heterogeneity among agents and in the strategy selection. We also compare the performance of the extended model to the baseline model. In Chapter 5, we present our last model, based on a different and more elaborate pricing mechanism than in the first two models. In the concluding discussion in Chapter 6, we address the following research questions:

• Is the model easily interpretable for the purposes of economics and fi- nance?

• Does it outperform other ABMs in modelling economic behaviour and expectations? In other words, is our model able to better replicate the empirical properties of the real world data? 1. Introduction 9

• Is it parsimonious enough to be easily applied to new problems?

• Is it robust to parameter modification?

• What are the limits and possible further extensions of the model?

The majority of the simulations were written and run in Matlab. Econometric analysis and figures were output by Wolfram Mathematica, Stata, and Eviews. All scripts, programs and data are available upon request. Chapter 2

The original boids model

In this chapter we briefly describe the original, underlying boids model as first introduced by Reynolds(1987). In his paper, Reynolds describes a simulation- based, heterogeneous agent-based approach to model flocking behaviour of birds or other animals forming or schools. The basic idea is that the system of agents, here called boids1, is viewed as a particle system, where the behaviour of each particle has its own characteristic (in our case these are, for example, speed, direction and attraction zone) and is governed by a set of rules. Trying to trace path of the whole flock would be in- efficient, computationally demanding and error prone. Stipulating behavioural rules for each agent yields a more robust solution with more realistic results.

2.1 Agent interaction in the boids model

As mentioned above, each of the agents has its specific, time-varying charac- teristics (speed, direction, position) and behavioural rules that are related to the following three principles:

• Repulsion: Agents avoid collision with others by moving away from the flock.

• Alignment: Agents synchronize their direction with other agents in the flock.

• Attraction: Agents are attracted towards the center of the flock.

These three forces are illustrated in Figure 2.1.

1“Boid” is a stereotypical New York slang word for a bird. 2. The original boids model 11

(a) Repulsion (b) Alignment (c) Attraction

Figure 2.1: Three main forces governing agents’ behaviour

In practice, repulsion force has the highest priority, followed by alignment and attraction. This means that first of all, the agent verifies that there are no other agents in her closest vicinity (the repulsion zone). Only then, the agent checks whether there are any other agents she can align with. If the alignment zone is empty, the agent proceeds to check whether the attraction zone is empty and adjusts her behaviour accordingly. The whole adjustment process is schematically depicted in Figure 2.2.

start Keep your direction no

Any agents in the no Any agents in the no Any agents in the repulsion zone? alignment zone? attraction zone? yes yes yes

Move away Align direction Approach the

Figure 2.2: Decision tree of an agent in the boids model Chapter 3

The baseline model

The main goal of this thesis is to apply the boids model to explain some relevant economic phenomena. In this chapter, we present a baseline model, inspired by the asset-pricing model (see Hommes, 2013; Tedeschi et al., 2012a). We call this model the baseline model as it will serve as a benchmark for further extensions of the model. We evaluate the performance of a model by looking at how closely the model is able reproduce stylized facts (as listed in section Section 1.3).

3.1 Description of the baseline model

3.1.1 Forecasting rules

At the beginning, we assume two types of agents – fundamentalists and trend followers. Each type of agents has her own forecasting rules in terms of xt, the deviation of the price from the fundamental value, the value of which is not important at the moment. In particular, the forecasting rules for each of the two types of agents are:

fF,t = 0 fundamentalists (3.1)

fT r,t = gxt−1 trend followers (3.2) where g > 0 is the strength of the trend following behaviour and F, T r stand for fundamentalists and trend followers, respectively. From Equation 3.1, it is clear that fundamentalists always assume that the price in the next time period will be equal to the fundamental price (or that the deviation from the fundamental 3. The baseline model 13 price will be zero). Each agent has the possibility to switch between the two types of behaviour based on the fitness associated with each type. In the ∗ baseline model, the evolutionary fitness measure Ut , ∗ ∈ {F, T r} is given by the past realized profits of each type of agents:

−Rx  U F = (x − Rx ) t−2 − C (3.3) t−1 t−1 t−2 σ2 gx − Rx  U T r = (x − Rx ) t−3 t−2 (3.4) t−1 t−1 t−2 σ2 where R = 1 + r is a constant interest rate, measuring the return of a risk- free asset, σ2 is the variance of the price returns (assumed to be constant and the same for both types of agents). C is the information gathering cost for the fundamentalists (equal to zero for trend followers). The fitness measures as in Equation 3.3 and Equation 3.4 are based on the myopic mean-variance optimisation of the agents. The full derivation of the fitness measures can be found, for example, in Hommes(2013, p. 160).

3.1.2 Price updating mechanism

Since the price mechanism is an expectation feedback system, the next period price deviation xt+1 is a weighted sum of fundamentalist and trend following expected prices (or forecasts), i.e.

N ξT r 1 X x = t gx +  , ξT r = I(κ = 1) (3.5) t+1 R t t t N i i=1 where I(·) is the indicator function, equal to 1 if the expression in the brackets is true and 0 otherwise. κ is the type of agents, equal to 1 if the agent T r is a trend follower and 0 otherwise. The ratio ξt is thus a ratio of the trend followers at time t. Note that fundamentalist expectations do not enter the price formation mechanism at all since the forecast is always zero (hence as the ratio of trend followers approaches zero, so does the price deviation xt). The small error term t is independently normally distributed with zero mean and variance 1/2.

At last, the daily returns rt are defined as the time difference between two subsequent price deviations, i.e.

rt = xt − xt−1 (3.6) 3. The baseline model 14

The daily returns rt are the main variable of interest in all our analyses.

3.2 Merging the asset-pricing and boids model

In the previous subsection, we have described the price and expectation for- mation mechanism based on the types of agents. In this part, we explain how these mechanisms drive the behaviour of the agents in the boids setup.

Name Label Class Description position P vector Position defines agent’s coordinates (2 × 1) in the bounded 2D space. direction d vector Direction is a standardized, unit vec- (2 × 1) tor directing the agent’s motion. type κ scalar Types 0 and 1 correspond to fun- {0, 1} damentalist and trend followers, re- Agent-specific spectively. speed ν scalar Speed indicates how much each agent moves in its direction in every time period. observable δ scalar Observable distance is the radius of distance the zone observable by each agent (see Figure 2.1).

Global herding τ scalar Herding threshold is the max. num- threshold ber of other agents that are tolerated within one’s distance. critical pc scalar Critical probability is the probabil- probability ity of switching types independently.

Table 3.1: Types of parameters in the baseline model

Assume a two-dimensional (2D) bounded space (0,S)×(0,S) and N agents, each characterized by three agent-specific and four global parameters. These parameters are described in Table 3.1. The agent-specific parameters vary both across agents and in time. The global parameters are kept constant through time and for all agents. The law of motion of the simulation is the following. At the beginning, there are N randomly scattered agents over the 2D space. Each agent has information about his type and the fitness Ut that is linked to his type. In addition, to model bounded rationality and incomplete information of the agents, she can only observe the types and fitnesses of agents strictly within her observable distance 3. The baseline model 15

δ. These agents are called the neighbours. If the number of neighbours within δ is less than the herding threshold τ, the agent picks the neighbour with the highest fitness (or picks one randomly in case there are different agents with the same fitness). The chosen agent is called the leader. If the leader’s type differs to our agent’s type, she compares the leader’s fitness to hers and switches to F fundamentalist strategy with probability pt (defined in Equation 3.7).

F 1 pt = −β(U ∗ −U ∗ ) (3.7) 1 + e F,t T r,t

In other words, in case there are both types of agents within neighbourhood of our agent, the probability of switching to the fundamentalist strategy depends on the fitnesses of both fundamentalist and trend following agents. For example, if the leader’s and our agent’s types are fundamentalist (κ = 0) and trend F 1 follower (κ = 1), respectively, then UF > UT r implies p > 2 , i.e. our agent is more likely to adopt the leader’s type than to keep her own. If the leader is of the same type, the agent does not compare relative fitnesses and only switches types independently and with low probability pc. For compu- F T r tational reasons, we standardize Ut and Ut in such a way that their ratios are F F ∗ Ut Ut  F ∗ T r∗ preserved, i.e. T r = T r∗ and max Ut ,Ut = 1. If unstandardized, high Ut Ut fitnesses lead to significant simulation instability due to exponentiation of high numbers. The β coefficient in Equation 3.7 is commonly called the intensity of choice since it measures how readily an agent switches to a more profitable strategy. In the two extreme cases, β = 0 means that the agents are unable to differentiate between the two strategies and choose either one randomly with probability 1/2. In the other extreme case, β = +∞, agents switch immediately to the best forecasting strategy. The flattening of the probability function with decreasing β is illustrated in Figure A.2. If the agent adopts the type of her leader, she also aligns her direction vector with the leader (subject to tiny er- ror) and gets closer to him by exactly ν units (since the length of the direction vector is 1). On the other hand, if the number of neighbours within δ from the agent exceeds the herding threshold τ, she turns her direction vector d in such a way that it points in the opposite direction from the gravity center of all the neighbouring agents (this reaction is an equivalent of the repulsion force as described in Section 2.1 – see also Figure 2.1(a) for illustration of the repulsion force). We say that the agent enters the survival mode. She then switches her type to the opposite of the herd’s majority type with (high) probability 1 − pc. 3. The baseline model 16

This step models the risk-averse, cautious nature of agents and prevents them from following blindly the herd for a long period of time. The whole direction and type adjustment processes are summarized by the diagram in Figure 3.1.

∀i ∈ {1,...,N}

Are there more than no Any agents at τ agents within δ? all within δ? yes yes no Direction Invert direction Align direction Keep direction change: away from the herd with the leader unchanged

Type Switch from herd’s Set κ = 0 Switch types c F c change: type with prob 1 − p with prob pt with prob p

Proceed at speed ν

Figure 3.1: Decision tree of an agent in the baseline model

Note that contrary to the original boids model as described in Section 2.1, there is no spatial frontier demarcating the repulsion zone. Instead, the re- pulsion force is activated when an excessive number of neighbours τ enter her observable distance δ. Furthermore, to keep the baseline model as simple as possible, the alignment and attraction step are merged into one, as the agent approaches her leader immediately after aligning her direction vector with him.

3.3 Simulation of the baseline model

At t = 0, N agents are randomly scattered over the 2D space, with randomized direction vectors d. At time t = 1, for every agent i ∈ {1,...,N}, the direction, position and type adjustment take place according to the diagram in Figure 3.1. The process is repeated T + w times, where w is the burn-in phase, the data of which are discarded immediately after the simulation and are not taken into account for further analysis. The burn-in phase precedes simulations of all three described models in this thesis and will not be explicitly mentioned in the next sections. 3. The baseline model 17

We run the simulation of the baseline model over T = 2000 periods, and extra 50 time periods as the burn-in phase. The default values of the parameters are listed in Table 3.2.

N S ν δ R g β C σ2 τ pc N 150 500 5 30 1.1 1.15 2 0.01 5 10 0.01 Note: (S × S) is the size of the square 2D space.

Table 3.2: Default parameter values of the baseline model simulation

The returns rt, the fractions of trend followers ξt, fitnesses and the repulsion ratios ρ are plotted in Figure 3.2. For the sake of completeness, the smoothed kernel density of the returns is plotted in Figure A.3(a) (to be discussed in more detail in Section 3.4).

0.9 0.8 0.5 0.7 0.6 0.0 0.5 -0.5 0.4 t t 500 1000 1500 2000 500 1000 1500 2000

(a) Returns rt (b) Fraction of trend followers ξt

0.8 UTr 0.20 0.6 UF 0.15 0.4 0.2 0.10 0.0 0.05

t t 500 1000 1500 2000 500 1000 1500 2000 F T r (c) Ut and Ut (d) Repulsion ratios ρt

Figure 3.2: The baseline model under the default parameter values

In this sequence of figures, we see that the returns rt rather resemble white noise with no evident spikes in either direction. The fraction of trend followers oscillates almost over the full range h0, 1i even though there are short periods when the ratio is kept unchanged. The last picture shows the development 3. The baseline model 18

of the repulsion ratio ρt, which is defined as the ratio of agents with more N than τ = 10 = 15 neighbours within δ = 30. Comparing the plots in the right column, we see that high repulsion ratios correspond to high fractions of fundamentalists (or low fraction of trend followers), which is in accordance with our model setup (see Figure 3.1).

(a) Positions and direction vectors of the agents (b) Empirical density histogram of the positions

Figure 3.3: Example of agents scattered in the space with direction vectors d (size not proportional) and the size of observable zones (of radius δ, in correct proportion)

A snapshot of the agents’ positions, direction vectors and observable zones can be seen in Figure 3.3. We can clearly see clusters, or herds, of agents following the same direction. In the upper part of Figure 3.3(a), we see clusters of agents disintegrating after surpassing the herding threshold τ = 15. For the sake of clarity, only the zones (of radius δ = 30) are plotted in the correct proportion whereas the unitary direction vector d is multiplied by 30. Figure 3.3(b) shows the empirical density histogram plot, obtained by the Gaussian kernel density estimation with bandwidth 25. Comparing the two figures, we see that the survival mode is activated in the most crowded clusters (dark red in the top of Figure 3.3(b)). 3. The baseline model 19

3.4 The baseline model and the stylized facts

We now look at the ability of the baseline model to explain some of the stylized facts that serve as a benchmark for evaluating the performance of our models. Since the model yields slightly different results under different random seeds, we performed 100 replications to obtain the average values of the mean, standard deviation, minimum, maximum, skewness and kurtosis, including respective standard errors. Table A.1 shows the summary statistics of the variables of T r F T r interest – the returns rt, fitnesses Ut and Ut , the ratio of trend followers ξt and the repulsion ratio ρt, including the standard errors.

The properties of returns rt will be more thoroughly discussed in the stylized facts part below. As for the remaining variables, we see that both fitnesses show fat tails – the mean kurtosis is 24.6 and 41.4 for trend followers and fundamentalists, respectively. However, the standard errors are also very high, suggesting that not in all simulations the fitnesses experience sharp jumps. The fraction of T r trend followers ξt is fairly high during all the simulations (around 75%). We now look at each of the stylized facts and discuss whether it is exhibited by the baseline model or not. For inspection of normality and autocorrelation, we pooled the data from all the simulation rounds (under different random seeds), yielding T × Rep = 2000 × 100 = 200 000 observations.

Skewness & Kurtosis We see that the returns rt are not significantly different from zero and their skewness and kurtosis seem to oscillate a lot – there is no statistical evidence for excess kurtosis and negative skewness. Never-

theless, from Table A.1 we see that, on average, the returns rt have fatter tails (high kurtosis) and slightly positive skewness. However, this result is most likely coincidental because the model does not provide any justi- fication for extreme negative or positive values of the returns. In fact, in the complete simulation, the returns are negatively and positively skewed with the same frequency. Furthermore, as mentioned above, the standard errors are too high to conclude that the model yields consistently negative skewness or excess kurtosis. The minimum and maximum kurtosis across all runs is 2.81 and 14.2 with median value of 3.1 – the model is slightly more likely to yield returns with excessive kurtosis than otherwise.

Non-normality The varying values of skewness and kurtosis suggest non- normality of the returns distribution. A more formal approach is to 3. The baseline model 20

perform the Jarque & Bera(1980) normality test with sample-adjusted standard errors (the adjustment mechanism described in D’agostino et al., 1990) based on the skewness and kurtosis of the sample. In our case the normality is strongly rejected with p-value 0.000. The kernel density esti-

mate of rt compared to the normal distribution is plotted in Figure A.3(a). We see that, visually, the estimated density does not differ significantly from the normal density.

Autocorrelation in rt We first plotted the Autocorrelation function (ACF) and Partial Autocorrelation Function (PACF) up to 150th lag. The plots are presented in Figure 3.4. The confidence intervals are computed using the Bartlett’s formula for MA(1) processes (see, for example, Brockwell & Davis, 2002). The confidence intervals for PACF are computed using the √ standard error 1/ N. We see that both ACF and PACF show strong expo- nential decay, suggesting an ARMA specification. The autocorrelation is formally tested by Ljung & Box(1978) test with 40 lags. The null hy- pothesis of independent data with no autocorrelation is strongly rejected (the Q-statistic is χ2(40) distributed with p-value 0.000). Even though the low-order autocorrelations are statistically significant, the economic importance of the autocorrelation is rather negligible (the first lag auto- correlation is less 0.1).

0.00 0.00

-0.02 -0.02

-0.04 -0.04

-0.06 -0.06

-0.08 -0.08

-0.10 -0.10 0 50 100 150 0 20 40 60 80 100 lag lag

(a) ACF of rt (b) PACF of rt

Figure 3.4: ACF and PACF of rt, the baseline model

The baseline thus does not replicate the stylized fact of no autocorrelation in the levels of returns. This was expected since the return equation is constructed as a coefficient-varying AR(p) process (see Equation 3.5).

Autocorrelation in |rt| Figure 3.5 shows power-law and exponential fits for 3. The baseline model 21

the autocorrelation of the absolute returns up to 150th lag, performed on the complete, pooled data from all simulations. We see that at the beginning the autocorrelation dies roughly at the exponential rate but, for higher past lags, the autocorrelation can be rather fitted by the power- law function, even though the function values occasionally drop below zero. We conclude that there is no clear power-law decay trend in the autocorrelation of the absolute returns.

0.01 0.001 10-4 10-5 A = 0.0245, Α = 0.68 - 10 6 B = 0.0358, Β = 0.0814 l 20 40 60 80 100 120 140 Figure 3.5: Power law (dashed) and exponential decay (dot-dashed) fits for autocorrelation in |rt|, semi-log plot. Negative autocorrelation values omitted.

Volatility clustering We also test for autocorrelation in squared returns. We test it by estimating the GARCH effect with a specified mean equation, and we also allow for a different effect of negative impact (the threshold effect). We specify the mean equation with one autoregressive (AR) and one moving average (MA) terms. The variance equation is a GARCH (1, 1) specification with a threshold term. For description of the GARCH model, see Tsay(2005, p. 113). The regression results are summarized in Table 3.3. We see that there is strong evidence for both autoregressive and moving average effects in the returns. This is not surprising given the construc- tion of the price mechanism (cf. Equation 3.5 and Equation 3.6) which contains both past return and a normally distributed error term. In the variance equation, both past squared return (L.arch term) and past variance (L.garch term) are significant, suggesting presence of volatility clustering. Surprisingly, the threshold term L.tarch is also strongly sig- nificant suggesting that negative news have larger impact on the returns than the positive news.

We have also added further lags of both ARCH and GARCH terms but with no significant improvement. No more ARCH lags were significant whereas 3. The baseline model 22

ARMA(1, 1)-TGARCH(1, 1)

dep var: rt cons 0.000000912∗∗∗ (2.00) (2.79) ARMA L.ar 0.848∗∗∗ (204.52) (587.92) L.ma −1.000∗∗∗ (−49947.76) (−68069.39) ARCH L.arch 0.0485∗∗∗ (7.35) (24.55) L.tarch −0.0201∗∗∗ (−2.62) (−10.25) L.garch 0.811∗∗∗ (68.11) (86.80) cons 0.0101∗∗∗ (14.32) (18.23) t-statistics in parentheses. 3rd column: cluster and heteroskedasticity-robust standard errors used. 4th column: heteroskedasticity-robust standard errors used. * p < .1, ** p < .05, *** p < .01

Table 3.3: ARMA(1, 1)-TGARCH(1, 1) model regression result

GARCH effect is present up to and including the fourth lag. To sum up, the model does exhibit strong volatility clustering which is in line with empirical observations.

We conclude that the baseline model is able to replicate some of the stylized facts in question. Even though there is not enough statistical evidence for excess kurtosis nor negative skewness, the skewness-kurtosis test on the complete, pooled data strongly rejected normality. The baseline model produces (weakly) autocorrelated returns which is not a desirable property of the model. There is no discernible pattern in the decay of the autocorrelation of the absolute returns. At last, the model yields returns that cluster in time of high volatility, as we have confirmed by our GARCH analysis.

3.5 Sensitivity analysis

In this subsection, we look at how the behaviour of the model evolves after a change in one single parameter, keeping all other parameter values constant. We focus on the parameters which directly influence the behaviour of the agents such as the intensity of choice β, the observable distance δ, the trend following strength g, the herding threshold τ, the critical probability pc and the funda- 3. The baseline model 23 mentalist cost C. For the sake of completeness, the range of values for each parameter of interest is presented in Table A.2.

Intensity of choice β The simulations did not yield qualitatively different re- sults as compared to the default value β = 2.0. This is due to fact that the β parameter plays a less important role than in the original asset- pricing model. Here the importance of β is diluted by the presence of the survival mode and the critical probability pc which, as we shall see, has a more significant impact on the dynamics of the model.

Cost C The change in the cost parameter C leads to significantly different

behaviour of the model. Figure 3.6 depicts the evolution of rt and ξt under two cases, C = 0 and C = 0.5. We see that under no cost the ratio of trend followers is very close to zero (on average only 3.1%) whereas under high cost (C = 0.5) the fraction of trend followers is close to 1 (on T r F average 91%). Under no cost the fraction of times when Ut > Ut is around 57% whereas, for C = 0.5, this fraction is about 95.5%, i.e. the fundamentalist strategy pays off only in about 4.5% time periods. Simply said, it becomes too expensive to be a fundamentalist. Nevertheless, the fundamentalists are never completely driven out of the market because of the survival mode that is activated whenever the herding threshold τ is surpassed and agents swap strategies with probability 1 − pc = 99%. Since trend followers outnumber fundamentalists when the cost C is high,

the returns rt are driven mainly by trend followers which is clear from the Figure 3.6(c). Few time periods before the sharpest spike at t = 963, the

ratio of trend followers is at ξt = 99.3%. At t = 963, a phase transition

occurs, the ratio of trend followers falls to ξt = 0.8 (most likely due to overcrowded observable zones) and keeps falling afterwards until the

returns rt stabilize around zero. We also include the plot of fitnesses in Figure A.4 in which we clearly see the difference in the average fitness for the two costs.

Critical probability pc The change in the critical probability pc mainly trans- formed the development of the fractions of trend followers. Note that pc has two functions in the model dynamics as is clear from the dia- gram in Figure 3.1. First, when the observable zone is overcrowded, the agent adopts the strategy opposite to that of the herd with probability 1 − pc. Second, when an agent decides not to imitate any other’s type, 3. The baseline model 24

1.0 0.8

0.5 0.6

0.0 0.4

-0.5 0.2

t t 500 1000 1500 2000 500 1000 1500 2000

(a) Returns rt, C = 0 (b) Fraction of trend followers ξt, C = 0

2 1.0

1 0.9

0 0.8

-1 0.7

t t 500 1000 1500 2000 500 1000 1500 2000

(c) Returns rt, C = 0.5 (d) Fraction of trend followers ξt, C = 0.5

Figure 3.6: rt and ξt under C = 0 and C = 0.5

she switches types with probability pc. As an example, for pc = 0 an agent would never switch types independently but only when her zone is overcrowded, she chooses the herd’s opposite strategy with certainty. For pc = 1 the agents in the survival mode always switch to the herd’s op- posite strategy and the agents with no leader switch types independently with certainty. Two examples for pc = 0.4 and pc = 1 are illustrated in Figure 3.7. For pc > 0 the fractions exhibit fairly erratic behaviour (due to frequent type switching of leaderless agents), whereas, for pc = 1, we see much stronger trend with periods with constant fractions (horizontal line segments in Figure 3.7(b)).

Observable distance δ The change in the observable distance δ affects mainly

the repulsion ratio ρt. For δ = 0, there is no observable zone at all so the survival mode is never activated. For δ ≥ S = 500, the observable zone contains the whole 2D space (i.e. the square box as in Figure 3.3 would be encompassed in any agent’s circular observable zone). In Figure 3.8

we show the repulsion ratios ρt for low and high δ. When the zone is 3. The baseline model 25

1.0 1.0 0.9 0.9 0.8 0.8 0.7 0.6 0.7 0.5 0.6 0.4 t t 500 1000 1500 2000 500 1000 1500 2000 c c (a) Fraction of trend followers ξt, p = 0.4 (b) Fraction of trend followers ξt, p = 1

c c Figure 3.7: ξt under p = 0.4 and p = 1

small (δ = 10), the survival mode is rarely activated (in 0.1% cases), whereas, for large zone (δ = 400), all agents are almost always in the survival mode, trying to escape from the herd and switching types with probability 1 − pc = 0.99.

1.00 0.06 0.98 0.05 0.04 0.96 0.03 0.94 0.02 0.92 0.01 0.90 t t 500 1000 1500 2000 500 1000 1500 2000

(a) Repulsion ratios ρt, δ = 10 (b) Repulsion ratios ρt, δ = 400

Figure 3.8: Repulsion ratios ρt for δ = 10 and δ = 400

Trend following strength g As seen in Equation 3.5, the trend following strength g has direct impact on the speed of price adjustment. When g = 0, both trend followers and fundamentalists forecast the same price and the re- spective fitnesses differ only in the fundamentalist cost C. This suggests that, on average, there should be many more trend followers than fun- damentalists, which is confirmed by our simulation – for g = 0, 94% of agents are trend followers on average. The remaining few percent are due to type switching in the survival mode. For 0 ≤ g / 1.5, the ratio F T r of trend followers gradually decreases with g as Ut exceeds Ut much more often than for low g, and the fundamentalist strategy thus becomes popular. 3. The baseline model 26

For values of g ' 1.5, the path of the returns rt and fitnesses is explosive and usually terminates the simulation due to reaching extreme values. Theoretically, the explosive paths could be expected for any g > R2 (see lemma in Brock & Hommes, 1998, p. 1251) since then the ratio no longer has a dampening effect on past returns.

Herding threshold τ At last, we have a look at the effect of change in the herding threshold τ. Figure 3.9 shows the ratio of trend followers for τ = 30 and τ = 150. In the former case, we see that when there are any agents in the repulsion zone (not plotted), the fraction of trend followers oscillates wildly. In the second case, τ is high (in fact, the survival mode is never activated for any agent and, hence, the repulsion ratio remains zero), and we see long periods of time with constant ratio of trend follow- ers. Any change in the type of agents is only induced through comparing fitnesses of the agents in δ or, marginally, through independent switching with probability pc, leading to tiny spikes in Figure 3.9(b).

1.0 1.0

0.8 0.9

0.8 0.6 0.7 0.4 0.6 t t 500 1000 1500 2000 500 1000 1500 2000

(a) Ratio of trend followers ρt, τ = 30 (b) Ratio of trend followers ρt, τ = 150

Figure 3.9: Ratio of trend followers ξt for τ = 30 and τ = 150 Chapter 4

The extended model

4.1 Description of the extended model

4.1.1 Forecasting rules

We now extend the model to allow for much richer heterogeneity among the agents. In particular, we allow for agent-variant (linear) forecasting rules among the agents. We do not permit non-linear forecasting rules of any form to keep the model as simple as possible. As mentioned in the literature review in Section 1.2, there is experimental evidence that simple rules are used by human subjects as well. The forecasting rule is now specified as:

fit = gitx˜t + bit ∀i ∈ {1,...,N} (4.1) where gi ∈ (gmin, gmax) is the trend following (g ≥ 0) or contrarian (g < 0) strength and bi ∈ (bmin, bmax) is the bias of each agent, bi R 0 andx ˜t = PL l l=1 λ xt−l, i.e.x ˜t is the geometric decay process with the decay parame- ter 0 < λ ≤ 1 and memory length L time periods. Figure A.5 illustrates the speed of decay of past price deviations depending on the value of λ. It is clear that for low values of λ there is no need to increase L because the more distant return lags would only get negligible weight. Conversely, for λ close to 1, even price deviations in the distant past carry considerable weight in determination of today’s price.

4.1.2 Price updating mechanism

Since we have many more strategies than in the baseline model (where we only had fundamentalists and trend followers), the price updating mechanism is now 4. The extended model 28

N 1 X 1 x = f +  = (¯g x˜ + ¯b ) +  (4.2) t NR it t R t t t t i=1 i.e. the price deviation xt is a sum of the average forecast and the average bias of all agents from t − 1 and a small error term. The returns rt are defined as in the baseline model and the fitness measure Uit is now generally defined as:

g x + b − Rx  U = (x − Rx ) it t−3 it t−2 − C (4.3) i,t−1 t−1 t−2 σ2 it In the baseline model, the cost C was only paid by fundamentalists. In this case, the probability of having a fundamentalist in a cohort of agents is equal to zero since the strategy parameters g and b are initially drawn randomly from the interval (gmin, gmax) or (bmin, bmax), respectively. We thus introduce so-called pseudo-fundamentalists – agents whose strategy is very close to fundamentalist. In other words, if |g| < γ and |b| < γ where γ is a threshold relatively close to zero then the agent is a pseudo-fundamentalist and must pay the fixed cost

Cit = C as in the baseline model. As in the baseline model, the observable distance δ and the herding thresh- old τ are kept constant and agent-invariant.

4.1.3 Roulette selection of the forecasting rules

The roulette selection is a procedure used in genetic algorithms that ascribes probabilities of selection according to the respective fitnesses of the agents (see Miller & Goldberg, 1995; Blickle & Thiele, 1995;B ¨ack, 1996). Unlike in the baseline model where each agent simply chooses her leader – the agent with the highest fitness – with certain probability, in this model, an agent considers all neighbours with higher fitness than herself and then ascribes them probabilities of choosing their strategies. These probabilities reflect the relative difference in fitnesses between the neighbours and the agent. This augmentation of the information set is more realistic since, in reality, economic agents hardly base their economic decisions on a unique piece of information but try to diversify and obtain as much information as possible. As an example, consider an agent i with J neighbours in her observable dis- tance δ that have higher fitness than herself. She then computes the (standard- ized) differences in fitnesses ∆U ∗ = Uj −Ui for each of the J neighbours j maxj (|Uj −Ui|) and the respective probabilities of choosing the neighbour j’s strategy as: 4. The extended model 29

1 pjt = −β∆U ∗ (4.4) 1 + e j The probability function is the same as in the baseline model and is plotted in Figure A.2 (note that we are interested in the right arm of the function since ∗ ∆Uj > 0). For each of the J neighbours, we obtain a probability (necessarily higher than 1/2) which will serve as a weight for choosing agent j’s strategy. These probabilities only sum to 1 after rescaling by the sum of all the proba- bilities. Intuitively, the higher the relative difference between the agent’s and neighbour j’s strategies as compared to other agents, the higher the probability of choosing agent j’s strategy. The role of the herding threshold τ, the critical probability pc and the sur- vival mode is now altered as well. First of all, activation of the survival mode no longer depends on the absolute number of agents within δ but uniquely on the number of agents with the same strategy. Since we face complete heterogene- ity with respect to strategies among agents, we would expect that the survival mode is activated less frequently than in the baseline model because it is much less likely to encounter identical strategies within the herd. However, given the roulette selection described above, there is always a positive probability that agents adopt the same strategy at some point in time. Consequently, the herding threshold is now set lower than in the baseline model, otherwise it would never be surpassed. When the survival mode is activated at last, i.e. when there are more than τ neighbours with the same strategy, the agent draws a strategy opposite to that of majority of the herd

(as in the baseline model) from N (−sh, σ˙ ) where sh is the mean strategy (h ∈ {g, b}) of the herd. In other words, in the survival mode, each agent adopts a strategy opposite to that of the herd subject to a small error, moderated by the standard deviationσ ˙ .

4.2 Simulation of the extended model

In addition to the baseline parameters listed in Table 3.2, we now reset or define new parameters in Table 4.1.

As we can see, since |gmin| > |gmax|, we initialize the model with higher number of contrarians than trend followers. This is mainly for computational reasons as more contrarians in the system avoid explosive returns paths. If gmax is much higher than gmin, the returns increase too quickly due to fast trend 4. The extended model 30

gmin gmax bmin bmax γ δ τ L λ σ˙

gmax N −2 1 −2 1 5 50 30 3 0.8 0.2

Table 4.1: Default parameter values of the extended model simula- tion

following and might reach astronomical values before the correction occurs. We also allow for memory in prices L = 3 with fairly high decay parameter λ. This

means that xt−1, xt−2 and xt−3 have all significant impact on the determination

of today’s price deviation xt and of the return rt. Unlike in the baseline model, we cannot plot the fitnesses of fundamentalists and trend followers because now we have a continuum of strategies among agents. A natural step is to look at the development of the cohort average ¯ trend following strengthg ¯t and bias bt through time. The key variables from one random simulation are plotted in Figure 4.1 and summarized in Table A.3 (which also contains summary statistics from the complete simulation under different seeds).

3 2 0.5 gt bt 1 0.0 0 -1 -0.5 t 500 1000 1500 2000 t -3 500 1000 1500 2000

(a) Returns rt (b) Average trend following strength and bias

0.4

2.0 0.3 1.5 0.2 1.0

0.5 0.1

t t 500 1000 1500 2000 500 1000 1500 2000

(c) Average fitness U¯t (d) Repulsion ratios ρt

Figure 4.1: The extended model under the default parameter values

We see that the returns rt exhibit usual mean-reversion and occasional 4. The extended model 31

¯ spikes in both negative and positive directions. The average fitness Ut seems yet more leptokurtic, despite averaging across all agents. As can be guessed from ¯ the top row, the periods with unusually low average bias bt correspond to unusu- ally low negative returns. At a closer look, the periods with very low negative returns are immediately preceded by a few periods with very low bias but very high trend following strength whereas, in periods of the low returns, bothg ¯t ¯ and bt are almost zero, suggesting that agents return to pseudo-fundamentalist strategies. The survival mode also has a significant impact on the dynamics of the model, as illustrated by fairly high repulsion ratios ρt in Figure 4.1(d). Note that if the herding threshold was kept as high as in the baseline model, the re- pulsion ratios would only rarely be positive, due to lower chance of encountering identical strategies, as explained at the end of Subsection 4.1.3.

4.3 The extended model and the stylized facts

As in the baseline model, we perform the whole simulation Rep = 100 times. The main results from one random seed and from all seeds together are sum- marized in Table A.3. The performance, as compared to the baseline model, is also shortly discussed for each of the stylized facts.

Skewness & Kurtosis As we can see from Table A.3, the average kurtosis of

rt is notably higher than in the baseline model and with much higher standard deviation. Even though we cannot conclude that there is statis- tical evidence for excess kurtosis due to high standard deviation, almost all kurtosis values across all seeds were higher than 3. Furthermore, if we pool the data from all simulations and treat them as one large dataset (with T × Rep = 200 000 observations), the kurtosis equals 5036. On average, the skewness is negative with yet larger standard deviation than in the baseline model. The skewness values range from −18.174 to 11.652 across the simulation runs. This is not surprising since, as in the baseline model, the model does not provide any justification for higher incidence of either positive or negative returns.

Non-normality The frequent large values of kurtosis and skewness throughout the simulations make it clear that the return distribution will be far from normal, which was also confirmed by the Jarque-Bera normality test – 4. The extended model 32

normality rejected with zero p-value. For comparison with the baseline model, we plotted the kernel densities of the respective returns next to each other. The result can be seen in Figure A.3. As suggested above, the returns data from the extended model are much more leptokurtic than in the baseline model.

Autocorrelation in rt Figure 4.2 shows the ACF and PACF for returns rt from the extended model. Due to memory in returns in agents’ forecasts, the price deviations and thus the returns are more interrelated than in the baseline model (see the pricing mechanism in Equation 4.2). The autocorrelation function is thus influenced by two counteracting forces – high heterogeneity of agents (dampening effect on autocorre- lation), and memory in returns in the forecasting rules of the agents (strengthening effect on autocorrelation).

0.50 0.20

0.00 0.00 -0.20

-0.50 -0.40

-0.60 -1.00 0 50 100 150 0 20 40 60 80 100 lag lag

(a) ACF of rt (b) PACF of rt

Figure 4.2: ACF and PACF of rt, the extended model

We conclude that the extended model produces returns with stronger au- tocorrelation than the baseline model and does not replicate the stylized fact of no autocorrelation.

Autocorrelation in |rt| We are interested in how quickly the autocorrelation in absolute returns disappears. We plot the power-law and exponential fit functions in Figure 4.3. Contrary to the baseline model, the autocor- relation in absolute returns decays much slower and can be fitted with a power-law function even for the complete, pooled dataset. As discussed in Section 1.3, this property is a sign of long-term dependency, caused by the interrelatedness of agents through the roulette wheel selection and by 4. The extended model 33

the moving geometric average process of the returns. We thus conclude that this stylized fact is better replicated by the extended model than by the baseline model.

1 0.1 10-8 10-4 10-16 10-7 10-24 -10 10-32 10 A = 0.115, Α = 0.453 A = 0.144, Α = 0.718 -40 10-13 10 B = 0.922, Β = 0.737 B = 0.784, Β = 0.245 10-48 l l 20 40 60 80 100 120 140 20 40 60 80 100 120 140 (a) One random seed (b) All seeds

Figure 4.3: Power law (dashed) and exponential decay (dot-dashed) fits for autocorrelation in |rt|, semi-log plot. Negative autocorrelation values omitted.

Volatility clustering As in the previous section, we try to discover the pres- ence of volatility clustering via the GARCH model. We ran the ARMA- GARCH regression and the results are presented in Table 4.2. We see that all coefficients except the threshold term (as expected, given there is no evidence of negative skewness) are strongly significant. As in the baseline model, the extended model also replicates the stylized fact of clustered volatility.

In a nutshell, the extended model shows some improvement over the baseline model. We conclude that increased heterogeneity among the agents and deeper integration (roulette selection method, letting lags of returns influence today’s returns and increasing δ) mainly lead to more extreme observations of returns and long-range dependence. As expected, the extended model failed to yield consistently larger (in absolute terms) negative values since the model is not designed to do so. 4. The extended model 34

ARMA(1, 1)-TGARCH(1, 1)

dep var: rt cons −0.000260 (−0.43) (−0.46) ARMA L.ar −0.812∗∗∗ (−356.45) (−383.07) L.ma 0.134∗∗∗ (23.89) (23.08) ARCH L.arch 0.138∗∗∗ (14.55) (28.88) L.tarch −0.00981 (−0.71) (−1.54) L.garch 0.738∗∗∗ (57.80) (102.06) cons 0.0216∗∗∗ (17.15) (24.63) t-statistics in parentheses. 3rd column: cluster and heteroskedasticity-robust standard errors used. 4th column: heteroskedasticity-robust standard errors used. * p < .1, ** p < .05, *** p < .01

Table 4.2: ARMA(1, 1)-TGARCH(1, 1) model regression results, ex- tended model Chapter 5

The limit-order model

5.1 Description of the limit-order model

The structure of our last model is very different to our previous two models. The pricing mechanism and the types of the agents are inspired by Iori & Chiarella(2002); Chiarella et al. (2009); Tedeschi et al. (2012b). In summary, agents no longer imitate other agents via comparison of fit- nesses or past returns, nor they ascribe probabilities of such imitation. In this model, agents are fully independent and do not alter their strategies over time. The emphasis is put on the pricing mechanism and the interactions between the agents in the market place.

5.1.1 Forecasting rules

At the beginning of each time period t, each agent i ≤ N makes a forecast about the future return ζ periods ahead in the form1:

f i i pt − pt i rˆt,t+ζ = g1 + g2rt + nit i ≤ N, t ≤ T (5.1) pt f where g1 moderates the strength of the fundamentalist strategy, pt is the fun- damental price, pt is today’s stock price, g2 is the trend-following (g2 > 0) or contrarian (g2 < 0) strength, n is the strength of the noise trading strategy, rt pt−pt−1 is today’s return, defined as rt = and t ∼ N (0, 1). As it is commonly pt−1 assumed in the literature, the fundamental price is known by the agents and f follows a random walk with p0 = 1000 and standard deviation 10. It follows 1To be consistent with the previous chapters, the returns of any form are always denoted rt. 5. The limit-order model 36

f that the fundamental price pt is (filtration) Ft-adapted and is a martingale: f f E(pt |Fs) = ps , for any 0 ≤ s < t. It is clear from Equation 5.1 that each agent’s return forecast is a weighted average of the three types of beliefs – fundamentalist, chartist and noise trading.

In our model, the parameters g1, g2 and n are initially drawn from the uniform max min max min max distribution of ranges (0, g1 ), (g2 , g2 ) and (n , n ), respectively. i Given the return forecastr ˆt,t+ζ over the period (t, t+ζ), the agents can also forecast the price at time t + ζ as:

i i rˆt,t+ζ pˆt,t+ζ = pte (5.2) assuming continuously compounded returns. Depending on whether the agent i i expects a price increase (ˆrt,t+ζ >0) or price decrease (ˆrt,t+ζ <0), she submits an order to buy or sell one unit of stock:

i i i bt =p ˆt+ζ (1 − k ) (5.3) i i i at =p ˆt+ζ (1 + k ) (5.4)

i where bt (at) is the bid (ask) offer, equal to the price forecastp ˆt+ζ times the discount factor 1−ki (or 1+ki), with ki uniformly distributed in (0, kmax). The offered buying price bt thus reflects agent’s expectation about the stock price pt+ζ and, if executed, the transaction gives the agent the possibility to gain i i i i (1 − k ), if his price forecast is correct, or (pt+ζ − pˆt,t+ζ )(1 − k ) if pt+ζ > pˆt,t+ζ . i i i i Note that at ≥ 0, bt ≥ 0 and atbt = 0, i.e. no agent can submit a bid and an ask at the same time.

5.1.2 Pricing mechanism

In the previous two models, the pricing mechanism was perceived as an expec- tation feedback system in the sense that the expectations of the agents about the future directly determined the future price. The biggest difference between the limit-order market and the two previous models is that the stock price pt and corresponding returns rt are set as in the real financial markets – by interaction of traders and matching bid/ask offers. The price formation works as follows. At the beginning of each time period i t, all agents make a forecast about the returnr ˆt,t+ζ (as in Equation 5.1) and submit their bids and offers that are stored in the trading book. From the 5. The limit-order model 37 moment of submission, each order has an expiry (or maturity) of length ζ. Hence, no orders can stay in the book for a period of time longer than ζ. The agents interact in the following way. Similarly as in the previous two models, each agent only connects with his close neighbours – agents in the ob- servable distance δ. To be concrete, the agent can only trade with the agents within the observable distance δ. For example, if there are other neighbours within δ from our agent, only the bids and asks recorded in the book under their ID can lead to a transaction, i.e. the agent only compares his asks (bids) with bids (asks) of his neighbours. A transaction (or a market order execution) q takes place whenever a quoted bid bt (the maximum offer price for a stock q price) surpasses the quoted ask at (the minimum asking price). Upon execu- tion of a market order, the two entries (selling and buying order) are removed from the book, the market volume in the time period t is incremented by one and, ultimately, the market price pt is set equal to the last price at which a q transaction occurred, i.e. the average of the quoted ask at and the quoted bid q bt . If no market order is immediately executed at time t, the orders are kept in the book until their expiry at time t + ζ and, since that moment, are called the limit orders. Note that, even though each agent is allowed to trade one stock at the time, he can participate in many more transactions due to his (not yet executed) limit orders from the past time periods. Hypothetically, each agent can be involved in up to ζ transactions in one time period. After the limit orders expire, they are removed from the trading book. The market orders are executed across neighbourhoods at different quoted prices. Hence, to determine the final closing price at time t (or opening price at time t + 1), we average all the quoted prices at which transactions have taken place across all neighbourhoods at time t. After the agent and his neighbours clear their orders, they move forward, following their direction vector d and the process continues until all agents have either participated in the trade and/or moved forward. Contrary to the baseline and extended models, in the limit-order model, the agents do not follow leaders nor they compare fitnesses. In other words, in the limit-order model the boids mechanism only serves to narrow the group of traders with whom an agent is allowed to trade. In summary, in the current model, we put more emphasis on the pricing mechanism than on the individual utility maximisation via fitnesses comparing and imitating of leaders, as in the previous two models. However, merging both 5. The limit-order model 38 utility maximisation approach and market-order has already been discussed, for example, in Chiarella et al. (2009). For our purposes of modelling stylized facts on financial markets, however, it is sufficient to employ the easier, tractable limit-order model with unit size orders.

5.2 Simulation of the limit-order model

In reality, trading on financial markets occurs almost continuously throughout the day. To model this feature, we divide the day into ∆t time periods such

pt−pt−∆t that the daily return rt is equal to . pt−∆t In addition to the baseline parameters listed in Table 3.2, we now reset or define new parameters in Table 5.1.

max max min max min max TN ∆t ζ g1 g2 g2 n n k max max 20 000 60 10 2∆t − 1 0.4 2 −g2 0.1 −n 0.2

Table 5.1: Default parameter values of the limit-order model simula- tion

As we can see, the role of noise traders is less important than that of trend- followers and fundamentalists, as noise trading does not lead to any interesting dynamics and, in reality, noise traders are rarer than more “rational” traders, such as trend followers or fundamentalists.

Furthermore, we split a day into ∆t = 10 time periods, leading to the total of T/∆t = 2000 daily observations for prices, returns, bid-ask spreads and volume. The parameter ζ is set to 2∆t − 1, meaning that the limit orders stay in the book for almost 2 days before they are removed. Due to much higher computational complexity of the limit-order model, we run the simulations with a decreased number of agents, which, fortunately, did not lead to any qualitative changes in the model, as confirmed by additional small-scale simulations. As in the previous two models, we run the simulation over Rep = 100 different random seeds to obtain standard errors of the core sample statistics, leading to the total of Rep × T = 2 000 000 replications. In Figure 5.1 we show the development of the most important variables. The summary statistics of these variables for one random seed and for all seeds are given in Table A.4. From Figure 5.1, we can see that the trading volume and the volatility of returns increase whenever the stock price pt deviates too far from the funda- 5. The limit-order model 39

f mental price pt due to prevalence of trend followers. As seen from Equation 5.1, when the difference between the fundamental price and the realized stock price is too large, the fundamentalist part of the agents’ forecasting rule balances out (or predominates) the remaining two strategies, leading to more diverse price forecasts and, thus, higher trading volume. From the summary in Table A.4, we see that the minimum trading volume ranges from about 288 to 2167 across the simulations, reflecting large changes in trading appetite of the agents over time. The last line of the summary table ¯ shows the average limit-order maturity ζt, indicating how long (on average) the limit-orders stay in the trading books before execution or removal. Given that the minimum and maximum maturity are 0 and (almost) 2 days, respectively, it is expectable that the average maturity will be around 1 day (precisely 0.962 days, with very small standard deviation).

0.08 1500 0.06 0.04 1000 0.02 500 pt 0.00 f - pt 0.02 t t 500 1000 1500 2000 500 1000 1500 2000

(a) Daily prices pt (b) Daily returns rt

30 2000 25 1500 20 15 1000 10 500 5 t t 500 1000 1500 2000 500 1000 1500 2000

(c) Daily trading volume vt (d) Daily bid-ask spread st

Figure 5.1: The limit-order model under the default parameter val- ues, results from one random seed 5. The limit-order model 40

5.3 Limit-order model and the stylized facts

As for the previous two models, we now discuss ability of the limit-order model to replicate the selected stylized facts. The summary statistics of the model returns are given in Table A.4.

Skewness & Kurtosis As in the previous two models, the limit-order model is not constructed to produce negatively skewed returns, which was con- firmed during the simulations – the returns are positively and negatively skewed with equal frequency and the skewness is not statistically different from zero. However, the simulated returns regularly showed excess kurtosis through- out the simulations, with less extreme values when compared to the pre- vious two models but, also, with much smaller standard deviation, sug- gesting only moderately fatter tails as compared to normal distribution. The minimum and maximum kurtosis values over all the simulation runs were 3.01 and 10.85, respectively. The kurtosis of the pooled returns from all simulation is equal to 15.72. The peakiness of the returns is also vis- ible from Figure A.3(c), which shows the kernel density estimate of the pooled returns.

Non-normality Frequent recurrence of large values of kurtosis throughout the simulations suggest that the return distribution is non-normal, which is also confirmed by the Jarque-Bera normality test – normality rejected with zero p-value. For comparison with the baseline and extended model, we plotted the kernel densities of the respective returns next to each other as in Figure A.3. The returns from the limit-order model are about as leptokurtic as in the baseline model but to a lesser degree than in the extended model. In all three cases, however, the empirical distribution of the simulated returns is comparable to the empirical distribution of the real-world stock returns (see Figure A.1 for the empirical density of the NASDAQ stock returns).

Autocorrelation in rt The deficiency of our first two models was that they produce autocorrelated returns, which suggests that agents can predict tomorrow’s price and thus profit from arbitrage. The advantage of the limit-order model is that it can consistently produce uncorrelated returns. 5. The limit-order model 41

0.10 0.10

0.00 0.00

-0.10 -0.10

-0.20 -0.20

-0.30 -0.30 0 50 100 150 0 20 40 60 80 100 lag lag

(a) ACF of rt (b) PACF of rt

Figure 5.2: ACF and PACF of rt, the extended model

Figure 5.2 shows the ACF and PACF of the daily returns rt. Contrary to the previous two models, the correlograms show no monotonic patterns and resemble much more the correlograms of the NASDAQ returns in Fig- ure 1.2. The unusually high values for the first lag are due to extending the maturity of the limit-orders over one day (see Table 5.1). The auto- correlation in the first lag disappears after shortening the maturity of the limit-order to less than one day.

Autocorrelation in |rt| As seen from Figure 5.3, the autocorrelation of the pooled absolute returns can be fitted almost perfectly by the exponential fit function, suggesting only short-range dependence of the returns. We obtain the same results regardless of the lag length – the absolute auto- correlation always decays roughly at the exponential rate. We conclude that, contrary to the previous two models, the limit-order model does not produce returns with long-range dependant volatility. So far, only the extended model is able to replicate the stylized fact of long-range dependency in volatility.

Volatility clustering In line with the previous two models, we run the ARMA- TGARCH(1,1) model to uncover volatility clustering in the returns. As seen in Table 5.2, both ARCH and GARCH terms are strongly significant under heteroskedasticity and cluster robust standard errors (the signifi- cance of the autoregressive term in the mean equation was already dis- cussed above). As in the previous two models, the limit-order model also produces returns with clustered volatility. 5. The limit-order model 42

0.42 = Α = 0.20 A 0.191, 0.137 0.4 B = 0.159, Β = 0.00463 0.38 A = 0.398, Α = 0.0609 = Β = 0.15 0.36 B 0.359, 0.00173 0.34 0.10 0.32 0.3 l 0.28 l 20 40 60 80 100 120 140 20 40 60 80 100 120 140

(a) One random seed (b) All seeds

Figure 5.3: Power law (dashed) and exponential decay (dot-dashed) fits for autocorrelation in |rt|, semi-log plot.

ARMA(1, 1)-TGARCH(1, 1) cons 0.0000690 (1.25) (2.42) ARMA L.ar −0.577∗∗∗ (−24.46) (−78.05) L.ma 0.483∗∗∗ (14.71) (61.27) ARCH L.arch 0.0604∗∗∗ (24.27) (47.08) L.tarch −0.0134∗∗∗ (−11.97) (−13.58) L.garch 0.945∗∗∗ (392.35) (828.26) cons 0.000000657∗∗∗ (9.20) (15.71) t-statistics in parentheses. 3rd column: cluster and heteroskedasticity-robust standard errors used. 4th column: heteroskedasticity-robust standard errors used. * p < .1, ** p < .05, *** p < .01

Table 5.2: ARMA(1, 1)-TGARCH(1, 1) model regression results, limit-order model 5. The limit-order model 43

We also run the GARCH estimation for higher lags – the ARCH effect was significant up to the 4th lag, while the GARCH effect was significant up to the 3rd lag.

In conclusion, the limit-order model, though very different by construction to the previous two models, is able to replicate the majority of the selected stylized facts. One improvement over both the baseline and extended models is that it consistently yields uncorrelated returns, which is an especially desirable property of any ABM modelling decision making of traders on financial markets. On the other hand, the autocorrelation in absolute returns decays faster than as a power law of the lag l, suggesting only short-range dependence in the volatility of the returns. This, however, is in slight contradiction with the GARCH estimation results in Table 5.2 where the L.arch and L.garch term almost sum to one. As Cont(2005, p. 4) points out, the closer this sum is to one, the slower the decay of the absolute returns. However, as the sum in our case is significantly not different from one, the estimation of the GARCH effect is more problematic as it suggests an integrated (and thus non-stationary) process in the returns. We run the GARCH model with an integrated ARMA mean equation with only small effect on the magni- tude of the ARCH and GARCH coefficients (since it is the GARCH model that is unit-root, not the mean). We thus run the Integrated GARCH (IGARCH) model under three different assumed error distributions (normal, Student’s t and generalized error distribution). The results of all three IGARCH models are almost identical in size and significance to the ones in Table 5.2 and are omitted. For theoretical issues linked to IGARCH, please see Tsay, 2005, p. 122. Chapter 6

Concluding discussion

The goal of this thesis is to introduce an ABM that could make a solid contribu- tion to the family of existing ABMs in economics and finance. We focus on the applicability of the boids model, originally created in biology for the purposes of modelling flocking of birds and other animals. We propose three different models, in which the underlying dynamics are driven by the boids algorithm, described in Chapter 2. To be able to answer the research questions proposed in the introduction, we set as an objective measure the ability of our derived models to replicate some of the stylized facts in financial markets. In the following section, we discuss some statistical issues encountered dur- ing writing of this thesis. In the last part of the concluding discussion, we answer each of the research questions as listed in Section 1.4.

Statistical issues

Cont(2001, p. 231) discusses the validity of the ACF when the underlying data are non-normal (especially fat-tailed). For computing autocorrelation in a given variable, the assumption of covariance stationarity is necessary to hold. However, since we have found statistical evidence of the GARCH effect in the simulated returns, this assumption does not hold in finite samples (even though it still might hold asymptotically). To treat this issue, it is possible to divide the (heteroskedastic) returns by the conditional variance obtained from GARCH estimation. Consequently, these modified returns are no longer heteroskedastic and thus suitable for computation of autocorrelations. Similar discussions also apply to the absolute returns, which are also most likely non-stationary. In the GARCH model, the positive excess kurtosis of the returns can also 6. Concluding discussion 45 be accounted for by imposing different distributional assumption on the errors in the GARCH estimation. Hall & Yao(2003) specifically address the issues of heavy-tailed errors in GARCH models and introduce fairly sophisticated meth- ods and supporting theory for their treatment. Of course, in the discussion above we implicitly assumed that GARCH is the correct model for the condi- tional variance, which alone can be subject to discussion and is beyond the scope of this thesis. In the last part of this thesis, we address each of the research questions as listed in Section 1.4.

Is the model easily interpretable for the purposes of economics and finance?

Since there had been no application of the boids model in economics or finance until now, we strove to provide solid economic background and intuition for most of the variables and parameters in the models as well as for the resulting dynamics. While some parameters of the model have a direct interpretation (e.g. observable distance δ to model bounded rationality, herding threshold τ to control the risk-averseness of the agents or critical probability pc to introduce error-proneness), other parameters such as the direction d or the position P of the agents are only part of the “engine” of the models and have no importance in the interpretation of the results. Nevertheless, the main message is that the boids model can be used and interpreted in economic modelling as shown by our, however prototypical, three models.

Does it outperform other ABMs in modelling economic be- haviour and expectations?

As already mentioned in the introduction, we measure the performance of our model in terms of the ability to replicate the empirical properties of the real world data, or the stylized facts. There is a myriad of ABMs that have success- fully replicated some of the stylized facts listed in this thesis. Hommes(2006, p. 34) presents a coherent summary of the literature on ABMs that successfully imitate the stylized facts of no autocorrelation, volatility clustering and long- range dependence, measured by the persistence of autocorrelation in absolute or squared returns. 6. Concluding discussion 46

In Table 6.1 we present a summary of the performance of all three models. We see that all three models yield returns with fat tails whose distribution is non-normal – a feature not exhibited by the perfect rationality models. The deficiency of the baseline and extended models is that they both produce auto- correlated returns – a property that is not commonly observed in reality since it implies the possibility of predicting returns and arbitrage. The limit-order model, on the other hand, produces uncorrelated returns along with the replica- tion of all other stylized facts except negative skewness (however, as mentioned above, the limit-order is fairly sensitive to parameter modification). We also include a stylized fact that is not easily replicated – negative skew- ness of the return distribution. In fact, to the best of our knowledge, there is no ABM that would consistently produce extreme negative returns more likely than the positive ones. Nevertheless, our model is no exception. Even though during some of the simulations we encountered strongly negatively skewed re- turns, it cannot be explained by the construction of our models. Indeed, we have observed negatively and positively skewed returns with equal frequency. As a whole, our models are comparable to other well-known ABMs by repli- cating most of the stylized facts on financial markets. Notwithstanding, none of the three models reproduced all stylized facts at once. Even though our models can be combined to produce more desirable results, this would also lead to higher parametrisation and complexity in comparison to other ABMs.

model baseline extended limit-order Excess kurtosis  Negative skewness  Non-normality  No autocorrelation in rt  Power-law decay  Volatility clustering 

Table 6.1: Summary of the main results of our models

Is it parsimonious enough to be easily applied to new prob- lems?

The underlying boids model is fairly simple and only becomes more compli- cated with increasing complexity of the additional behavioural rules laid upon 6. Concluding discussion 47 the agents. In the baseline and extended model, the law of motion is governed by the utility maximisation of the agents (imitating the more successful neigh- bours), while, in the limit-order model, the law of motion is independent of the actions of the agents. The boids model is thus flexible and allows for many modifications and possible ways of interpreting its defining parameters. Nevertheless, the model can only be as succinct as the behavioural rules imposed on it. In the extended model and the limit-order model, we have introduced many new unique parameters that, on one side, lead to richer dy- namics and desired results but, on the other side, might have worsened the brevity of the model. In summary, the boids algorithm itself is succinct and easy to implement but the applicability of the final model depends largely on its purpose and specific behavioural rules.

Is it robust to parameter modification?

We have performed a complete sensitivity analysis for the baseline model only, as it later serves as a benchmark for comparison with the subsequent models (see Section 3.5). As described thereat, some parameter changes have little or no impact on the dynamics of the model (such as the intensity of choice β) while some other parameter are more important (such as the threshold parameter τ, the fundamentalist cost C or the critical probability pc). However, the change in the dynamics of the model is generally easily explained by the economic theory. Only in the case of the trend following strength g, it is not possible to predict the threshold value of g after which the modelled returns explode due to excessive trend following. The extended model shows a similar level of robustness towards parameter modification as the baseline model. Both the baseline and extended models yield qualitatively similar results across different random seeds. The limit-order model exhibits the highest level of sensitivity towards pa- rameter changes, most likely because the emphasis is put solely on the pricing mechanism, whose importance is mitigated in the previous models by tighter interactions among agents, the survival mode and the roulette-wheel selection. In comparison to the first two models, the change in dynamics in the limit- order model triggered by changes in parameters is harder to justify from the viewpoint of economic theory. 6. Concluding discussion 48

What are the limits and possible extensions of the model?

As mentioned above, one of the main problems of some of our models was excessive parametrisation. Aggregating the three models together, we have defined 25 unique parameters, listed in Table 6.2 along with their importance (sensitivity to changes in their values). We see that the extended model is the most parametrized of the three, with 8 important parameters (or parameters whose change has a notable impact on the model dynamics), followed by the baseline and limit-order model, each with 6 important parameters.

Model† Model Model Par (1) (2) (3) Par (1) (2) (3) Par (1) (2) (3)

max N ˜˜˜ C ˜˜ g1 ˜ 2 max S ˜˜˜ σ ˜˜ g2 ˜ R ˜˜ gmin ˜ ∆t ˜ c p ˜˜ gmax ˜ ζ ˜ max ν ˜˜˜ bmin ˜ n ˜ min δ ˜˜˜ bmax ˜ n ˜ max τ ˜˜ γ ˜ k ˜ g ˜ L ˜ β ˜ λ ˜ † The model numbers correspond to baseline, extended and limit-order model, respectively.

Table 6.2: List of parameters in our models along with their impor- tance – red: important parameters, blue: less important parameters

Another problem closely linked to parametrisation is the model validation – in other words, how we decide which parameter values should be used in our model. Generally, model validation is one of the weakest parts of ABMs. In some cases, experiments with human subjects might help to define the parameters of interest – see Heckbert et al. (2010) for concrete examples of model validation. In our models, we face similar issues – we are not always able to justify the choice of the parameters other than by the observation that it“works”. See Dosi et al. (2013) for a similar system of parametrisation – setting the benchmark parameter values and then performing a sensitivity analysis. Winker & Gilli(2001) present an interesting solution to the problem of model validation, named the “indirect method of parameter estimation”, which defines the parameter values by minimizing a loss function that is based on the difference in empirical moments between some reference dataset (e.g. daily 6. Concluding discussion 49 stock returns, as in our case) and the data generated by the ABM in question. While this method is economically appealing, it is only applicable to very simple ABMs. For highly parametrized models (such as ours), the indirect estimation is computationally infeasible. The validation of the parameters thus remains a weakness of our models as well. On the other hand, the underlying boids model is also very flexible and allows for various extensions. The most natural yet simple extension is to allow for distance-proportional weights of the neighbours’ opinions. For very specific purposes, the boids model can also be extended to higher dimensions, at the cost of higher computational demands but, for the purposes of reproducing stylized facts in financial markets, with very little or no qualitative improvement – the only change in the model is induced by adding dimensions to the space where the agents interact, but that alone has no effect on the behavioural rules of the agents. While, in this thesis, we focus solely on the reproduction of stylized facts and left the spatial direction of the model (direction, positions and speed of the agents) uninterpreted, the model might find a wider application in the fields where spatial models are more important. As an example, the spatial ABMs are widely used in ecological and rural economics for the purposes of resource management, land use distribution, and any other social-ecological system that accommodates interactions among agents, non-linearities and self-organizing behaviour of the agents. See Heckbert et al. (2010) for a survey of spatial ABM application in economics. The boids model can also find application in urban economics. For example, the network of agents in the boids model can be fitted onto a transportation map of a city, confining the agents to pass through a specific set of paths, and impose behavioural rules related to congestion (or herding as in the original boids model), estimated energy consumption and allowing adaptive learning rules would prevent agents passing through paths that are frequently clogged. Bibliography

Arifovic, J. (1995): “Genetic Algorithms and Inflationary Economies.” Jour- nal of Monetary Economics 36(1): pp. 219–243.

Arifovic, J. (2000): “Evolutionary Algorithms in Macroeconomic Models.” Macroeconomic Dynamics 4(03): pp. 373–414.

Arifovic, J. & J. Ledyard (2012): “Individual Evolutionary Learning, Other- Regarding Preferences, and The Voluntary Contributions Mechanism.” Jour- nal of Public Economics 96(9-10): pp. 808–823.

Back¨ , T. (1996): Evolutionary Algorithms in Theory and Practice: Evolution Strategies, Evolutionary Programming, Genetic Algorithms. Oxford univer- sity press.

Bao, T., C. Hommes, & T. Makarewicz (2014): “Bubble Formation and (In)efficient Markets in Learning-to-Forecast and -Optimize Experiments.” CeNDEF Working Papers 14-01, Universiteit van Amsterdam, Center for Nonlinear Dynamics in Economics and Finance.

Blickle, T. & L. Thiele (1995): “A Mathematical Analysis of Tournament Selection.” In “ICGA,” pp. 9–16.

Bollerslev, T. (1986): “Generalized Autoregressive Conditional Het- eroskedasticity.” Journal of Econometrics 31(3): pp. 307–327.

Bollerslev, T., R. Y. Chou, & K. F. Kroner (1992): “ARCH Modeling in Finance : A Review of the Theory and Empirical Evidence.” Journal of Econometrics 52(1-2): pp. 5–59.

Brock, W. & P. De Lima (1995): “Nonlinear Time Series, Complexity Theory, and Finance.” Working papers 9523, Wisconsin Madison - Social Systems. Bibliography 51

Brock, W. A. & C. H. Hommes (1998): “Heterogeneous Beliefs and Routes to Chaos in a Simple Asset Pricing Model.” Journal of Economic Dynamics and Control 22(8-9): pp. 1235–1274.

Brockwell, P. J. & R. A. Davis (2002): Introduction to Time Series and Forecasting, volume 1. Taylor & Francis.

Cameron, C. & P. Trivedi (2005): Microeconometrics. Number 9780521848053 in Cambridge Books. Cambridge University Press.

Chiarella, C., G. Iori, & J. Perello´ (2009): “The Impact of Heteroge- neous Trading Rules on the Limit Order Book and Order Flows.” Journal of Economic Dynamics and Control 33(3): pp. 525–537.

Cont, R. (2001): “Empirical Properties of Asset Returns: Stylized Facts and Statistical Issues.” Journal of Economic Literature 1: pp. 223–236.

Cont, R. (2005): “Long Range Dependence in Financial Markets.” In“Fractals in Engineering,” pp. 159–180. Springer.

Cont, R., M. Potters, & J.-P. Bouchaud (1997): “Scaling in Stock Market Data: Stable Laws and Beyond.” Science & Finance (CFM) working paper archive 9705087, Science & Finance, Capital Fund Management.

D’agostino, R. B., A. Belanger, & R. B. D’Agostino Jr (1990): “A Suggestion for Using Powerful and Informative Tests of Normality.” The American Statistician 44(4): pp. 316–321.

De Grauwe, P. (2012): “Booms and Busts in Economic Activity: A Behav- ioral Explanation.” Journal of economic behavior & organization 83(3): pp. 484–501.

Dosi, G., G. Fagiolo, M. Napoletano, & A. Roventini (2013): “Income Distribution, Credit and Fiscal Policies in an Agent-Based Keynesian Model.” Journal of Economic Dynamics and Control 37(8): pp. 1598–1625.

Duffy, J. (2006): “Agent-Based Models and Human Subject Experiments.” In L. Tesfatsion & K. L. Judd (editors), “Handbook of Computational Economics,” volume 2 of Handbook of Computational Economics, chapter 19, pp. 949–1011. Elsevier. Bibliography 52

Engle, R. (1982): “Autoregressive Conditional Heteroscedasticity with Esti- mates of the Variance of United Kingdom Inflation.” Econometrica 50(4): pp. 987–1007.

Fama, E. F. (1970): “Efficient Capital Markets: A Review of Theory and Empirical Work.” Journal of Finance 25(2): pp. 383–417.

Farmer, J. D. & D. Foley (2009): “The Economy Needs Agent-based Mod- elling.” Nature 460(7256): pp. 685–686.

Gopikrishnan, P., V. Plerou, X. Gabaix, & H. E. Stanley (2000): “Sta- tistical Properties of Share Volume Traded in Financial Markets.” Quantita- tive finance papers, arXiv.org.

Hall, P. & Q. Yao (2003): “Inference in ARCH and GARCH Models with Heavy–Tailed Errors.” Econometrica 71(1): pp. 285–317.

Heckbert, S., T. Baynes, & A. Reeson (2010): “Agent-based modeling in ecological economics.” Annals of the New York Academy of Sciences 1185(1): pp. 39–53.

Heemeijer, P., C. Hommes, J. Sonnemans, & J. Tuinstra (2009): “Price Stability and Volatility in Markets with Positive and Negative Expectations Feedback: An Experimental Investigation.” Journal of Economic Dynamics and Control 33(5): pp. 1052–1072.

Holland, J. H. (1975): Adaptation in Natural and Artificial Systems. Ann Arbor, MI: University of Michigan Press. Second edition, 1992.

Hommes, C. (2013): Behavioral Rationality and Heterogeneous Expectations in Complex Economic Systems. Number 9781107019294 in Cambridge Books. Cambridge University Press.

Hommes, C. H. (2006): “Heterogeneous Agent Models in Economics and Fi- nance.” In L. Tesfatsion & K. L. Judd (editors), “Handbook of Com- putational Economics,” volume 2 of Handbook of Computational Economics, chapter 23, pp. 1109–1186. Elsevier.

Iori, G. & C. Chiarella (2002): “A Simple Microstructure Model of Double Auction Markets.” Computing in Economics and Finance 2002 44, Society for Computational Economics. Bibliography 53

Jarque, C. M. & A. K. Bera (1980): “Efficient Tests for Normality, Ho- moscedasticity and Serial Independence of Regression Residuals.” Economics Letters 6(3): pp. 255–259.

Kahneman, D. & A. Tversky (1973): “On the Psychology of Prediction.” Psychological review 80(4): p. 237.

Kantelhardt, J. (2009): Encyclopedia of Complexity and Systems Science. Springer.

Keynes, J. M. (1936): “The General Theory of Interest, Employment and Money.”

Kyle, A. S. (1985): “Continuous Auctions and Insider Trading.” Econometrica: Journal of the Econometric Society pp. 1315–1335.

LeBaron, B. (2006): “Agent-based Computational Finance.” In L. Tesfat- sion & K. L. Judd (editors), “Handbook of Computational Economics,” vol- ume 2 of Handbook of Computational Economics, chapter 24, pp. 1187–1233. Elsevier.

Ljung, G. M. & G. E. P. Box (1978): “On a Measure of Lack of Fit in Time Series Models.” Biometrika 65(2): pp. 297–303.

Lux, T. & S. Schornstein (2003): “Genetic Learning as an Explanation of Stylized Facts of Foreign Exchange Markets.” Economics working papers, Christian-Albrechts-University of Kiel, Department of Economics.

Miller, B. L. & D. E. Goldberg (1995): “Genetic Algorithms, Tournament Selection, and the Effects of Noise.” Complex Systems 9(3): pp. 193–212.

Reynolds, C. W. (1987): “Flocks, Herds and Schools: A Distributed Behav- ioral Model.” In “ACM SIGGRAPH Computer Graphics,” volume 21, pp. 25–34. ACM.

Silverman, B. W. (1986): Density Estimation for Statistics and Data Analy- sis, volume 26. CRC press.

Simon, H. A. (1962): “The Architecture of Complexity.” In “Proceedings of the American Philosophical Society,” pp. 467–482.

Simon, H. A. (1978): “Rational Decision-Making in Business Organizations.” Nobel Prize in Economics documents 1978-1, Nobel Prize Committee. Bibliography 54

Tedeschi, G., G. Iori, & M. Gallegati (2012a): “Herding effects in order driven markets: The rise and fall of gurus.” Journal of Economic Behavior & Organization 81(1): pp. 82–96.

Tedeschi, G., G. Iori, & M. Gallegati (2012b): “Herding Effects In Or- der Driven Markets: The Rise And Fall Of Gurus.” Journal of Economic Behavior & Organization 81(1): pp. 82–96.

Tsay, R. S. (2005): Analysis of Financial Time Series, volume 543. John Wiley & Sons.

Winker, P. & M. Gilli (2001): Indirect Estimation of the Parameters of Agent Based Models of Financial Markets. Citeseer. Appendix A

Appendix

Silverman’s plug-in bandwidth estimate minimizes the integrated mean-squared error under the Gaussian kernel and the assumption of normality of the data. The bandwidth formula is

0.9m h = where m = min (std(X), iqr(X)) (A.1) n0.2 where iqr is the inter-quartile range of the data vector X. See Cameron & Trivedi(2005, p. 304) for details and various methods for bandwidth selection.

0.6

0.5 NASDAQ Normal 0.4

0.3

0.2

0.1

-2 0 2 4

Figure A.1: Gaussian kernel density estimate of NASDAQ log-returns rt using Silverman’s plug-in bandwidth estimate A. Appendix II

1.0

0.8

0.6 Β = 0.3 Β = 0.5 0.4 Β = 1.0 Β = 2.5 0.2

UF -UTr -4 -2 0 2 4

Figure A.2: The probability function for various values of β

One random seed Var Mean Stdev Min Max Skewn. Kurt.

rt 0.076 0.435 −1.407 1.658 0.048 3.215 T r Ut 0.002 0.017 −0.067 0.118 0.993 8.624 F Ut 0.002 0.029 −0.090 0.222 1.984 10.046 T r ξt 0.759 0.085 0.453 0.987 −0.195 3.241 ρt 0.028 0.034 0.000 0.220 1.313 4.623

All seeds Var Mean Stdev Min Max Skewn. Kurt.

rt −0.000 0.269 −0.950 0.999 0.049 3.348 (0.000) (0.010) (0.126) (0.343) (0.223) (1.742) T r Ut 0.002 0.022 −0.226 0.126 −0.242 24.593 (0.002) (0.025) (0.612) (0.027) (3.454) (58.517) F Ut 0.007 0.076 −0.145 1.264 3.962 41.424 (0.020) (0.204) (0.079) (4.294) (3.139) (58.706) T r ξt 0.747 0.118 0.328 0.988 −0.493 3.105 (0.034) (0.017) (0.069) (0.018) (0.255) (0.522) ρt 0.046 0.038 0.000 0.221 0.895 3.694 (0.009) (0.004) (0.000) (0.029) (0.180) (0.542) Standard errors in parentheses.

Table A.1: Summary statistics of the key variables in the baseline model, T = 2000, Rep = 100 replications A. Appendix III

0.7 1.4 0.6 1.2 rt rt Normal 0.5 Normal 1.0 0.4 0.8

0.6 0.3

0.4 0.2

0.2 0.1

-1 0 1 2 -2 0 2 4 (a) Baseline model (b) Extended model

30

25 rt Normal 20

15

10

5

-0.05 0.00 0.05 0.10 (c) Limit-order model

Figure A.3: Kernel density estimate of the returns rt, pooled data from 100 simulation runs (in case of the baseline and extended model), for all three models

8 Tr Tr 0.15 U 6 U UF UF 0.10 4 0.05 2 0.00 0 t t 500 1000 1500 2000 500 1000 1500 2000

(a) Fitnesses C = 0 (b) Fitnesses under C = 0.5

Figure A.4: U T r and U F under C = 0 and C = 0.5, baseline model A. Appendix IV

Variable Range β {0, 0.5, 1.0, 1.5, 2, 2.5, 3, 3.5, 4, 5, 10, 30, 50, 100, 1000} C {0, 0.01, 0.02, 0.1, 0.3, 0.5, 2, 5, 10, 30, 100, 1000} pc {0, 0.01, 0.05, 0.3, 0.4, 0.5, 0.6, 0.8, 0.9, 0.95, 0.97, 0.99, 1} δ {0, 1, 5, 10, 30, 50, 100, 150, 250, 400, 500} g {0, 0.01, 0.5, 0.7, 1, 1.15, 1.5, 2, 5, 10} τ {0, 2, 8, 15, 30, 60, 75, 105, 135, 150} N {1, 10, 30, 50, 100, 150, 200, 250, 500}

Table A.2: Sensitivity analysis in the baseline model: range of pa- rameter values

Λl 1.0ìçòôæà æ Λ = 0.1 ç à Λ = 0.3 ì Λ = 0.5 0.8 ô ç Λ = ç ò 0.7 ò Λ = 0.8 ô ç ô 0.6 ç ç Λ = 0.9 ô ç ì ò ç ç 0.4 ô ç ò ô ç à ì ò ô 0.2 ô ò ô ì ò ô æ à ô ì ò ò à ì ò ò æ æ æà æà ìæà ìæà ìæà ìæà ìæà l 0 2 4 6 8 10

Figure A.5: Decay speed of xt−l in the extended model depends on the value of λ A. Appendix V

One random seed Var Mean Stdev Min Max Skewn. Kurt.

rt −0.017 0.475 −2.343 3.319 0.551 7.808 g¯t 0.057 0.260 −0.781 0.855 −0.187 3.026 ¯ bt −0.019 0.322 −1.077 0.835 −0.127 2.630 ¯ Ut 0.025 0.092 −0.395 2.168 10.973 200.470 pf ξt 0.002 0.010 0.000 0.120 5.650 41.475 ρt 0.084 0.057 0.000 0.386 1.048 4.240

All seeds Var Mean Stdev Min Max Skewn. Kurt.

rt 0.000 0.683 −7.132 5.979 −0.333 40.805 (0.003) (0.436) (15.590) (8.855) (3.668) (110.401) g¯t 0.024 0.060 −0.192 0.189 −0.052 0.706 (0.045) (0.109) (0.351) (0.343) (0.109) (1.286) ¯ bt −0.004 0.073 −0.231 0.190 −0.032 0.614 (0.015) (0.132) (0.421) (0.346) (0.068) (1.117) ¯ Ut 0.015 0.358 −2.588 13.485 3.354 88.948 (0.107) (4.331) (33.255) (172.753) (7.512) (241.680) pf ξt 0.001 0.002 0.000 0.029 1.453 12.635 (0.001) (0.004) (0.000) (0.055) (2.718) (26.082) ρt 0.027 0.020 0.000 0.135 1.362 10.522 (0.042) (0.027) (0.000) (0.171) (2.335) (22.868) Standard errors in parentheses.

Table A.3: Summary statistics of the key variables in the extended model, T = 2000, Rep = 100 replications A. Appendix VI

One random seed Var Mean Stdev Min Max Skewn. Kurt.

pt 926.391 139.334 562.758 1185.684 −0.643 2.607 rt 0.000 0.015 −0.064 0.078 0.179 5.211 vt 954.447 314.029 254.000 2065.000 0.546 2.794 st 2.594 3.266 0.000 30.024 3.021 15.896 ¯ ζt 0.964 0.014 0.913 0.994 −0.552 2.701

All seeds Var Mean Stdev Min Max Skewn. Kurt.

pt 1083.098 367.343 441.031 1871.443 0.257 2.735 (562.074) (168.917) (324.355) (794.890) (0.746) (2.489) rt 0.000 0.019 −0.081 0.094 0.161 4.862 (0.000) (0.010) (0.045) (0.058) (0.176) (1.710) vt 981.347 347.762 287.560 2166.680 0.523 3.273 (322.924) (169.528) (78.054) (646.594) (0.662) (1.214) st 3.217 5.718 0.001 86.284 4.692 47.965 (1.507) (5.111) (0.001) (104.187) (3.027) (59.935) ¯ ζt 0.962 0.016 0.905 0.997 −0.535 3.340 (0.015) (0.008) (0.032) (0.003) (0.659) (1.260) Standard errors in parentheses.

Table A.4: Summary statistics of the key variables in the limit-order model, T = 20 000, Rep = 100