A Calibration Procedure for Analyzing Stock Price Dynamics in an Agent-Based Framework

In this paper we introduce a calibration procedure suitable for the validation of agent based models. Starting from the well-known financial model of Brock and Hommes 1998, we show how an appropriate calibration technique makes the model able to describe price time series. In particular, we formulate the calibration problem as a nonlinear constrained optimization that can be solved numerically via a gradient-based method. The calibration results show that the simplest version of the Brock and Hommes model, with two trader types, fundamentalists and trend-followers, well replicates the price series of four different markets indices: the S&P 500, the Euro Stoxx 50, the Nikkei 225 and the CSI 300. Moreover, we show how the parameter values of the calibrated model are important to interpret the trader behavior on the different investigated markets. These parameters are then used for price forecasting. To further improve the forecasting, we modify our calibration approach by increasing the trader information set and we show how this new method improves the model’s ability in the prediction of market prices.


Introduction
The growing expansion of the financial sector and its influence on the real economy has made it essential to understand how it operates. In recent decades, in fact, the massive transfer of resources from the productive to the financial sector has characterized the economic systems. This re-allocative process, well known as the "financialization of the economy", is a major cause of the recent financial instability, characterized by recurrent crises of increasing intensity and culminating in the current global crisis 1 (see Orhangazi 2008; Rochon and Rossi 2010).
Financial markets are a powerful channel of prediction and transmission of economic crises making the understanding of their complex behavior important. Some insights into trader strategies and their impact on aggregate variables have been provided by agent-based models. These models have shown that the interactions at the micro-level are crucial in comprehending macro-economic dynamics. The agent-based model approach has highlighted the interplay between the micro and macro levels, revealing the similarities and differences between the overall system and its parts (see Delli Gatti et al. 2011).  (2007,2009) have analyzed how mechanisms of behavioral switching or the coordination of traders' strategies by market mediated interactions (for example by following chartist trading rules) can generate persistence of asset price volatility. In particular, Brock and Hommes, in several papers (1997a, 1997b, 1998), have studied an asset pricing model where traders can switch among different forecasting strategies. The switching mechanism is driven by a fitness measure, which is a function of past realized profits. The price dynamics driven by heterogeneous strategies is capable of explaining a range of complex financial behaviors. Collective behavior, nonetheless, gives rise to the phenomenon known as herding which occurs when agents imitate each other (see Bannerjee 1992;Bannerjee 1993;LeBaron et al. 2009; Tedeschi et al. 2009;Tedeschi et al. 2012). The studies on collective behavioral effects have shown how herding can lead to large price fluctuation and volatility clustering. 1 Different interpretations of the current financial crisis have been shown. In a recent paper, for instance, Delli Gatti et al. (2012) propose an explanation of the crisis which emphasizes the sectoral dislocation following localized technical change in the presence of barriers to labor mobility.
While agent-based models are able to reproduce many of the stock market stylized facts (see Cont 2007), they suffer from a serious weakness. Agent based models are, in fact, very often not calibrated and their outputs not validated against observed data.
This weakness arises from two contrasting aspects of the models. On the one hand the large number of parameters employed by these models might permit to fit with any feature of real data. On the other hand, this large number increases the difficulty of getting analytical expressions for model evaluation. The calibration and validation of agent-based models is, therefore, becoming crucial for researchers working with this approach (see Troitzsch 2004;Fagiolo et al. 2007). Despite the efficiency of these tools in the studying a wide set of issues in economics, the number of validated agent based models is not large. Most of these validated models are based either on a descriptive output validation or on an input validation 2 (see Bianchi et al. 2007; Bianchi et al 2008; Cirillo and Gallegati 2011). However, the important field of the predictive output validation (see Hassan et al. 2013), has essentially not been addressed (see Tesfatsion 2013). Furthermore, the calibration of the AB models' parameters suffers from some weaknesses. Most of the calibration techniques are based on "trial and error" procedures (see Brock and Hommes 1997b;Hommes 2001), which produce mismatches between real and simulated time series. Important exceptions can be found in the results of Winker and Gilli (2001) and Gilli and Winker (2003) where the authors present an agent-based exchange market model and introduce a global optimization algorithm for calibrating the model's parameters via simulation. Other important contributions are Alfarano et al. 2005Alfarano et al. , 2006Alfarano et al. , 2007. These authors obtain the analytical solution for the return probability distribution of a simple agent-based financial market model, and, consequently, estimate the model parameters via maximum likelihood.
The aim of our paper is the development of a rigorous calibration procedure designed to validate agent-based models. To this end, we undertake the estimation of the parameters of the agent based model developed by Brock and Hommes 1998 (BH hereinafter), using market data. The BH model, which uses the familiar demand-supply cobweb framework (see Muth 1961) and considers an adaptive belief system where heterogeneous agents can choose among different trading strategies, is well suited for our calibration exercise. It is, in fact, very popular in the ABM literature, as well as being analytically tractable and involving few parameters. The use of a wellknown framework allows us to focus more on the calibration process than on the model itself. The calibration procedure that we propose identifies the set of model parameters by minimizing a loss function. This function is the sum of the squared residuals which are computed as the difference between the observed and simulated market price at given date. This approach, known as least squares calibration, is commonly used in asset and option pricing (see Andersen and Andreasen, 2000;Avellaneda et al. 2000;Fouque et al. 2001). We solve the resulting minimization problem numerically via a gradient-based method (see, for example, Andersen and Andreasen 2000; Bates 1996; Recchioni and Scoccia 2000). We show that a simplified version of the BH model, considering only fundamentalist and trend-follower strategies, is able to reproduce the daily price time series of four different markets indices (i.e. the S&P 500, the Euro Stoxx 50, the Nikkei 225 and the CSI 300). Moreover, the calibration of the model parameters provides some information on the micro market behavior. In fact, the values of the parameters resulting from model calibration on different markets show the differences and the similarities in the behavior of agents operating in the markets considered. This means we are able to answer questions about risk aversion, imitative behavior and agents' strategies in the investigated markets.
Our work is closely related to Boswijk et al. 2007. In their paper the authors consider the BH model and estimate the model parameters by nonlinear least squares using yearly US stock price data. Their analysis focuses mainly on the agents' switching behavior between fundamentalists and trendfollowers. Specifically, their estimation results show statistically significant behavioral heterogeneity and substantial time variation in the average sentiment of investors. In this paper, instead, we are more interested in analyzing the accuracy of our calibration procedure in reproducing short-run price dynamics. Interestingly, although we consider a different time frequency and a different time window, we discover quite similar features in the traders' behavior. As in Boswijk et al. 2007, in the markets we find a switching between the two predictors and a dominance of the trend following regime. The estimation method we propose has some similarities with Boswijk et al. but also many significant differences. Both calibration procedures are nonlinear optimization problems solved numerically via a gradient method. The first difference between this work and that of Boswijk et al. 2007 is the algo-rithm used to solve the optimization problem. Specifically, our constrained optimization problem is solved via a metric variable steepest descent method (see Recchioni and Scoccia 2000). This method is an iterative procedure that starts from an initial point in the feasible region and moves in the direction of minus the gradient in a suitable metric. This approach has two important advantages. Firstly, the points generated by this method belong to the feasible region when the starting point is also in this region. Secondly, the gradient is rescaled in order to ensure the convergence of the iterative process. The second important difference concerns the BH model specifications. We both use an evolutionary fitness based on realized profits for modeling the agent switching between different forecasting expectations. However, Boswijk et al. estimate the BH model with no memory (i.e. the fitness equals realized profit in the previous period) while we estimate the model with infinite memory (i.e. the fitness equals total wealth as given by accumulated realized profits over the entire past). We consider this scenario not only because the analyzed time series seem to have very long memory, but also because, theoretically, it is not clear whether, in the case of infinity memory, the price dynamics are stable (see Hommes 2001). The last relevant difference is in the investigation approach. Boswijk et al. estimate the model in order to investigate whether deviations from the fundamental price are significant. They define the asset fundamental value using the Gordon growth model which assumes an exogenously given stochastic process. We, on the other hand, do not assume any noise in prices and, therefore, our calibration procedure is deterministic.
Having successfully proven our calibration for input and output validation, we also test its efficiency in generating predictive output validation. This exercise requires not only that the procedure describe aggregate regularities, but that it also forecast macro dynamics. To this end, we investigate how our calibration mechanism is able to provide reasonable price trend predictions. We see the opportunity to improve these predictions by introducing a second calibration approach able to incorporate market information in the trader information set. This method (ABH method) differs from the previous one in that it assumes that agents, in order to calculate the simulated market price, use the values of the spot price observed in the real stock market in the preceding period. We study how these two methodologies compete in describing and forecasting market prices. Our findings show a good performance of both procedures in data validation, with the ABH one slightly outperforming the BH one.
The rest of the paper is organized as follows. In Section 2 we describe the BH model. In Section 3 we formulate the calibration problems and their numerical solution. In Section 4 we present the numerical experiments on four market indices. Finally, in Section 5 we draw conclusions.

