Looking for the self-fulfilling prophecy effect in a double auction artificial stock market Abstract—This work proposes a double auction artificial stock sell signals when a short run moving average crosses a long market based on the Santa Fe market structure. Our market tries run moving average price. to shed light on some facts that usually arise in real stock markets, Chartism is one of the two main investment approaches that specially the creation of technical figures in price series. The origin of these figures is believed to be caused by the self-fulfilling can be usually found in stock markets [8]. The other one is fun- prophecy effect, which will be investigated with the proposed damental trading, where investors base their investments upon market. future price expectations based on fundamental and economic factors, such as future dividend expectations, macroeconomic I. I NTRODUCTION data and growth prospects. Nowadays, investors and chief The main purpose of the agent-based simulation of an dealers combine both technical and fundamental information artificial stock market (ASM) is to reproduce, in a controlled [6]. Frankel and Froot in [9] showed that both approaches environment, some properties of real stock markets. In that affected the US dollar exchange rate in the eighties. They as- way, ASMs are a suitable tool to analyze and understand sociated the long-term expectations, which are stabilizing, with market dynamics. See [1] for a comprehensive review of the fundamentalists, and the shorter term forecasts, which seem to topic. have a destabilizing nature, with the chartist expectations. As Many market models has been developed in order to a result, many people used weighted averages of the chartist reproduced those properties, like Genoa Stock Market [2], and fundamentalist forecasts in formulating their expectations [3], $-Game [4], or the Santa Fe Institute Stock Market for the value of the dollar at a given future date, with weights (SFM), developed by LeBaron and his coauthors since the depending on how far the date is. early nineties and analyzed in depth in [5]. Most of them This article proposes an ASM based on the SFM structure are able to reproduce several well-known market properties that exhibits technical figures and that reproduce the self- -called stylized facts,- while each market has his own special fulfilling prophecy effect. The proposed ASM modifies some microstructure. However, in the time series of prices that important features of the SFM with the aim of being more emerges in ASMs it is difficult to find some of the typical realistic and reproducing stylized facts. The most relevant behaviors that appear in real-life price time series, for example, changes are introduced in the next section. the bid-ask bouncing or the sideways movement within the support and resistance lines. II. D ESCRIPTION OF THE DOUBLE AUCTION ARTIFICIAL These behaviors, which are usually know as technical STOCK MARKET PROPOSED patterns, cannot be explained from the fundamental analysis The SFM [10], [11] consists of a small number (typically perspective. Despite this fact, they are used by many investors 25) of artificially-intelligent agents that each period choose be- and also by chief dealers, as is reported in [6]. The reality is tween investing in a stock and leaving their money invested in that patterns such as trends, channels, resistances and supports a fixed interest rate asset. The stock pays a stochastic dividend can be spotted in stock charts. A possible explanation to these and has a price which fluctuates according to agent demand. phenomena is the self-fulfilling prophecy effect [7]. As many The agents make their investment decisions by attempting to people look for similar technical patterns in the stock markets forecast the future return on the stock with the help of a set of and place their orders according to them, the patterns finally forecast rules that are triggered when they match certain states emerge as a result of this collective belief. This belief is of the market. Each rule map into a set of parameters that reinforced when the stock price behave as expected, because are used to yield a forecast for the future price and dividend technical traders feel confident with their chartist strategy and using the rational expectations equilibrium theory. The forecast technical analysis is considered as a useful tool. is converted to the share demand, according to the agent’s Technical analysts, also known as chartist investors, base demand function which follows risk aversion behavior. Agents their expectations in historical price patterns that are expected learn through time because their predictive rules evolve by to appear again at some future point. They try to predict future means of a genetic algorithm. extreme prices in order to buy assets when the value is under The SFM shows, amongst other features, the theoretically- those limits, and sell them when the price is close to a bounce predicted rational expectations behavior, with low overall trad- zone. Moreover, technical traders usually follow price trends. ing volume, uncorrelated price series. However, it is difficult A common example is the use of the moving averages crosses to find realistic market behavior such as high trading volume, to set their trading strategies. This method provides buy and time-varying volatility clustering (periods of swings followed by periods of relative calm), bubbles and crashes and market A. Agent’s trading strategy patterns such as supports, resistances, channels, etc. One of the As in the SFM, our market has two assets: a risk free bond main reasons is that the auction mechanism is not realistic as in infinite supply with constant interest rate (r = 0.1) and a there is an auctioneer that takes into the account the demand risky asset. The price of the risky asset in t, pt is endogenously of shares and the fixed supply of shares (25 shares) to set the determined by the market. The risky asset considered does not price that clears the market. pay dividends, in contrast to the SFM’s risky asset. In our ASM, a continuous double auction system is imple- The trading strategy consists of buying (or selling, if the mented. In continuous double auction markets, agents place agent goes short) risky assets at the current price of the market buy or sell orders at any time in an asynchronous manner. and at the same time placing a fixed price stop-profit order. In this kind of auctions, a public order book lists the bids The price of the stop-profit order is determined by taking into in descending order and the sell offers in ascending order. account the agent’s resistance line (or the agent’s support line, When a new order matches with the best waiting order of if the agent goes short). Both orders are sent at time ta . In the opposite type then a trade is made, otherwise the new addition, the agent also estimates the price of a stop-loss order order remains waiting. Once the transaction is carried out, both using the support line (or the resistance line, if the agent goes orders are removed from the order book. This kind of auction short). This order will be placed as a market-price order only is implemented in stock markets such as NYSE or AMEX. if the risky asset reaches the stop-loss price. This kind of auction has been already implemented as an ASM As any market-price operation has its corresponding stop- [12], [13], [2], [14], where some aspects of market dynamics profit order, the total number of stocks M is always available are successfully explored. As continuous double auction is in the market, providing the necessary liquidity to supply the commonly used in real stock markets, we believe that is the possible demands of other investors. The system restrictions most suitable auction mechanism for an ASM that aims to ensure the liquidity of the market and consequently market replicate these markets. price orders are executed at the time when they are placed. In our market, agents are rationally bounded, , which means In ta the stop-profit order is booked in its corresponding that their rationality is limited by the information they have. priority queue of awaiting orders, depending on if the trading They make price bids (offers to buy) and/or price asks (offers agent goes long or short. The agent determines the stop-profit to sell) subject to a budget constraint and using the information price using a future stock price that is forecasted with the they have about the state of the market. Our market allows help of a support line (or a resistance line if the investor is agents to place both market-price and fixed-price orders. The going short) that is drawn by the agent using three parameters ASM does not allow fixed-price orders. However, this kind determined by the activated forecast rule j (more details of orders are used in real-life stock markets. In an artificial about the forecast rules are given in the next subsection). market that allows this orders it is possible to observe technical The parameters are: the number of local maximum (resp. patterns. If a group of traders set fixed-price orders close minimum) points used to draw the resistance (resp. support) to a certain price value, then supports or resistances lines lines ai,j , the length of the sliding window used to look for the may appear in the resulting price time series. Also, cascade local maxima and minima bi,j , and the length of the trading effects could emerge behind certain price limits obtained using horizon ci,j . A support (resp. resistance) line is drew joining technical analysis. at least two minimum (resp. maximum) price values. These parameters allow agents to operate to different time horizons. In our ASM, agents tune the fixed-price orders using a If at time ci,j the price of the risky stock has not been system of forecasting rules similar to that used in the SFM, but matched the agent close its position and cancel the stop-profit based on support and resistance lines. In doing so, they will fix order that was previously submitted. This is an interesting the price taking into account the support and resistance lines feature because, as is reported in [15] not all researchers in the and the length of the trading horizon (it denotes if is a short-, experimental markets literature allow to cancel limit orders. mid- or long-term trade). The mechanism will be described below. B. The classifier system Our market follows the basic structure of the SFM model, The behavior of the trader is determined by the classifier but implementing a double auction market. Another notewor- system they use to set their trade orders. The classifier system thy difference is the number of agents. Instead of the 25 agents consists of a set of rules that are triggered when some market used in the SFM, in our market there are 512 agents that conditions are present. The classifier system implemented that will make possible to have enough trade operations in the follow our agents is based on the one used in the SFM, which market and a great variety of behaviors. It is important to is described in detail in [11]. remark that our aim is not related with the rational expectations The agents have to set of rules one for ”going long” and equilibrium theory, but with the study of real-life phenomena other for ”going short”. The rules of both sets have the same such as resistance and support lines. These changes affect structure, which consists of two parts. The left part of the not only the auction mechanism but also the equations that rule is a string of 30 conditions, where each string position determine the wealth and the classifier rules. More details will represents a state of the market. The possible values of each be given in the next subsections. position are 1, 0 or ♯. The 1 means that the state have to be number of extra periods will be denoted as f . While agent Target Price stop-profit Resist. Adj. Target Price traders can not execute several operations at the same time, and also can not modify their current trading strategy, wealth value resistances is updated when a trading operation has concluded. Given that, Stocks sold at different times the wealth of agent i in te+f is buy price Wte+f ,i = Wtrisky a →te+f + Wtfaree f ree →te+f + Wte →te+f . (1) Effective Holding Period The equations of these three terms are explained next. Max Holding Period The term Wtrisky a →te+f ,i represents the changes from ta to te+f in the wealth invested in the risky asset. Its equation is slightly ta tb tb 1 tb 2 + + ta+cj different depending on the way stocks are sold. If they are sold because they reach the stop-profit price, then te = tb is the Fig. 1. Time line that illustrates an investment operation made by a trading agent period when that price is reached and the wealth is f X Wtrisky a →te+f ,i = pte xout te+l ,i , (2) present, the zero that the state have not to be present while the l=0 ♯ is a wildcard that matches either. The right part of the rule where xout te+l ,i is the number of stocks sold at time te+l by consists of three parameters (ai,j , bi,j and ci,j ) that are used Pf to draw the resistance and the support for the trade operation. agent i and satisfying l=0 xout te+l ,i = xta ,i . If the agent is going long, it will use the resistance to set the On the other hand, if stocks are sold because the maximum stop-profit order and the support for the stop-loss order, while holding time ends, which happens at te = ta+cj , then all if the agent is going short it will do it the other way round. the stocks are sold at that time (which means that f = 0). The idea is that each rule matches a state of the system, where However, it may happen that not all the stocks are sold at the agent invest in the risky stock asset at market price. The the price pte . This happens when the demand of the awaiting position will be held until the asset reaches either the stop- order does not cover the whole sell. If this is the case, other profit or the stop loss prices. If the rule is matched at ta , the awaiting orders, possibly with a different price are required. agent expects to reach the stop profit price at ta + ci,j . The wealth Wtriskya →te+f ,i in this case is estimated as The parameters are initially set to random values distributed v X uniformly. As in the SFM the rules are not static. Each agent Wtrisky a →te+f ,i = xout te,l ,i pte ,l . (3) is allowed to learn by changing its set of rule. The learning l=1 process is implemented by means of a genetic algorithm where As all the stocks are sold at the same price, the price pte ,l the poorly performing rules are substituted by new ones. Rules and the stocks number xout te,l ,i both depend on a parameter are selected for rejection and persistence based on a accuracy l = 1, ..., v that represents the number of awaiting sell order measure that takes into account both the errors in the price matched. and in the forecast horizon. The second term, Wtfaree →te+f ,i , represents the evolution of C. The state of the agents the capital invested in the free risk asset since ta . It is given When a forecast rule j of agent i is activated in ta , the by agent will forecast the future stock returns for time horizon k X Wtfaree tb+f −ta pta ,l xin  ta +ci,j , instead of ta +1 as in the SFM. Once the operation is →te+f ,i = (1 + r) Wta ,i − ta ,i,l , (4) done, the agent will hold its position until instant ta + ci,j or l=1 until the price of the stock reaches a stop-profit or a stop-loss where r is the constant interest rate of the free-risk asset value at an undetermined time tb > ta , whatever comes first. and the pair of values (pta ,l , xin ta ,i,l ) represents the awaiting In the second case, the operation may not be closed at that sell order matched at time t with the market price order. It undetermined time, which will be denoted as tb . It happens means that xin ta ,i,l stocks have been bought at price pta ,l with when there are not enough buy (resp. sell) orders to sell (resp. Pk xin = xta ,i . l=1 ta ,i,l buy) all the stocks at the stop price in tb . Figure 1 illustrates Finally, the term Wtferee∗ →te+f ,i represents the evolution of the the process for the case where the agent goes long. capital of the stocks sold between te and tef , because during Once the transaction is completed (i.e. once the ordered this period this capital is invested in the free risk asset. Thus, stocks have been bought and then sold or viceversa for short the term is only taken into account if f > 0. It is given by positions), the investor’s wealth has to be updated. As said f before, the transaction is completed either when stocks reach X the stop-profit price at tb or when the holding time period is Wtferee∗ →te+f ,i = (1 + r)tb+f −tb+l (ptb+l xout tb+l ,i ). (5) expired ta + cj . For the sake of simplicity, we will refer to l=1 these periods as te . The wealth equation must take into account In our market as in the SFM, investors use a simply constant that the sold of stocks can require more than one period. The relative risk aversion preference for stock demands [16]. When a classifier detects an investment opportunity, the investor [2] M. Raberto, S. Cincotti, S. M. Focardi, and M. Marchesi, “Agent- agent estimates the asset demands, trying to maximize the based simulation of a financial market,” arXiv.org, Quantitative Finance Papers cond-mat/0103600, Mar. 2001. [Online]. Available: wealth utility function Ui,t+cj = − exp (−λWi,t+cj ), where http://ideas.repec.org/p/arx/papers/cond-mat-0103600.html the wealth equation has been described above. [3] S. Cincotti, S. Focardi, L. Ponta, M. Raberto, and E. Scalas, “The waiting-time distribution of trading activity in a double auction artificial III. VALIDATION OF THE MODEL financial market,” vol. 567, pp. 239–247, 2006. [4] J. Andersen and D. Sornette, “The d-game,” European Physics Journal, This paper represents the current state of a work-in-progress. vol. 31, no. 1, pp. 141–145, 2003. An example of a candlestick time series with the trading [5] N. Ehrentreich, Agent-Based Modeling: the Santa Fe Institute Artificial volume generated by the ASM is shown in Figure 2. The Stock Market Model Revisited. Springer-Verlag, 2008. [6] L. Menkhoff, “Examining the use of technical currency analysis,” model is being satisfactorily programmed using Nvidia CUDA International Journal of Finance and Economics, vol. 2, pp. 307–318, technology, which allows to drastically reduce the simulation 1997. time. This parallel programming technology also allows to [7] M. P. Taylor and H. Allen, “The use of technical analysis in the foreign exchange market,” Journal of International Money and Finance, vol. 11, scale the number of agents without increasing the simulation no. 3, pp. 304–314, June 1992. time. Detailed information about trading strategies, agent be- [8] C. Hommes, “Heterogeneous agent models in economics and finance,” havior and evolution, the rule system and auction mechanism in Handbook of Computational Economics, 1st ed., L. Tesfatsion and K. L. Judd, Eds. Elsevier, 2006, vol. 2, ch. 23, pp. 1109–1186. will be explained in the subsequent extended paper along with [9] J. Frankel and K. Froot, Private Behaviour and Government Policy in the simulation results and validation. Interdependent Economies. New York: Oxford University Press, 1990, Regarding validation it will consist of analyzing two issues. ch. Chartists, fundamentalists and the demand for dollars, pp. 73–126. [10] B. LeBaron, W. B. Arthur, and R. Palmer, “Time series properties of First the usual econometric properties, i.e. the stylized-facts, an artificial stock market,” Journal of Economic Dynamics and Control, that are present in real-life stock market time series such us fat vol. 23, no. 9-10, pp. 1487–1516, September 1999. tails and leptokurtic properties in return distributions, excess of [11] B. LeBaron, “Building the santa fe artificial stock market,” Brandeis University, Working paper, june 2002. kurtosis, no significant autocorrelation and volatility clusters. [12] N. T. Chan, B. LeBaron, A. W. Lo, and T. Poggio, “Agent-based models Second, it will be shown that technical patters, familiar to of financial markets: A comparison with experimental markets,” MIT professional technical analysts, do appear in the time series of Sloan, Working Paper 4195-01, 2001. [13] D. K. Gode and S. Sunder, “Double auction dynamics: structural the prices as a result of the self-fulfilling prophecy effect. effects of non-binding price controls,” Journal of Economic Dynamics & Control, vol. 28, no. 9, pp. 1707–1731, 2004. [14] J. Derveeuw, B. Beaufils, P. Mathieu, and O. Brandouy, “Testing double auction as a component within a generic market model architecture,” vol. 599, pp. 47–61, 2007. [15] S. Crowley and O. Sade, “Does the option to cancel an order in a double auction market matter?” Economics Letters, vol. 83, no. 1, pp. 89 – 97, 2004. [16] S. J. Grossman and J. Stiglitz, “On the impossibility of informationally efficient markets,” American Economic Review, vol. 70, no. 3, pp. 393– 408, 1980. Fig. 2. Preliminary results: synthetic market (blue bars) following SP500 daily closing price (red line) as reference market. ACKNOWLEDGMENT The authors acknowledge support from the project Agent- based Modelling and Simulation of Complex Social Systems (SiCoSSys), supported by Spanish Council for Science and Innovation, with grant TIN2008-06464-C03-01. We also thank the support from the Programa de Creación y Consolidación de Grupos de Investigación UCM-BSCH, GR58/08 R EFERENCES [1] B. LeBaron, The Handbook of Computational Economics, Vol. 2: Agent- Based Computational Economics, ser. Handbooks in Economics Series. Amsterdam: North-Holland, 2006, ch. Agent-based Computational Fi- nance, pp. 1187–1234.