Home Download Help Resources Extensions FAQ References Contact Us Donate Models: Library Community Modeling Commons User Manuals: Web Printable Chinese Czech Japanese Spanish

NetLogo User Community Models(back to the NetLogo User Community Models)
WHAT IS IT?
This model features an artificial financial market with speculators, trend followers and value investors. Its main new features are the following:
1) It includes new agent types (that were not present in the previous artificial financial market), namely: speculators and trend followers;
2) It endows speculators and trend followers of a learning scheme based on social learning;
3) It determines a new risk measure introduced recently in the financial literature (Gonçalves, 2004, Gonçalves and Ferreira, 2004) that possesses important features like tail risk freeness (that is, it reflects the whole of the information regarding the probabilities associated with extreme events).
4) The emerging patterns regarding tail risk and the price logarithm produce music.
5) The agent grid is threedimensional.
This presentation is divided as follows:
PART 1: Part 1 reviews the problem of tail risk and the main issues regarding the problem of undetected tail risk. It also introduces the tail exponential risk measure.
PART 2: Part 2 presents each agent type and behaviour;
PART 3: Part 3 introduces the musical analysis of tail risk;
PART 4: Part 4 describes the basic interface with the user;
PART 5: Part 5 addresses things to notice and things to try.
PART 1: TAIL RISK
The problem of tail risk is a central problem to the globalized financial markets. This problem can, roughly, be summed up in the following idea  the change, with time, in the probabilities of extreme losses makes these losses more probable at some times, and less probable at others. Large investments may incur in large losses, if the agent holds these investments at times when the probability of extreme losses is high, then the agent is at risk of losing large amounts.
Extreme losses are usually located at the tails of the probability distributions, this, along with the fact that the risk associated with extreme losses comes from changes in these tails probabilities, leads to the concept of tail risk.
It is essential that a risk measure be able to dynamically reflect the risk of these extreme losses in the financial markets, in order to control for this kind of risk.
As Yasuhiro Yamai and Toshinao Yoshiba (2001, 2002a) showed, most tail risk measures (including the widely used VaR and CVaR) are unable to reflect this extreme loss risk in their risk measurement, thus, undetected unaccounted for tail risk may be present. This is what the authors called non tail risk freeness.
A risk measure is said to be free of tail risk if it is able to reflect in its measurement, the risk contained in the tails of the underlying distributions. If a risk measure is unable to reflect the risk contained in the tails, then, it is not to free of tail risk.
Recently, Gonçalves (2004) proposed a tail risk measure that is free of tail risk. This risk measure was called Tail Exponential Risk Measure, or TE, for short.
The TE is determined as follows:
TE = E[exp(L.X)X > K)
L  tail risk aversion coefficient
The exponential may be seen as playing the role of a pain function (the symmetric of a utility function), thus expressing displeasure (Gonçalves and Ferreira, 2004). The tail exponential is, thus, the "expected pain", associated with the tail that is defined by the event X > K.
Mathematically, the Tail Exponential measures a new notion of tail risk introduced by Gonçalves (2004), the notion of pKtail risk. The pKtail risk is the risk contained in the conditional loss probability measure, conditional on the event that the losses are greater than the threshold K.
The tail exponential measures the risk contained in this conditional probability measure (Gonçalves (2004), Gonçalves and Ferreira (2004)).
In this model, we let the tail risk aversion coefficient change, with time, by setting it equal to a base tail risk aversion coefficient, times the estimate of the volatility parameter (the volatility parameter is determined by using RiskMetrics (TM) Exponentially Weighted Moving Average volatility estimate).
Although the phenomenon of tail risk was largely researched upon at a theoretical level, specifically, at the level of the properties that a risk measure should satisfy. Once we have a risk measure that is capable of reflecting the whole of the information regarding the tails beyond a threshold K, it is important to consider other aspects of the phenomenon of tail risk, namely, its dynamical nature.
The present model has, as one of its main goals, to allow the financial researcher and the economist or any other researcher interested in financial markets phenomena and group behaviour, to explore the dynamical features of tail risk. Specifically:
a) The changes that occur, through time, in tail risk (especially the presence of trends in tail risk, and the changes that can be seen in real time in the histogram);
b) The relation between tail risk and synchronization in asset trading;
c) The relation between tail risk and financial crashes.
The model also introduces new kinds of agents with learning rules that evolve with time, so that the model is also intended to make some contributions to complex systems theory and the view of a financial market as a complex adaptive system.
PART 2: AGENT TYPES AND BEHAVIOURAL RULES
MARKET MAKER
The market maker appears in the artificial financial market only in terms of the price formation rule, that is, the market maker is treated solely in terms of the market clearing mechanism.
The agents can, then, be divided in two large typologies. Specifically, a first type of agents, that includes value investors, speculators and trend followers, that place their orders to buy or sell stock, a second type of agents, or, in this case, a unique agent that is the market maker.
The market maker guarantees that the market clears by taking up the excess demand or supply. Therefore, the orders are filled by the market maker at a price that depends on the net order of the first type of traders. The market impact function f is the mechanism that the market maker uses to set the prices, which leads to a market clearing mechanism that can be expressed in terms of a price formation rule relating the net order to the new price.
At each time step we take the price to be a function of the net order W{t} which is a difference between the demand and the supply, therefore, the market maker uses the following algorithm to compute the price:
P{t+1}=f(P{t},W{t})
Following Farmer (2000), assuming that f is of the form
f(P{t},W{t})=P{t}F(W{t})
where the market impact function F(W(t)) is taken to be an increasing function with F(0)=1, leads to the loglinear market impact function (Farmer, 2000). In this case the logarithmic returns y{t} are given by:
y{t}=lnP{t}lnP{t1} = W{t})/ L
where L is a normalizing liquidity parameter.
The net order is taken to be equal to the weighted sum of the net orders of the three agent types, the weights convert orders from quantity (number of shares) to money, amount being bought, or sold.
We take the parameter L to be equal to theta times G, and let, G be such that the sum of the weights divided by G is equal to 1. The quotient between each weight and the parameter G represents the impact, to the market, of each agent type.
Thus, the price formation rule is similar to the one proposed by Farmer (2000), with the difference that instead of the net order we have an average net order, E[W{t}] averaged over the agent types. The logarithmic returns are, then, given by:
y{t}=((E[W{t})]/theta)
As we saw in the previous artificial financial market, the expected value E[W(t)] can be thought of as a measure of the average market sentiment, or of sentiment polarization. This variable has also been previously called 'groupthink' (Ponzi, Aizawa, 1999).
The logarithm of price p{t}=ln(P{t}) is given by:
p{t}=p{t1}+y(t) = p{t1}+((E[W{t})] / theta)
Having discussed the market maker, and the price formation rule, we now address each agent type.
VALUE INVESTORS (BOUNDED RATIONALITY AND SOCIAL INFLUENCE IN GROUP DYNAMICS)
Value investors follow the previous artificial financial market's rules. They are agents that trade, based on the social learning of information that arrives to the market.
At each time step new information arrives to the market as a signal I(t).
A qualitative meaning is given to the information, this meaning is taken in binary terms as either being good (+1) or bad (1), in this sense we have, at time t:
(1): I(t)~N(0,1)
I(t)  New Information (news for short)
There are three behavioural assumptions underlying these agents:
Assumption 1) Individuals are boundedly rational.
The fact that individuals are boundedly rational leads to limits in the interpretation of the information. These limits, in our case, need not come necessarily from different accesses to information, indeed all traders are informed traders and these limits are considered to be intrinsic to the individual.
The reason for this, is that, unlike the neoclassical agent that knew all in all of its dimensions, we assume that agents need to cognitively interpret their experiences, they form models of the world and of their position in the world, and these models differ from individual to individual (assumption 3). Indeed, the knowledge and experience, the background of each trader is different, so that they interpret the information differently, and they have to learn about the world, to make sense of it, and of their position in it.
In this sense, the sentiment regarding the market is formed differently for each trader, and each reacts differently to the information. The new information, however, is not the only external force acting at the agent level, we also have to take into account the possibility of social communication and of social transmission of sentiments regarding the qualitative meaning of the information. In this sense, we assume that there is some sensitivity of the individual to the sentiments of his/hers closest colleagues in the trader's network of relations.
This openness of the individual to others is a strategy of rationality expansion, given the limits of the individual's rationality.
The following rule (the sign function takes the value +1 when the argument is positive and 1 when the argument is negative) defines the agent's sentiment update rule:
(3): Si(t)=sign(Ki*NSi(t)+nsi*E[Q(t),h]+ei(t))
Ki  Propensity of the trader i to be contagiated with the friends sentiment.
NSi(t)  The sum of the trader i's friends sentiments.
nsi  the sensitivity of the trader i to the news qualitative meaning.
ei(t)  a random term that accounts for each individual's own interpretation of the news (called the idiosyncratic term (Sornette, 2003)), we take it to be normally distributed around zero and with standarddeviation to be controlled by the user.
Si(t)  trader i's sentiment regarding the information, if it is good (bullish) the trader buys if it is bad (bearish) the trader sells.
Q(t)  News qualitative meaning
E[Q(t),h]  The expected value of the news qualitative meaning, taken as an average over a timeperiod h (which varies from agent to agent).
Note that each of the elements that form the argument of the sign function differ from trader to trader, except the news qualitative meaning which is a common component.
There is a cognitive rule for the dynamics of the propensity to be contagiated by the sentiments of others.
We assume that individuals have a base propensity to be contagiated by the sentiments of others, and that, if a good(bad) news is confirmed by a market movement in the same direction, then the individual's propensity to contagion is set equal to his/hers base propensity plus(less) an amount equal value of to the average market polarization (measured by the 'groupthink', E(W(t))), otherwise the propensity to contagion is set equal to the base propensity less(plus) an amount equal to the average market polarization (E(W(t)).
The choice of E(W(t)) for the amount to be added or subtracted has to do with the fact that this is an indicator of the average aggregate state of the market, and it is related to the degree of herding, as we shall see later on in this presentation.
Let us give a basic intuition for this rule. Assume a pessimistic scenario (an optimistic would also serve as an example), more specifically, assume that a bad news arrives and that this bad news is confirmed by a market movement in the same direction. The market only confirms the bad news if there is a larger number of agents with a negative sentiment (bearish) relative to those with a positive sentiment (bullish), so that the aggregate sentiment is bearish, then, the traders become more sensitive to the others sentiments, and the bad sentiment catches on to the next period.
SPECULATORS (SOCIAL LEARNING PROCESS IN A MINORITY GAME)
The speculators play a minority game with the market. Their strategies are taken to be one of the following four:
S1: Sell no matter what (strategy code: [00])
The speculators keep scores as follows: if the market went up and they bought, their score is set equal to 1 (they were not on the minority side), likewise, if the market went down and they sold, then, they were not on the minority side and their score is also set equal to 1. Their score is only set equal to 1 if the market rose and they sold, or if the market fell and they bought.
Speculators possess a finite memory of the past scores, which allows them to form a historical record of past scores. Given that record, they determine the average score; and compare their average scores with those of their six nearest neighbours in a 3 dimensional grid that forms the network of traders. Afterwards, if their average score is greater than the best score of the six nearest neighbours, the speculators reproduce the strategy. If not, they imitate the strategy of the best performer of the six nearest neighbours. Notice that the best performers are agents that, on average, have been in the minority side more times than their neighbours.
This is a social learning process, in the sense that each agent learns from her neighbours what strategy to implement.
We allow for individual creativity in the strategy selection process, by giving individuals the freedom to choose a strategy different from the one that follows from the social learning process. This is done by introducing a probability of strategy innovation.
If, in the course of strategy innovation, the individual finds a strategy that works better, then, this strategy may be learned by the neighbours and reproduced. This is largely what happens if, in the course of an individual strategy change, the local new strategy spreads to a number of agents in the vicinities (more or less like an avalanche process).
TREND FOLLOWERS (SOCIAL LEARNING, SOCIAL IDENTITIES AND STRATEGIES)
Trend followers are agents that are not necessarily trying to play a minority game and do not pay attention to fundamental information, instead, they try to find patterns in price history and then they develop trading strategies based upon these patterns.
We develop here a very simple model of trend following. In this case, we assume that the information that the trend followers use to predict the trend is the past returns at different time horizons, so that, if the price went up, they predict that it will go up and if it went down, they predict that it will go down.
That is, if y(tm) are the returns at time tm, then, if y(tm) < 0, they predict that y(t+1) will be positive and viceversa. The lag m, is the trendfollower time scale. Each trendfollower has a different time scale.
We model here two basic kinds of trend following strategies: contrarian investing, and simple trend following.
Contrarian investors play a minority game with the market, in the same way as speculators did, however, while the speculators may have different strategies, that do not necessarily coincide with the ones of the contrarian investors, contrarian investors' trading is completely mechanical in nature, more specifically, they sell if the y(tm) > 0 and buy if y(tm) < 0.
Simple trend followers, on the other hand, buy if y(tm) > 0 (because they predict that it will continue rising) and sell if y(tm) < 0 (because they predict that it will continue falling). Thus functioning as trend enhancers.
If the returns are equal to zero, both of the trend follower strategies hold (they do not buy nor sell).
Trend followers also possess a memory, and keep records of scores.
If the trend follower is a simple trend follower, then, her goal is to place an order that coincides with a market movement in the same direction, thus, they win if their market order coincides with the majority (score 1) and lose (score 1) if their market order coincides with the minority.
If the trend follower is a contrarian, then her goal is to place an order that is opposite to the market movement (the exact opposite of a simple trend follower), they thus win (score 1) if their order coincides with the minority and lose (score 1) if their order coincides with the majority.
The social learning here is similar to the one of the speculators at the level of the learning algorithm. Namely, the agent's imitate the best local performer, and they also innovate in their investment strategies.
The difference here is that, instead of selecting a strategy, what we have is a social identity selection. That is, the agent either considers herself to be a simple trend follower or a contrarian, according to the success that the nearest trend followers and contrarian have.
PART 3: EMERGENCE, MUSIC AND TAIL RISK
One important finding of this artificial financial market is that despite the randomness there are emerging patterns in tail risk. The simulation transforms in a musical scale a comparison between the tail risk aversion parameter and the returns (switch music_tail_risk_aversion?) and between the tail exponential and the returns.
The comparison between the tail exponential and the returns, is done as follows:
A) If TE is the value of tail risk associated with the conditional probability measure, then,
B) ln(TE) / L is the certain loss equivalent, that is the amount of logarithmic losses that suffered with certainty would be considered to be equivalent to the random loss X, conditional on the event that it is greater than K.
It is the certain loss equivalent rather than the TE that is compared with the returns in the musical pattern (switch music_tail_risk?).
We can capture musical patterns and literally hear the tail risk increasing and decreasing.
The emerging musical patterns in tail risk betray the emergence of changing patterns in the fluctuations of the tails. It reflects the main feature of the model's dynamics the constant change of phase from disordered to ordered states.
These patterns change as the threshold is increased. For the threshold equal to zero, the tail exponential reflects the tail risk contained in the left tail of the returns probability distribution (that is, it reflects the tail risk contained in the loss probability distribution). This is the default configuration.
The user may increase slowly the parameter and hear the changes in the patterns.
The fact that the price and the tail risk contain musical patterns is an example of how structure and meaning emerges from the agent behaviour and interaction, even despite the underlying randomness of the news signal that arrives, the agent's behaviour produce emerging patterns that possess enough structure to be played through as music, and enough novelty not to make it repetitive.
It is important that the user looks at the returns' timeseries and the tail exponential chart, that depicts not the tail exponential but, rather, the certain loss equivalent. If one listens to the music, and looks at these pictures one can see the interconnection between the music and the tail risk dynamics.
PART 4: THE SIMULATION
HOW TO START
To start the simulation you should must click first setup, then, setuppasthistory, and when the program regarding setuppasthistory stop, you must click go, to run the simulation.
The setuppasthistory defines an initial history for the valueinvestors to learn.
THE MAIN USER INTERFACE
The main user interface is divided in several areas that the user can explore.
It contains the value investors’ parameters that are the same as the ones of the previous artificial financial market.
It also contains the speculators and trend followers’ parameters. For both of these agenttypes the user can control the memory and the probability of strategy innovation (as long as the innovation switch is on).
The user can also control the basic parameters that allow the determination of the volatility. Namely:
I) The decay factor that allows the determination of the exponentially weighted moving average volatility estimate;
II) The threshold that determines the conditioning event that allows the determination of the TE risk measure;
III) Since the TE is estimated according to a moving average scheme, the user can also choose the timewindow for the determination of the TE, by default, the time window slider is set to 50 time periods.
The user can also determine the impact that each agent type has in the market. The sliders to do this are the valueinvestorstrength and the trendfollowerstrength.
The weights for the determination of the logarithmic returns, as explained when we addressed the marketmaking mechanism, are obtained as follows:
 The weight of the value investors is set equal to the valueinvestorstrength