The mathematical structure of the model
This section describes the asset pricing model with heterogeneous beliefs developed in Brock and Hommes 1998. Considering its simplicity, its analytical tractability, and the small number of parameters, this model is well suited for the calibration which is the main purpose of our work.
Traders can either invest in a risk free asset, which is perfectly elastically supplied at a gross return R = (1 + r) > 1, or in a risky one, which pays an uncertain dividend y and with a price ofp. Wealth dynamics is given by where W t+1 ,p t+1 and y t+1 are random variables and z t the number of the risk asset shares purchased at time t.
In the market there is a publicly available information set on past prices and dividends so that we can define the conditional expectation, E t , and variance V t . We assume that agents are heterogeneous in that they have different forecasts (beliefs) about conditional expectation and variance. In particular, E h,t and V h,t are the beliefs of trader h on these operators. Each investor is assumed to be a myopic mean-variance maximizer so, her demand z h,t for the risk asset solves i.e., with α to be the risk aversion parameter and σ 2 the conditional variance which is assumed constant and equal for all traders. The market equilibrium equation, in the case of zero supply of outside shares and of different trader types h, can be written as: where n h,t denotes the fraction of agents h at time t.
In a world with identical and homogeneous traders, from eq. (4), we can obtain the arbitrage market equilibrium equation with rational expectations 3 : where p * t is the fundamental price and E t the conditional expectation on the information set I t = [p t−1 ,p t−2 , ...; y t−1 , y t−2 , ...].

