1 Ph.D. in Electronic and Computer Engineering Dept. of Electrical and Electronic Engineering University of Cagliari Agile Methodologies and Tools for implementing and testing X-Agent Based Macroeconomic models Author Mario Franco Locci Advisor Prof. Michele Marchesi Curriculum: ING-INF/05 XXII Cycle February 2010
2 Declaration of Authorship I, Mario Franco Locci, declare that this thesis titled, Agile Methodologies and Tools for implementing and testing X-Agent Based Macroeconomic models and the work presented in it are my own. I confirm that: This work was done wholly or mainly while in candidature for a research degree at this University. Where any part of this thesis has previously been submitted for a degree or any other qualification at this University or any other institution, this has been clearly stated. Where I have consulted the published work of others, this is always clearly attributed. Where I have quoted from the work of others, the source is always given. With the exception of such quotations, this thesis is entirely my own work. I have acknowledged all main sources of help. Where the thesis is based on work done by myself jointly with others, I have made clear exactly what was done by others and what I have contributed myself. Signed: Date: i
3 Doubt grows with knowledge. J. W. von Goethe
4 UNIVERSITY OF CAGLIARI Abstract Ph.D. in Electronic and Computer Engineering Dept. of Electrical and Electronic Engineering Doctor of Philosophy by Mario Franco Locci Economies are complicated systems depending also on micro behaviours, interaction patterns, and global regularities. In fact, studying economic systems, considering a general or a peculiar point of view, has to take into account completely different real-world issues, such as asymmetric information, imperfect competition, strategic interaction, collective learning, and multiple equilibria possibility. An approach to study the real-world economic issues is Agent-Based Computational Economics (ACE). ACE regards the study and the development of multi-agent models reproducing, at aggregate economic level, global features emergencing from the complex pattern of individuals interactions. In my PhD research I considered the issue of multi-agent macroeconomic systems development, aimed to model and simulate European economy. The system used a framework based on X-Agent, which enabled parallel computation, and it can be considered a large agent-based software system. There are few cases in the literature of large agent-based economic systems. Given the unstable nature of the requirements and the flexibility of the chosen framework, I devised a software development process implementing a new and effective software engineering approach - Agile methodologies. Moreover, I introduced a notation for X-machine analysis based on Unified Modelling Language (UML) language, and I designed an approach based on Extensible Markup Language (XML) for unit testing and consistency verification of X-Agent systems, including the implementation of the relative tools.
5 Acknowledgements This thesis carries only my name as author but it is the achievement of my own efforts together with several contribution in my professional and personal life from all those with who I shared my experience. I want to dedicate the first tribute to my supervisor Michele Marchesi for making this Ph.D. possible and successful till the end, for her dedication to Science with passion and for her flexibility and determination. As all experimental projects, also this one needed cooperation with many members of the EUR-ACE European Agent-Based Economics (EURACE) project, whose contributions showed to be essential in my work. For this I want to thank all members of the project. I am also grateful to all the other members of the Agile group, with whom I shared three years of learning, researching and hours of life exchange.... iv
6 Contents Declaration of Authorship i Abstract iii Acknowledgements iv List of Figures List of Tables List of Abbreviations viii x xi Introduction xiii 1 Agent Based Economics Agent-based Model in Financial Markets Agent-based Model in Goods and Labour Markets Agent-Based models characteristics Software development issues Software agents and tools Agent based modelling and simulation (ABMS) tools NetLogo Java Swarm MASON Objective-C Swarm Repast Flexible Large-scale Agent-based Modelling Environment (FLAME) Agile software development EXtreme programming SCRUM The method v
7 Contents vi SCRUM phases The Sprint Flame Framework Transition Function Memory and States X-Machine Markup Language (XMML) Agent Messages A general description of EURACE model A general description of EURACE model Investment Good Market Consumption Good Market Labor Market Credit Market Financial Market Software Development Process and Practices Sofware development in EURACE The EURace Agile Methodology (EURAM) software development process EURAM Roles EURAM Artefacts EURAM Meetings The EURAM Process Software Practices Requirements Analysis and Design Coding Testing Using CCPForge Tracker to manage EURAM process Description of the levels of the EURAM project How organize the feature list and the iteration list Standard Subproject name Feature list name Iteration list name Dependencies Results X-Agent Analysis and Design What is an X-Agent? The basic design process of X-Agents UML for X-Agent State Diagrams
8 Contents vii Activity and Package Diagrams Agent-Message Diagrams X-Agent Representation Message Representation X-Agent and Messages Relationships Tools for updating agents models Testing Process Unit Testing Unit Testing concepts Automatic Testing Tools for large ACE models Automatic Unit-Test Generator Tool The configuration file The Suite Constants The Unit Tests The declarative part The fixture The expected values Automatic Integrity Testing Tool Consistency rules for ACE model The grammar rules Specifying integrity rules Application ouput Results Conclusions 99 Bibliography 101
9 List of Figures 2.1 (a)the Waterfall Model and its long iteration cycle.(b) The Spiral Model within its shorter iteration cycle. (c) Extreme Programming,encompassing of all these activities, a little at a time, throughout the entire software development process Xparser The market structure and agents of EURACE The EURAM process Repository organization and Directory Contents Conventions. For each model there are three sub-directories: <model> trunk, <model> branches and <model> tags. (1)trunk: contains the most up-to-date complete and working version of the model. This will contain: all files defining the model and three directories - initial data, tests and utilities. (2)branches: contains any development directories. These can be created by the developers and used as thought appropriate. (3)tags contains the tagged releases of the model. These tagged will be those that are offered as a distribution under the FILES tab of CCPForge Subprojects: in the Task Manager section there are eight sub-projects, one for each team Feature List and Iteration List: in each sub-project it is possible to organize the work using a feature list decomposed in a sub-set of iteration lists Add Task Section: the Add Task option allow users to create and modify personal iteration list and the corresponding feature list Line Of Code (LOC) and Churn shows the total LOC, and the amount of code touched per day File count. The total number of files Average file size viii
10 List of Figures ix 5.1 The XMML definition of an Household; Tags defined formally the structure :(1)tag < name >: x-agent name;(2) Tags < memory > < function > functions operating on inputs and memory, < nextstate > and < currentstate >: states name e transition.(3) < input > < output > are respectively input and output messages The dependency graph; the agent dependency among states are internal (backs arrows) and external (green arrows) The structure of an X-Agent; i : functions operating on inputs and memory, S i : states. σ Υ are respectively input and output stream messages An informal diagram showing Function Dependencies for the labour market model UML State Diagram applied to the states and the state transitions of a Household UML Activity Diagram used to document a function UML Package Diagram of a large economy simulator Graphical representation of an X-Agent. ( + ) Functions directly invoked in the states and able to read and write external message and ( - ) Functions able to access only its internal memory Graphical representation of a message Graphical representation of inheritance and message dependency relationships Agent-Message Diagram Verification and Validation (V&V) Modular organization of the test suites. There is a test suite for each sub-module of the system Modular organization of the test suites in the case of the Financial Market module An example of configuration file of the suites An example of constants definition Declarative part of the tool input The definition of a Fixture An example of expected values of a test Some integrity rules written accordingly to lexical-grammar of Automatic Integrity Testing (AIT). rules An example of integrity rule declaration An example results due to integrity rule application
11 List of Tables 4.1 Work meeting time-table The table with states, functions and transitions of an X- Agent representing an Household Rules checked taken from the EURACE wiki project Rules checked taken from the EURACE wiki project x
12 Abbreviations xi OOP Object Oriented Approach EURACE EUR-ACE European Agent-Based Economics EURAM EURace Agile Methodology ACE Agent-Based Computational Economics V&V Verification and Validation FLAME Flexible Large-scale Agent-based Modelling Environment AGT Automatic Unit-Test Generator Tool XML Extensible Markup Language XMML X-Machine Markup Language AIT Automatic Integrity Testing ABMS Agent based modelling and simulation GASM Genoa Artificial Stock Market HAMs heterogeneous agent models UML Unified Modelling Language AMD Agent-Message Diagram LOC Line Of Code
13 This thesis is dedicated to my wife and my parents for their love, endless support and encouragement... xii
14 Introduction Economies are complicated systems depending also on micro behaviours, interaction patterns, and global regularities. In fact, studying economic systems, considering a general or a peculiar point of view, has to take into account completely different real-world issues, such as asymmetric information, imperfect competition, strategic interaction, collective learning, and multiple equilibria possibility. New quantitative approaches are possible thanks to the development of analytical and computational tools. One new approach is Agent-Based Computational Economics (ACE), the computational study of economic processes modelled as dynamic systems of interacting agents ACE regards the study and the development of multi-agent models reproducing, at aggregate economic level, global features emergencing as a self-organized process born from the complex pattern of heterogeneous individuals interactions. Possible agents could be individuals (e.g. consumers, producers, workers), social groups (e.g. families, firms, communities, government agencies), institutions (e.g. markets, regulatory systems). Moreover, building a whole economics system, including real and financial economics, is a critical issue. In this work we consider macroeconomic systems development, focusing our attention on European economy, performed in EU funded STREP EURACE project. EURACE project involved eight different research groups dislocated in various European countries. The task of each group was to design models of modern economy interacting components and their implementation using a framework based on X-Agent, enabling parallel computation. EURACE innovation consists in simulating European economy creating a large software platform that implements an economy system as a whole, xiii
15 adopting the ACE paradigm. Our research aim in EURACE project has given important contributes to built the system, representing an original work on the software engineering methodologies used to develop large agent-based systems. This thesis is organized as follows: Chapter 1. A wide overview of ACE literature is presented, showing a large number of applications in finance and other economic sectors. The first and most successful field of application of ACE methodology was financial market, so here it is described the growing and promising literature about goods and labour markets. The chapter ends with a brief introduction on basic characteristics of ACE models. Chapter 2. In this chapter, firstly we give an overview of the state of art for implementing agent economic models. Secondly we present most important methodologies used to software development. We focus our attention on FLAME, one of the most important framework, used to implement EURACE model. The Agile methodologies (AM) well represent the state of art of modern software engineering. Among AM peculiar characteristics there is a particular software process approach, allowing to manage unclear and changing requirements. In second part we describe two of the most important agile methodologies: XP and SCRUM. Chapter 3. The chapter offers a detailed description of EURACE research project. EURACE project uses ACE paradigm as an alternative approach to rational representative agent model. The first section gives a general overview of the macro-economic model and underlines its fundamental requirements and its research objects. The last chapter sections give more details of each markets whole model and their agents. Chapter 4. In this chapter is presented a novel approach to develop large agent-based system. This approach, matured in EURACE research project, represents the emblematic case study. EURACE software is not a conventional one, because it uses software agents, with the aim to be run on parallel computers. This software development
16 needed a specific process management methodology specified and followed by the various involved teams. These teams were dislocated so they need to be coordinated and work together using the Internet. Chapter 5. In this chapter it is proposed a UML based method to perform analysis phase for x-agents and novel diagram. The first two sections analyse x-agents structure and their basic design process. Finally, the last section describes UML for x-agents and there is also a proposal for a novel diagram derived from the class diagram, underlining the relations among agents and messages:agent-message Diagram (AMD). Chapter 6. We present, in this chapter, two advanced tools for verifying and validating macro-economics models. The main characteristics of these tools, representing the enhancement respect to the preexisting ABMS, allows to enable testing phase using an easy and intuitive language based on XML. These tools are named Automatic Unit-Test Generator Tool (AGT) and AIT. AGT is a tool for facilitating non-expert programmers in writing unit-tests. Tests are written by using a simple and formal language, easy to learn. Economic models are characterized by several different assets flows, such as AIT, which automatically checks whether there is integrity in model set of internal consistency flows. Chapter 7. In this chapter we presents our conclusions.
17 Chapter 1 Agent Based Economics During the past two decades we had a big evolution of economics modelling; in fact, since 1990 many scientific works have been addressed to the agent-based computational approach. In this chapter we describe the ACE approach to analyze economic problems. ACE is an alternative theoretical paradigm to the Neoclassical Theory, based on Rational Expectation Hypothesis, Representative Agent concepts and Arbitrage and Efficient Market Hypothesis. Bounded rationality, endogenous out-of-equilibrium dynamics, direct interactions are some of the keywords that define ACE approach. ACE has been adopted to model the EURACE system. EURACE represents the experiment, which we carried out our research on; it represents a tentative to build a platform software to perform policy exercises and policy design. A detail description of EURACE model is provided in the Chapter 3. During past years, a large literature following ACE approach has appeared, focusing on different fields of economic theory, such as finance [1, 2], industrial organization , labour market [4, 5], electricity market , auction allocation efficiency , and innovation . Up to now, however, only a few partial attempts have been made in order to model a multiple-market economy as a whole [9 11]. About on 1998s, Basu et al. , were perhaps the first to develop an agent-based macroeconomic simulation model of the U.S. economy at Sandia National Laboratories. It was a computer simulator of a capitalistic economy with a detailed financial sector including a banking system and a bond market; agent learning was simulated by means of genetic algorithms. In the following sections, we will 1
18 Chapter 1. Agent Based Computational Economics 2 provide a detailed account of the state of the art of agent-based methodology on some fields of economics such as Financial Market, Labour Market and Goods Market Agent-based Model in Financial Markets The first and most successful field of application for ACE methodology were financial market. Basically, it was due to the availability of huge amount of financial data which allowed to make empirical analyses with a very accurate statistical resolution useful for models validation. Artificial financial market models can be considered as a natural evolution of the stylized heterogeneous agent models (HAMs) introduced in finance in the late 70s and in the 80s. Both HAMs and artificial financial markets aim to capture the real functioning of markets trying to explain the main statistical properties regulating the financial time series as a prices, returns, volumes etc. These statistical properties are commonly known as Stylized Facts of financial markets. The most important and common Stylized Facts are: Unit Root Property, Fat Tails and Volatility Clustering. An artificial financial market has to reproduce them for assuring its validation. These phenomena are at odd with the classical paradigm in academic finance, developed in the 60s and in the 70s by among others [13 16], and based on the representative agent approach, the efficient market hypothesis and the rational expectation equilibrium. The classical theory has been able to make only limited progress in resolving the important issues of the apparent instability in financial markets, but it failed to reproduce all the statistical properties of real markets. HAMs emerged in response to the difficulties faced by the classical appoach to understand some typical phenomena in the economic and in particular in financial markets. In fact, in the last decade, an increasing number of structural heterogeneous agent models have been introduced in the economics and finance literature. Among HAMs, a landmark of the recent research has become the modelling of various degrees of heterogeneity among agents, concerning either their trading strategies, or their learning abilities, or their adaptive responses, or their different expectations about future prices. In most of these models there are two typical types of traders.
19 Chapter 1. Agent Based Computational Economics 3 The first type are fundamentalists, believing that the price of an asset is determined solely by its efficient market hypothesis fundamental value. The second trader type are chartists traders, believing that asset prices are not completely determined by fundamentals, but that they may be predicted by simple technical trading rules, extrapolation of trends observed in past prices. One of first early example of financial HAMs has been introduced by Zeeman in 1974 . So, simple technical trading rules, such as chartist or trend-following behaviour, may survive evolutionary competition, even in the long run and beat rational strategies, based, e.g., on fundamentals [18, 19], [20, 21]. A second major issue investigated by HAMs is herding behaviour and the communication structure among traders see the papers [22 25]. A recent survey on HAMs is available by . With respect to HAMs, artificial financial markets try to address the problem of the complex agent heterogeneity and to model more realistic clearing mechanisms, thus abandoning analytical tractability for computer simulations. One of the first project in this respect has been the Santa Fe Artificial Stock Market, originally developed for simulation and validation of the genetic model. It combines a well defined market trading mechanisms with inductive agent learning performed by means of a classifier-based system [27, 28]. Following the Santa Fe Artificial Market, a number of computer simulated markets later appeared. In the 2000s, some researchers at the University of Genoa and Cagliari developed Genoa Artificial Stock Market (GASM). This framework includes both models and simulators able to simulate advanced financial market models more realistic with respect to the existing ones. It can be use to make what-if analysis of trading strategies, clearing mechanisms, behavior of traders, etc. or analysis of the impact of new trading rules. Computational experiments performed with GASM have shown that the market micro-structure plays a very important role in affecting price statistics; indeed, the well-known stylized facts can be recovered even with budget-constrained zero-intelligence traders and a realistic price formation process [29, 30]. Many other studies have been done about on the long-run wealth of traders characterized by different trading strategies [31, 32]. These studies have shown that different trading strategies give different results in different market conditions.
20 Chapter 1. Agent Based Computational Economics Agent-based Model in Goods and Labour Markets Agent-based models of goods and labour markets have tried to overcome the unrealistic assumptions of general equilibrium theory, perfect competition, centralized exchange and full information. Many, if not most features of real world transactions, can only be understood in an imperfect competition and asymmetric information framework. These can lead to adverse selection where low quality products drive out good ones. Solutions to avoid such a situation are signal and screening activities. Imperfect competition is the paradigm that develops when competition takes place among the few. In this system, agents act strategically, taking into account the impact of their own decisions on competitors behaviour and on the price mechanism. Such situations commonly arise when firms differentiate their products, erect strategic entry barriers, or exploit the imperfect information of their customers about the price or characteristics of their product, see [? ]. Decentralized instead of centralized exchange should also be considered. Albin and Foley  is an example of an earlier simulation study where geographically dispersed utility-seeking agents are engaged in decentralized exchange. The possibility that markets do no clear should also be taken into account. Jean-Pascal Bénassy (see ) makes an attempt to integrate, into a single unified framework, dynamic macroeconomic models including imperfect competition, Keynesian theory, and rational expectations. This framework is applied to a large number of dynamic macroeconomic models, covering topics as persistent unemployment, endogenous growth, and optimal fiscal and monetary policies. We can find the growing and promising literature about goods and labour markets in agent based models; examples about this context are Neugart s work which builds an agent-based model with endogenous vacancy creation, endogenous job search, random applications in a context of random matching, see . Similarly, Fagiolo and other, , replicate with their model three aggregate outcome related to labour market: Beveridge Curve, Phillips Curve and Wage Curve. They develop agent-based models of the labour and goods market taking into account the main findings of information economics. We model not only the search process, but we include asymmetric information, efficiency wage
21 Chapter 1. Agent Based Computational Economics 5 theory etc. also in the bargaining and adjustment process, in order to consider explicitly informational issues into agent based models. In this context, we formally analyse strategic behaviour with imperfect competition, disequilibrium markets and coordination failures providing an organic synthesis between agent-based economics and information economics. Among others, relevant results are obtained in the area concerning firms size distribution, aggregate fluctuations and growth. Recent empirical investigations have shown that firms size distribution is well approximated by a power law probability density function  and aggregate and firms growth rates are Laplace distributed . Several other related stylized facts, from industrial dynamics to business cycles, have been discovered and analysed by means of agent-based models. The ACE approach has also obtained interesting results about the relationship between financial fragility of firms and business fluctuations . The role of financial factors in business fluctuations was already pointed out by Greenwald and Stiglitz, . If firms are heterogeneous, also in terms of degree of financial fragility, this type of heterogeneity plays a crucial role in the evolution over time of aggregate variables such as production and employment. Firms bankruptcies and financial indicators, e.g., equity ratio, are good predictors of turning points in the business cycle or of financial crises. 1.1 Agent-Based models characteristics In the ACE models the economies is a complex systems, where a huge number of agents populate an artificial environment [41, 42]. The agents react changing their attributes adapting to new environment conditions. This approach consist mainly to build an economic world and to observe the emergent properties simulating the computational system. To understand the domain of research where the thesis is centred is useful to introduce the main characteristics of the economics agent based models. Bottom-up approach. The traditional neoclassical models have a topdown approach, where in the lowest level of detail there are the representative individual, which is constrained by strong consistency requirements, hyper-rationality and equilibrium. The agent-based
22 Chapter 1. Agent Based Computational Economics 6 models are in contrast to the traditional models for the bottom-up perspective, it builds a decentralized economy starting from the lowest level, which means that the aggregate properties are obtained as macro outcome of an micro dynamics interaction of agents. Evolving complex system. The basic entities live in the complex system that change over time. The aggregate properties emerge from the agent interaction rather than the imposed consistency requirements of rationality and equilibrium. Direct interaction. The agent models tries to represent the real nature of the economy, where the exchange of goods happen among the direct individual interaction. The agent decision depends on the adaptive expectations and on the past choices made by other agents. Bounded Rationality. The real world is too complex for hyper-rationality, so that the agents decide their actions with limited information and rationality, they behave as bounded rational entities with adaptive expectations. Learning. Agents in ACE model are able to change their parameters to adapt themselves to dynamically changing environment. Non reversible and non-stationary dynamics. The agent based models are characterized by true non reversible dynamics, which means that the state of the system evolves though different paths. The social economic system are inherently non stationary, the introduction of learning and adaptation determines the generation of new patterns of behaviour, so that novelties are persistent. The structure of an agent model, which is useful to understand the software issues where the state of art is discussed in the next chapter 2, possess typically the characteristics that follow. The system is populated by a set of agents whose size may change or not during the time. The system time is discrete, the evolution is observed varying the time discretely, the time step may be, second, minute, days or years, etc..