There is also a slider that controls for the agents that are represented at any time by the Netlogo world. The slider called board
Although all agents are trading at the same time, you are only able to see each agent type at any time, depending on the board chosen. If the board is set to equal to 0, then, you'll only see the value investors, the green ones buy, and the red ones sell. If the board is set equal to 1, you'll see the speculators buying and selling, with the same code colour. If the board is set equal to 3 you'll see the trend followers.
Finally, if you're looking at the speculator or the trend follower board and have the switch strategycolour set to on, then, you'll see, instead of buying and selling colour codes, the colour codes represent the strategy, in the case of the speculators, and, for the trendfollowers, trendfollower identity.
PART 4: THINGS TO NOTICE AND TRY
Try to alter the strength of each trader, the innovation probabilities and see what happens to the behaviour of the returns.
Notice the music, it reflects the tail exponential risk measure versus the returns. Can you identify any patterns in the music?
Try to classify the music played by the returns.
Notice what happens to the TE risk measure, does it show trends. Put the world next to the graph and look at what happens to the TE when the market synchronizes for more than one period, for the value investors.
Try to run the model with the strategy switched on, can you describe strategy contagion effects.
What happens when you switch off the innovation button are the learning dynamics different?
As the market synchronizes for the value investors turn the cube around and notice the colouring of the several faces of the cube.
Change the number of agents by increasing the cube, does the overall behaviour change.
CREDITS AND REFERENCES
We would like to thank Professor Miguel Ferreira, ISCTE Business School, my thesis coordinator, for his support and continuing interest in my research on tail risk. Professor Yasuhiro Yamai of the Bank of Japan for the important exchange of thoughts regarding tail risk, Professor Shaun Wang of SCOR which played a major role in the path taken by my MsC thesis, and, Professor Didier Sornette, of UCLA Department of Earth and Space Sciences, for the interest shown in the first artificial financial market and the important exchange of ideas regarding the first artificial financial market.
The tail exponential risk measure was introduced in the MsC thesis:
Gonçalves, Carlos P., 2004, A Method for Tail Risk and Model pKTail Risk Control in (Sub)Market Risk Measurement Systems, MsC Thesis, ISCTE Business School, May.
And further developed in the papers:
Gonçalves, Carlos P.; Ferreira, Miguel A., 2004, Tail Risk and pKTail Risk, December 2004. Available at: http://ssrn.com/abstract=639181 (submitted to the Journal of Risk and Insurance).
Gonçalves, Carlos P., 2005, Um Método de Controlo de Risco de Cauda, in Temas em Métodos Quantitativo: Perspectivas do Cálculo Financeiro  2005, Raul Laureano and Luis Lopes dos Santos (Ed.), Edições Sílabo, Lisboa.
To produce this new artificial financial market we based ourselves, for the market maker and the trend follower in:
Farmer, Doyne (1998). "Market, Force, Ecology, Evolution". Santa Fe Working Papers
The speculators and trendfollowers learning algorithms came from the combination of genetic algorithms and from the social learning rule contained in the Netlogo model library’s model PD Basic Evolutionary:
Wilensky, U. (2002). NetLogo PD Basic Evolutionary model.
We like this combination better than traditional Genetic Algorithms (GAs) for social systems since it is less biological and more social, with its main strength put on local social imitation, and on individual creativity (in the form of the innovation, which corresponded to mutation, in the case of GAs). It also has a more Lamarckian flavour to it, which makes it closer to human social and cultural evolution.
This model is a part of a project still under investigation and this is the first place in which it is being proposed and in which a description and overall discussion of the model is being made. Any references to this model for academic publication should refer to:
Gonçalves, Carlos Pedro (2003) Artificial Financial Market Model II  Tail Risk. http://ccl.northwestern.edu/netlogo/models/community/Artificial Financial Market Model
There are two papers under way regarding this new artificial financial market and the, forthcoming, Artificial Financial Market III  Synchronicity, featuring two risky assets and interasset synchronicity (and more music).
Any comments or suggestions are quite welcomed and should be addressed to cgon1@iscte.pt
FURTHER REFERENCES:
Besides the references that appear on the first artificial financial market, here are some further references:
1) Regarding the concept of tail risk:
Yamai, Y.; Yoshiba, T., 2001, Comparative Analyses of Expected Shortfall and Value at Risk (2): Expected Utility Maximization and Tail Risk, IMES discussion paper series 2001E14, Institute of Monetary and Economic Studies, Bank of Japan.
Yamai, Y.; Yoshiba, T., 2002a, Comparative Analyses of Expected Shortfall and Value at Risk (2): Expected Utility Maximization and Tail Risk; Monetary and Economic Studies, April, pp. 95116.
Yamai, Y.; Yoshiba, T., 2002b, Comparative Analyses of Expected Shortfall and Value at Risk (3): Their Validity under Market Stress; Monetary and Economic Studies, October, pp. 181238.
2) Regarding the artificial financial market:
Some additional work done by Sornette that influenced the artificial financial market project:
Corcos, A.; Eckman, J.P.; Malaspinas, A.; Malevergne, Y.; Sornette, D., 2002, Imitation and Contrarian Behavior: Hyperbolic Bubbles, Crashes and Chaos, Quantitative Finance 2, 264281 (also available at http://arXiv.org/abs/condmat/0109410)
Zhou, W.X. and Sornette, D., 2003, Evidence of a Worldwide StockMarket LogPeriodic AntiBubble Since mid2000, Physica A
Johansen, A.; Sornette, D., 2004, Endogenous versus Exogenous Crashes in Financial Markets, in press in "Contemporary Issues in International Finance" (Nova Science Publishers)
Sornette, D.; Gilbert, T.; Helmstetter A.; Ageon, Y., Endogenous Versus Exogenous Shocks in Complex Networks: an Empirical Test (available at http://arXiv.org/abs/condmat/0310135)
Sornette, D. and Zhou, W.X., Predictability of Larger Future Changes in Complex Systems (available at http://arXiv.org/abs/condmat/0304601)
3) Regarding financial risk we also used:
J.P. Morgan Bank, RiskMetrics Technical Manual, New York: J.P. Morgan Bank, 1995 
(back to the NetLogo User Community Models)