Agents' strategy
Trading happens over a number of periods, denoted by t = 1, ..., T . At the beginning of each trading period t, agents make expectations about future prices and dividends. We assume that agents are heterogeneous in that they have different forecasts ofp t+1 and y t+1 .
It is convenient to define the price deviation from the fundamental: Following Brock and Hommes (1998), we assume that all beliefs are of the form: According to the assumption (7), investors believe that, in a heterogeneous world, prices may deviate from the fundamental value p * t by some function f h depending upon past deviation from the fundamental price. Many forecasting strategies, f h , have been implemented in economic literature 4 , each one corresponding to a different agents' trading rule. In this framework, we use two simple linear trading rules with only one lag. The first one describes fundamentalists, i.e., f h,t ≡ 0, believing that market price will be equal to fundamental price, or equivalently that the deviation x from the fundamental will be 0. The second strategy describes trend followers, i.e., f h,t = gx t−1 , where g is the trend parameter.
We can, now, reformulate the market equilibrium equation (4) as deviation from the fundamental. In particular, substituting the price forecast (see eq. 7) in the market equilibrium equation (4) and using the definition of fundamental price in eq. (5), we obtain the equilibrium equation in deviations from fundamental: In our framework, with fundamentalists and trend followers, eq. (8) simply becomes: with f 1,t to be the fundamentalist strategy, n 1,t the fraction of these traders at time t, f 2,t the trend followers strategy and n 2,t their fraction.

The evolution of the agents' strategy
We, now, describe how trader's strategies are updated over time, that is, how the fractions n h,t of investor types in eq. (8) evolve time by time. We implement an endogenous mechanism of "strategy evolution" based on a fitness parameter given by the accumulated realized profits of investors. Our fitness measure is where z h,t is defined in eq.(3), C h represents the cost of obtaining a "good" forecasting strategy and ω ∈ [0, 1] is a memory parameter.
It is useful to compute the realized excess returns R t in deviation from fundamental to obtain: where E t−1 (p * t +y t )−Rp * t−1 = 0 (for the arbitrage market equilibrium equation with rational expectations (see eq. 5)) and δ t ≡ p * t + y t − E t−1 (p * t + y t ) is a martingale difference sequence. By using Eq.(11), we can reformulate the fitness measure in deviations from the fundamental as: In our simple model, with two trading rules, we can easily derive the fitness of the fundamentalist (h = 1) and of the trend follower (h = 2). Specically, As time goes by, a strategy may become more profitable than the other one in term of fitness. Each agent h starts with her own strategy. Strategies are rewound at the beginning of each period in the following way: each agent h reassesses her own strategy profitability with respect to the competitive one. The probability that a trader chooses the strategy h is given by the 'Gibbs' probability: The rewind algorithm is designed so that the successful strategy gains a higher number of followers n h and thus has a higher probability of being followed. Nonetheless the algorithm introduces a certain amount of randomness, and the more profitable strategy has a finite probability to be not followed in favor of the less successful belief. In this way, we model imperfect information and bounded rationality of agents. The randomness also helps unlocking the system from the situation where all traders follow to the same belief. The parameter β ∈ [0, ∞) in Eq. (14) represents the intensity of choice and answers the question how much traders trust on the information (expectation) about other agents' performances. In some sense, β measures the "imitative behavior". In fact, the most profitable strategy has more followers. This means agents tend to synchronize (or coordinate) their own expectations. Specifically, when β is zero, agents act independently from each other, however, increasing β, agents behave similarly and their rationality increases.

The calibrated model
We calibrate the agent based model described in the previous section with two agent's strategies, i.e., fundamentalists and trend followers. The BH model, which depends on few parameters, allows us to easily associate them to some behavioral features of the investigated stock market or to compare differences and similarities of several stock markets through the values of the calibrated parameters. The BH model is calibrated using two different approaches. The first one uses the deviation from fundamental as in Eq. (8). In this way, we show how the BH model well reproduces some market indices behaviour. The second calibration approach assumes that agents observe the realized spot prices available from the real stock market, instead of the simulated equilibrium market price. This adjusted version of the BH model (ABH model in the following) allows us to include in the trader information set I t the realized spot prices. Specifically, our traders in order to calculate the simulated equilibrium market price at time t = τ use the realized spot price up to t = τ − 1. The ABH model may be used as a tool to generate a satisfactory forecast of stock price dynamics.

The expectation formation mechanism in the calibration
Let us consider a time series of observed market spot prices p o t , t = 0, 1, . . . , τ − 1, τ > 1, where t = 0, t = τ − 1 correspond, respectively, to the first and the last observation dates used in the calibration procedures. Specifically, p o t is the daily closing stock price or the daily closing index value.
Let p h,t = E h,t (p t+1 ), t > 0, h = 1, 2, be the agents simulated expectation on the spot price at time t,p t , t > 0, the simulated equilibrium market price at time t (see Eq. (4)), p * t the fundamental price and, finally,x t =p t − p * t , t > 0, the deviation from the fundamental price.
The following steps identify the time sequence necessary for the calibration of the BH model: Step i 1 ): compute fitness measures of fundamentalists and trend-followers: Step i 2 ): compute the agents' expectation on the spot price: Step i 3 ): compute the simulated equilibrium market price and its deviation from fundamental:x Step i 4 ) if t ≤ τ go to Step i 1 else stop.
We underline that, in the time window of the calibration procedure, we assume the cost, C h , equals zero and the dividend process, y t , constant. Constant dividends imply a constant fundamental price in Eq. (5) and, therefore, the martingale difference sequence δ t in Eq. (13) equals zero 5 . This assumption makes deterministic the proposed calibration process since it does not involve any noise in previous steps.
The calibration procedure for the ABH model requires the same steps i 1 )-i 4 ) but with a relevant difference in the definition of "deviation from fundamental"x t . In particular, this procedure requires a step, i 0 ), which anticipates the previous steps i 1 ) − i 4 ): Step In the step i 0 ) we are substituting the simulated equilibrium market pricep t with the observed spot price p o t . The motivation of this identification lies in the fact that the observed spot price p o t is the effective market price resulting from the transactions in the "real" financial market. In this way, we are assuming that, at time t, our agents know the previous time realized price in the "real" stock market.

Calibration problems and their numerical solution
We now formulate the calibration problems.
Letp BH,t andp ABH,t the simulated equilibrium market price obtained using the BH and ABH models respectively and p o t the observed spot price.
Let R 4 be the four-dimensional real Euclidean space and Θ ∈ R 4 be the vector containing the model parameters to be determined, Θ= (β, g, p * , α) ∈ R 4 , and let M ⊂ R 4 be the set of the feasible parameter vectors defined as follows: The calibration problems considered are formulated as follows: where the objective function F L (Θ) is given by: Problem (22) is a nonlinear constrained least squares problem that we solve with a local minimization algorithm. Specifically, we use a variable metric steepest descent method (see Recchioni and Scoccia 2000). It is an iterative procedure that, given an initial point Θ 0 ∈ M generates a sequence {Θ k }, k = 0, 1, . . ., of feasible vectors (i.e.: Θ k ∈ M, k = 0, 1, . . .) obtained making a step in the direction of minus the gradient of F L with respect to Θ. This gradient is computed in a suitable metric which is defined according to the constraints defined in M. Roughly speaking, the metric is defined by a diagonal positive definite matrix depending on the current point of the iterative procedure and the "new" gradient is the standard gradient multiplied by this matrix. It is important to emphasize that a deterministic model, which is what we consider here, makes the estimation via the variable metric steepest descent method much more robust.
To be more specific the optimization algorithm used to solve problem (22) consists of the following basic steps: where | · | denotes the absolute value of ·, go to item 7; 3 evaluate the gradient (in cartesian coordinates) of the function ∇F L (Θ k );  4 Numerical experiments 4

.1 Data Description
In the numerical experiments we use the daily closing values of four stock market indices: the USA S&P 500, the Euro Stoxx 50, the Nikkei 225 and the CSI 300. We have chosen these indices because they represent four different geographical areas (i.e. USA, Europe, Japan and China, respectively). The currency of each series corresponds to the one of the Country (i.e US dollar, Euro, Yen and Yuan, respectively). The data run from February 25 th 2011 to February 23 th 2012, corresponding to 245 daily observations. Figure 1 shows the re-scaled observed market price (i.e. the re-scaled index values) used in the calibration procedure. The x-axis displays the day index, where t = 1 corresponds to February 25 th 2011 and t = 245 to February 23 th 2012. Figure 1 shows some broken-trend behaviors. For the S&P 500 and Euro Stoxx 50 indices, it occurs at t = 114 − 116 (i.e. August 8-9 2011). In those days, Federal Reserve policy makers were likely to embark on a third round of large-scale asset purchases which have strongly impacted on the two Western indices. The same broken-trend behavior appears in the Nikkei 225 index at t = 10, which corresponds with the Japanese Earthquake of March 11 2011.
In order to calibrate our model, a delicate issue is the choice of the initial point,Θ 0 , of the iterative algorithm described in Steps [1]- [7]. In this regard, we solve the same minimization problem (22) starting from different initial points. Specifically, we generate 400000 initial points uniformly distributed in the following set 6 : The parameter values are chosen as follows: We evaluate the objective functions F BH and F ABH on 400000 points, Θ i = (β ν , g n , p * k , α m , ω j ), ν = 1, 2, . . . , 20, n = 1, 2, . . . , 20, k = 1, 2, . . . , 10, m = 1, 2, . . . , 10, j = 1, 2, . . . , 10, i = 1, 2, . . . , 400000. We, then, sort the vectors containing the values of the objective functions, F BH (Θ i ) and F ABH (Θ i ), in ascending order and use, as starting points, the values of parameters corresponding to the smallest value of the objective functions. Tables 1 and 2 show the starting points used in the BH and ABH calibration procedures.  Tables 1 and 2 show the value of parameters corresponding to the smallest value of the objective functions (i.e. our starting points in the calibration 6 Initial points of each market index have been selected by using the set S.  observe that the initial points for both calibration procedures are quite similar, with the only exception being for α and β in the two eastern markets. The selection of the same set of initial points by both methods indicates the ability of the BH model in describing the market behavior through the value of parameters. The two methods, in fact, only differ in the definition of the past market equilibrium price: the BH uses the simulated equilibrium price while the ABH the observed spot price. Given that the introduction of the observed spot price does not generate different information from that obtained using the simulated equilibrium price we can conclude that the BH model already fully captures all the information contained in the data. In the first experiment, we investigate the efficacy of our calibration process in replicating daily price time series. We solve problem (22) for the BH and ABH approaches with τ = 200 (i.e. from February 25 th 2011 to December 16 th 2011) and M iter = 10000. In both calibration procedures, we fix the parameters r = 0.01/250 (daily risk free return), σ = 0.1 and ω = 1. The initial point of the traders' fraction, n h,0 , is 1/2. The initial values of the remaining parameters are fixed as in Tables 1 and 2. In the calibration procedure we do not estimate the parameter ω for two important reasons. First the choice of ω = 1 (i.e. the so-called infinity memory case) is supported by the analysis on starting points (see Tables 1 and 2). In fact, this value corresponds to the smallest values of the objective function for all indices of the BH model and for many indices of the ABH model. Second the dynamics generated by the infinity memory case are controversial. From a theoretical point of view it remains an open question whether, in this circumstance, fundamentalists are able to stabilize the price towards its fundamental value and can drive trend-followers out of the market (see Brock and Hommes 1998;Hommes 2001). From an empirical point of view the BH model has only been estimated in the case of zero memory (see Boswijk et al. 2007). To cope with these shortcomings, we have decided to focus on the case of infinite memory, i.e. ω = 1. Tables 3-4 show the optimal parameters obtained by the BH and ABH calibration procedures. Since both our calibration procedures are determin- istic (i.e they do not include any noise in the simulated equilibrium market price), the confidence interval of the estimated values of parameters in Ta-    Err.) and biases confirm that the parameters are statistically significant. Comparing the two tables, we observe that for both procedures the optimal values of the investigated parameters are quite similar with the except of α and β on the two eastern markets. The interpretation of these model parameters is substantially the same as the one given in the analysis of the starting points. On the one hand, similarities between the two tables reinforce our belief of the ability of the BH model to accurately interpret the dataset. Given that the value of parameters obtained by following a simple deterministic calibration (i.e. the BH procedure) does not deviate signif- 7 The software is free downloadable from the website http : //www.jstatsof t.org/v29/105/. icantly from that obtained introducing a noise coming from the observed spot price 8 (i.e. the ABH procedure), we can conclude that the BH model nicely describes market behaviors. On the other hand, differences in the values of the parameters α and β show that the objective functions are relatively independent of these parameters. We emphasize, however, that the intensity of choice, β, is of little significance in switching models (see Boswijk et al. 2007;Teräsvirta 1994).
The analysis of the calibrated parameters of the four indices shows there are differences and similarities in the behavior of traders operating in different geographical areas. For the S&P 500 and the Euro Stoxx 50 indices, the intensity of choice β is significantly larger than for the Nikkei 225 and the CSI 300. This indicates, according to the interpretation of the implemented ABM framework, that in the first two financial markets there is a stronger collective behavior. In the two Asian markets the intensity of choice β is close to zero meaning that the agents' strategies are independent. In all the investigated markets, our results show that the trend follower behavior is predominant. As shown by Hommes (2001), when we have a sufficiently large value of the trend parameter g (i.e. g > 1+r), trend-followers can destabilize the system and prices may not converge to the fundamental. Moreover, it is important to emphasize that the value of the parameter g is approximately 2. This value of g has been found also in other studies involving S&P 500 index (see Boswijk et al. 2007). This suggests that, even considering different scenarios, such as annual observations and a model with zero memory (i.e. ω = 0), as in Boswijk et al. 2007, the persistence of the trend-following strategy and its ability to deviate prices from the fundamental is a constant feature in financial markets. The value of the risk aversion parameter α is also very large in all considered markets. This finding can be explained by the persistent financial crisis in the considered period which induces agents to be more cautious. As expected, the values of the ABH objective function, F ABH are smaller than those of the BH one. This is consequence of the replacement, in the ABH calibration procedure, of the simulated equilibrium market price,p, with the observed spot market price, p o , at each time step.
In Figures 4 and 5 we compare, for the four market indices, the time series of the observed market price, p o t , with the simulated equilibrium market price,p t , (i.e. the simulated prices obtained in the final step of the iterative   Table 3. Panels (a), (b), (c), (d) show the fitting of the S&P 500, Euro Stoxx 50, Nikkei 225 and CSI 300 indices respectively. procedure) and we show the corresponding fractions of fundamentalists, n 1,t , and trend-followers, n 2,t . All simulated time series use, as input, the calibrated parameters obtained at the final iteration step of the BH and ABH procedures respectively. It is worth noting that while the BH simulated series (see Figure 4) looks like a "regression" of the observed data, the ABH one (see Figure 5) follows the same trend behavior of the observed index value. The ABH approach is able to track satisfactorily the observed prices despite the fact that it does not involve any stochastic noise. The reason for this lies in the fact that we substitute the simulated equilibrium market pricep t with the observed spot price p o t in the agents' information set  Table 4. Panels (a), (b), (c), (d) show the fitting of the S&P 500, Euro Stoxx 50, Nikkei 225 and CSI 300 indices respectively.
. .], t < τ . The inclusion of the observed spot prices in the trader information set acts as a kind of "filtering" method. In fact, we have a temporal time-series of observable data (spot prices p o t ) and a model (the ABH model) that uses some unobservable variables (the fractions of agents n h,t ). This allow us to construct an algorithm containing a transition equation linking our two consecutive unobservable variables, and a measurement equation relating the observed data to these hidden variables. Our filtering approach is based on the following two steps (see, for example, Wells 1996): first, we estimate the hidden variables a priori by using all the information prior to that time-step. Second, using these predicted values together with the new observation, we obtain a conditional a posteriori estimation of the variables. Furthermore, the values of the fraction of traders, n h,t , shown in Figures 4 and 5 indicate that the agents act more independently of one another in Asian markets than in the other markets. This finding has already been stressed in the analysis of the optimal values of the intensity of choice parameter, β. In fact, when β = 0, we obtain the same fraction of fundamentalists and trend followers. In this case, the equation (14) implies n h,t =0.5 for any value of the fitness measure U h,t . This means that the trader decision making process is independent of the fitness measure. It is also evident that, in all the investigated scenarios (markets and procedures), we do not observe a strong switching between traders' strategies, that is, the fraction of fundamentalists and trend-followers is relatively stable. This result seems to contrast with the results of Boswijk et al. 2007. In fact, the authors show a substantial time variation and switching between strategies. However, it is essential to stress that the BH model estimated by Boswijk et al. uses annual stock price data. It is well known that traders slowly adjust their strategies (see Boswijk et al. 2007). This makes our model, which is estimated on daily data, less suitable in capturing wide switching phenomena. However, given our daily horizon, we can still observe some fluctuations in the fractions of agents using fundamentalist and trend follower forecasting rules.
In order to assess the accuracy of our methodology, we calculate, for both the calibration procedures, the relative errors of the simulated equilibrium market prices. Specifically, Figures 6 and 7 show the quantities 10 e r,t = |p o t −p t |/|p o t | versus t, t = 0, 1, . . . , τ . Note that the larger relative errors are found at the broken-trend behaviors. They occur on t = 114 − 116 for the S&P 500 and Euro Stoxx 50 indices and on t = 10 for the Nikkei 225 9 A simple random walk could be able to fit the observed prices as well as our models. However, by using a random walk, we could not infer any information about agents' strategies.
10 Figures 6 and 7 are on the same scale in order to be comparable. index. On these days, the relative errors of the three indices obtained using the BH model are 10%, 15% and 20% respectively. The larger relative errors using the ABH model also occur on the same days. These errors are 7%, 6% and 12% which are significantly smaller than those of the BH model. (see panels (a), (b), (c) of Fig. 7). The robustness of our calibration procedures is also investigated. In Appendix A we analyze the sensitivity of the estimated parameters with respect to starting points and additive noises on the observed market indices. The results confirm the robustness of the calibration procedures.
In the second experiment, we validate the BH and ABH models. We follow the two-step calibration scheme in which the available data set is divided into two parts (see Hansen and Heckman 1996;Sims 1996). In this scheme, the first step is labeled "calibration" and the second step is labeled "verification" 11 . In the calibration step, described in the first experiment, the Here our goal is to understand whether the distribution functions of the simulated equilibrium market prices reproduce those of the observed market prices.
At this aim we work with the daily log-returns (also called continuously compounded returns) instead of daily prices because they can be assumed to be from an independent and identically distributed population.
For each market index we compare out-of-sample (i.e. December 19 th one, consists in using two different samples. In this regard, an interesting contribution is Midgley et al. 1997. Authors use a genetic algorithm to calibrate their model and, then, compare the output from the simulated interactions of the synthetic brands with historical data, which had not been used during the model calibration. 2011 -February 23 th 2012) the observed index log-returns with the simulated BH and ABH log-returns obtained using the model parameters shown in Tables 3-4. Simulations are repeated 500 times with different random seeds 12 . For all the investigated markets, Figure 8 shows the decumulative distribution functions (DDF) of the three sets of data. The shape of the simulated log-return distributions well fits the observed log-return distributions. Our results are supported by the generalized Kolmogorov-Smirnov test with a confidence interval 95%. We can conclude that, for each index, the three samples belong to the same distribution.
More statistical details relative to the DDF are shown in Table 5. The statistical analysis confirms the previous conclusion.

Forecasting of market indices
In this subsection we investigate the important field of the predictive output validation. We try to understand if a well calibrated ABM is able to reproduce future trends. In this regards, we present the one and two days ahead forecast values obtained by the BH and ABH models. The relevance of price forecasting is well known in finance. Several approaches have been proposed in order to match asset and derivative prices using both time continuous and discrete stochastic processes (see, for example, Fusai, Roncoroni, 2008 andLiu 2009). In particular, the stock market forecasting has been modeled also through neural network approaches (see, for a survey, Preethi and Santhi 2012). However, two main methodologies compete in forecasting prices, one based on econometric time series analysis and the other one on mathematical finance analysis. Roughly speaking, both these techniques use some modification of the price expected value to predict the observed one. However, the econometric approach is not always suitable for financial forecasting (see Chen and Pearl 2013 and the reference therein). In fact, when the stochastic price dynamic is simple, some more complex approaches are necessary to get satisfactory forecasts such as neural networks (see, Hadavandi et al. 2010).
Indeed, the conditional expected value can be an adequate tool able to predict also spiky prices when the prices are described by more sophisticated stochastic models (see, Fatone et al. 2013 and the reference therein).
However, statistical analysis alone is not sufficient to interpret price dynamics, and economic mechanism that can explain the origin of these phenomena are needed. Our analysis shows that a very naive model and a suitable calibration procedure allow us not only to explain the micro mechanism beyond the price dynamics but also to provide a reasonable price trend prediction 13 .
Let us briefly describe our forecasting procedure. We use the time series from  Tables 3-4. All other parameters are as in the previous experiment (see Subsection 3.2).
To compute n-days ahead forecast values, the BH and ABH models follow the iterative procedure described in steps i 1 )-i 4 ) (see Subsection. 3.1), but an adjustment is needed to the ABH model to predict more than one-day ahead prices. Specifically, steps i 1 ), i 2 ) have to be modified as follows: for t = 1, 2, . . . , 201, the deviation from the fundamental,x t , is computed aŝ The ABH forecast value for the last n steps, thus, is simply the BH simulated price.
Moreover, results of one and two days ahead forecast values of the BH and ABH model are compared with those of a random walk. Specifically, the random walk forecast value (RW hereinafter) can be written as p τ +n = p τ + √ n σ N (0, 1), with σ to be the standard deviation of the observed market returns in the considered time window and n to be 1 (2) in the case of one (two) day ahead forecast values. Figures 9-10 show the one and two days ahead forecast values of indices for the BH, ABH and RW models respectively. In case of the one day ahead forecasts, the BH and ABH models are not completely suitable to match accurately the price behavior in periods of persistent asset price volatility. For example, in the case of the Euro Stoxx 50 and CSI 300 indices, which show a persistent volatility during all the investigated time period, the BH model suffers from the strong market instability while the ABH model seems to be not too affected by the volatility. For the S&P 500 and the Nikkey 225 indices, instead, both models fit quite well the observed values. Finally, the predictions of both models on all indexes match the observed values better than the random walk. In the case of the two days ahead forecasts, the  ability of models in predicting prices slightly falls and the competition with the random walk becomes more tight. For instance, in the case of the S&P 500, the RW gives better results than the BH model, while the ABH model produces forecasts in line with the RW. The opposite is true for the CSI 300, where the ABH lose the competition against the RW, while the BH maintains the supremacy. To better quantify these observations we calculate the average relative errors of the BH, ABH and RW model on all indices in the case of one and two days forecasts. Tables 6-7   However, the forecast values of both procedures are able to track the trend of the observed index values despite of the simplicity of the agent based model considered. To better analyze the quality of the forecasts in predicting the trend, we compute how many times the forecast value matches the upward/downward trend of the observed value 16 . Tables 8-9 show that,    Our results have also shown that an appropriate calibration procedure allows the BH model to perform well in the predictive output validation. In fact, the model has attained satisfactory results in forecasting stock price trends and dynamics. Although our calibration process has been applied to the BH model, it is easily applicable to any agent-based model. The use of appropriately calibrated agent-based models as descriptive and forecasting tools is a rather unexplored field which deserves further investigation.

Appendix A. Robustness analysis on the calibration procedures
In this Appendix we analyze the robustness of our deterministic calibration procedures. Specifically, we evaluate the sensitivity of the estimated parameter values (see Tables 3-4) with respect to the choice of the starting point and, then, to noise effects. Firstly, we investigate the basin of attraction of the optimal solutions Θ * shown in Tables 3 and 4. In particular, we solve problem (22) using different initial pointsΘ 0 j , j = 1, 2, . . . , N s (see Subsection 3.2 Step 1) given by: where ε r is a positive number, 0 < r ≤ 1 and ξ j ∈ R 4 are vectors whose elements are random numbers uniformly distributed in [−1, 1]. The initial pointsΘ 0 j belong to a ball having centre at Θ * and radius ε r with real Euclidean distance from the optimal point Θ * smaller than ε r .
We denote with Θ a j the new solution of problem (22) obtained starting from the new initial pointΘ 0 j (see Eq. (26)).
We compute the average of the relative errors between Θ * and Θ a j , j = 1, 2, . . . , N s , as follows: where · is the real Euclidean norm of · and N s = 100.    Tables 10 and 11 display the couples (ε r , e s ) with ε r =0.01, 0.05, 0.1, 0.5, 1.0. Our results show that the mean error, e s , is smaller than the radius, ε r , in both models. Furthermore, by increasing ε r , the mean relative error, e s , increases but with a decreasing rate and it is anyhow smaller than 10 −2 . Roughly speaking, even in the worst case (i.e. e s = 10 −2 ) Θ * and Θ a j have at least two common significant digits. It means that the solution obtained with the calibration procedures is substantially not influenced from the choice of the initial point so that both procedures can be considered robust. However, the ABH procedure slightly outperforms the BH one. In fact, for any value of the radius, the error of the ABH model is smaller than the corresponding one of the BH model, with the only exceptions being for the Euro Stoxx 50 with ε r = 0.01 and the CSI 300 with ε r = 0.1.
Secondly, we analyze the robustness to additive noise effects. We perturb the observed market spot prices, p o t , adding a noise sampled from a normal  Figure 11: Robustness of the BH (solid line) and ABH (dotted line) calibration procedures to an additive noise normally distributed with zero mean and standard deviation σ n proportional to the standard deviation of the S&P 500 historical series σ s (i.e. σ n = ξ σ s ). The four panels show the value of the estimated parameters as a function of the noise to signal ratio ξ. distribution with zero mean and standard deviation given by σ n = ξ σ s , where σ s is the standard deviation of the observed data and ξ is a constant also known as "noise to signal ratio". This noise is used to describe bid-ask bounce effects on exchange rates and equity (see, for example, Nielsen and Frederiksen 2007, Mancino and Sanfelici 2012). We consider the S&P 500 index and the CSI 300 index 17 from February 25 th 2011 to December 16 th 2011. The standard deviations of the S&P 500 and CSI index are σ s = 88.37 and σ s = 315.074 respectively. We generate 100 trajectories for each index and for each value of the noise to signal ratio, ξ, with ξ = ξ i = (i−1)0.004 σ s , i = 1, 2, . . . , 50. We then estimate the BH and ABH parameters.  Figure 12: Robustness of the BH (solid line) and ABH (dotted line) calibration procedures to an additive noise normally distributed with zero mean and standard deviation σ n proportional to the standard deviation of the CSI 300 historical series σ s (i.e. σ n = ξ σ s ). The four panels show the value of the estimated parameters as a function of the noise to signal ratio ξ.
(i.e. σ n ≤ 7.06 in the case of S&P 500 index and σ n ≤ 25.20 in the case of the CSI 300 index). This experiment shows that the calibration procedures are sufficiently robust to additive noises.