Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Agent Brokerage:


Published on

Published in: Business, Economy & Finance
  • Be the first to comment

Agent Brokerage:

  1. 1. Agent Brokerage A human-centred approach to automated stock trading Jón Grétar Guðjónsson Gary Alistair MacRitchie Department of Computer and Systems Sciences Stockholm University / Royal Institute of Technology November 2005 The following thesis equates to 20 weeks of full work for each author
  2. 2. Abstract An emerging concept in the field of financial products is that of software agents which are able to place trades directly on financial markets. The impetus for this is a perceived reduction in transaction costs, along with the ability to place complex trades that rely on a multitude of criteria being met. The additional benefits of increased speed of reaction and the ability to operate over many more investment opportunities than their human counterparts make software agents an interesting avenue of exploration for those wishing to gain a competitive edge on the financial markets. Following on from the proof-of-concept design of an Agent Trade Server at the Swedish Institute of Computer Science, this thesis shows that implementing a practical trading agent goes beyond the purely technical difficulties and has to consider the many legal, political, security and robustness considerations that are involved when dealing within an environment as significant as the financial markets. By carrying out a full requirements analysis, we show the major attributes from a technical and humanistic point of view required by any system that should work as part of a stock exchange. Further to this we propose a new architecture and offer an architectural design of an Agent Brokerage as a possible solution to support the creation of software agent traders, while meeting the requirements of the financial markets environment. ii
  3. 3. Acknowledgements The authors would like to thank the following people, whose valuable assistance made the thesis writing process an enjoyable and educational one. Magnus Boman our thesis supervisor and mastermind behind introducing us to agent trading. Magnus supported us throughout but also gave us enough space to explore our own path. Always available for a chat and kept us on track with great advice and suggestions. Thank you Magnus! Daniel Hilmersson, a former masters student whose work we took as a starting point for our investigations and who was always enthusiastic of our ideas and willing to help wherever he could. Employees of Islandsbanki and Ludvig Sandhagen at Hagströmer & Qviberg whose time spent assisting our research phase was much appreciated and proved invaluable. And finally to Elísabet and Maria for putting up with us spending too much time with our heads in books about the stock market. Jon and Gary iv
  4. 4. Table of Contents CHAPTER 1 - INTRODUCTION 1 1.1 Early efforts towards systematic trading 1 1.1.1 The approach of the academics 2 1.1.2 The approach of the industry 3 1.2 Research Question 4 1.2.1 Scope of the work 4 1.2.2 Formulation of a general research question 5 1.2.3 Related work 6 1.2.4 Feasibility of the solution 7 1.3 Goal 8 1.4 Purpose 8 1.5 Method 9 1.5.1 Research phase 9 1.5.2 Design phase 10 1.6 Limitations 10 CHAPTER 2 - RESEARCH AND REQUIREMENTS 13 2.1 The Social Environment 13 2.1.1 Clients 13 2.1.2 Analysts 14 2.1.3 Traders 15 2.1.4 Brokers 15 2.2 Hierarchy and information flow 16 2.3 The technical environment 17 2.3.1 Analyst information providers 17 2.3.2 Online Brokers 18 2.3.3 Trading Platforms 18 2.3.4 Existing exchange software 20 2.3.5 The Agent Trade Server 21 2.4 Complex trading agents 23 2.4.1 Many strategies, one active 23 2.4.2 Many strategies, many active 24 2.5 Reflections on requirements 25 2.5.1 Usability and humanity requirements 25 2.5.2 Performance requirements 26 2.5.3 Cultural and social requirements 28 2.5.4 Security requirements 29 2.6 Reflections on trading strategies 31 2.6.1 Strategy Representation 31 vi
  5. 5. CHAPTER 3 - THE BROKERAGE CONCEPT 35 3.1 Structural design 35 3.2 Internal design 35 3.3 Work segmentation 36 3.4 Scalability 36 3.5 Defining roles 37 3.5.1 Strategy Agent 37 3.5.2 Information Agent 37 3.5.3 Information Collectors 38 3.5.4 Portfolio Agent 38 3.6 Information flow 38 3.7 Interfacing with the stock market 39 CHAPTER 4 - DESIGN 41 4.1 Architectural design 41 4.2 Architecture overview 41 4.2.1 The Brokerage 42 4.2.2 The Information Agent 43 4.2.3 The Portfolio Agent 43 4.2.4 The Strategy Agent 43 4.2.5 The Representative Agent 44 4.2.6 Component communication 44 4.2.7 Client portfolios and strategy interactions 45 4.2.8 Information tokens 46 4.2.9 Strategy selection technique 47 4.3 Meeting the requirements 49 4.3.1 Usability and humanity requirements 49 4.3.2 Performance requirements 51 4.3.3 Cultural and social requirements 52 4.3.4 Security requirements 52 CHAPTER 5 - CONCLUDING REMARKS 55 5.1 Lessons learned 55 5.2 Conclusion 57 5.3 Future work 59 5.3.1 Designing a notification service 59 5.3.2 Visualisation methods for strategies 59 5.3.3 Implementation of the design 60 APPENDIX A - REQUIREMENTS SPECIFICATION I vii
  6. 6. Chapter 1 - Introduction A stock exchange provides facilities for the trading of securities and other financial instruments on a stock market. Members of the exchange are known as “Stock Brokers” and they work to match buyers with sellers so that trading transactions can take place. On modern stock exchanges, most stock trading is completed by the exchange software matching buy and sell orders that are sent to it by brokers. The brokers are following the instructions of traders; institutional or private investors, who employ varied strategies and methodologies in order to decide what stocks they should buy or sell. An emerging development in this relationship between traders, brokers and the exchange is the possible introduction of a method to allow software agents (Kagel and Roth 1995; Weiss 1999) to trade directly on the exchange. In this first section of our thesis, we will show why there is a need for such a new service, discuss the approach currently taken by industry, introduce the prototype agent trade server (ATS) and discuss how a trading agent can be designed to operate on this server. 1.1 Early efforts towards systematic trading Many traders see investing in the stock market as being a competition between them and the market, hence the term “to beat the market”. In order to beat the market, investors have devised a multitude of means and strategies in order to regulate their activities in the market place and protect themselves from what are seen as the disrupting emotions of greed and fear (Hasselström 2003). Historical methods and strategies such as those developed by Benjamin Graham, called value investing, as early as 1928, (Vanstone, Finnie et al. 2004) or Charles H. Dow’s (Edwards, Magee et al. 2001) introduction of technical analysis by Page 1
  7. 7. creating indices of leading shares as indicators of future market behaviour, have been developed into an array of methods, tactics and practices, which modern day investors have at their disposal. Immense amounts of work have been, and still are, spent towards creating new and innovative methods and theories to outsmart the competition, to gain a competitive edge. The financial industry has been relying more and more on the innovation and development within the IT industry and academia (ibid.). 1.1.1 The approach of the academics Academia has been industrious in producing models of the financial market (Kagel and Roth 1995). One of the first attempts to model economical environments, a field within economics called experimental economics, explores economical theories and paradoxes using experimental setups. The method dates as far back as the 17th century and from it classic problems such as the prisoner’s dilemma, the free-rider problem and more originate. Experimental economics have been used to test the prediction of theories, serving as a dialogue between experimenters and theorists and connecting the ideal world to the real world (Kagel and Roth 1995). Another field of academia, computational economics, is mainly interested in the behaviour of markets and many computational models have evolved to simulate trade on a double auction market. One of the tools academia has used to implement these models is the agent oriented approach. Each investor is represented with a surrogate in a multi agent system which behaves according to the computational model’s prescription. These models are either homogeneous (Homme 2005) where the interactions of a few types of traders are being researched, or Page 2
  8. 8. mixed, where the market consists of various types of traders utilizing various strategies to benefit from the behaviour of stock prices (LeBaron 2005). For example, artificial neural networks have been used successfully by a number of researchers to classify different types of stock, allowing them to identify undervalued stocks (Kendall and Su 2003; Vanstone, Finnie et al. 2004). Genetic algorithms have also been used to breed artificial investors, in an attempt to weed out the unsuccessful and create a breed of highly successful investors, or just strategies for use by real life traders to invest with (LeBaron 1998; Kendall and Su 2003). The agent metaphor has been used with success to create autonomous software to trade stocks using simple heuristics, both on artificial and real life markets (Sherstov and Stone 2004; Hilmersson 2005). Summarizing all the work previously done in academia is a book in itself and will not be covered in this introductory chapter in detail. Besides proving to be an immensely useful tool to analyze market behaviour, the work done within academia has resulted in researchers gaining insight into the inner workings of trading, and the creation of Artificial Stock Markets, such as the Santa Fe artificial stock market, and the trading agent competition (TAC) (Boman 2004), where agents can compete against each other in business. Recent times have seen the development of many technologies to attempt to allow users to find information, create new strategies, run complex strategies and automate the trading process using the existing stock market. 1.1.2 The approach of the industry Information technology has provided a recent revolution in the way in which non-institutional investors gain access to the stock Page 3
  9. 9. market and surrounding information. The rapid growth of online, execution-only brokers has changed the way people are buying stocks, not only in the way a transaction is completed, but also in the method with which a stock is chosen and investment decisions are made. These include various Internet-based information providers, stock screeners, online brokers and sophisticated trading platforms that shall be discussed later which allow the testing and implementation of individual trading strategies. The rise of the online broker has not only come about due to the lower costs incurred, but also due to the fact of the increased ease with which a trade is placed. Investors can monitor their own portfolio in real time (with more expensive accounts) or with a fifteen minute delay for free. 1.2 Research Question We will examine and research what conditions must be met in order for an autonomous agent to trade stocks on the real market. We will also try to capture those conditions in a design fit to trade stocks using multiple complex strategies. Hence our thesis type is of the artefact development type overlapping the areas of improvement of artefact types and need for understanding, cf. (Brash, Björck et al. 2005). In the following subsections we formulate our general research question, setting the scope for our work. 1.2.1 Scope of the work Many stock traders and brokers today spend a lot of time looking at numbers on a computer screen monitoring their investments. Their efforts are mainly spent on responding to market fluctuations, trying to make money on these changes. Very few of Page 4
  10. 10. today’s stock brokers actually make sense of all the abundance of information they are presented with every day (Hasselström 2003). The fast response time of the market and ever growing complexity of the exchange leave little time for the professional stock trader to think about tactics and evaluation of actions. According to the websites of the London stock exchange (LSE 2005) and the New York stock exchange (NYSE 2005), the number of listed companies is increasing by the week and new technological advances are made each year, resulting in faster and wider dissemination of information. Furthermore, the increased complexity and speed are straining those members of the public who want to monitor and do business on the stock market. It is our belief that the use of agents, acting on the behalf of investors, can address the complexity-and-speed issues of modern-day trading. We recognise that stock trading is now a global market and we will hence not be limiting ourselves to any local perspective. 1.2.2 Formulation of a general research question We will concentrate our work on the issue of adaptability and the environment of stock trading agents. With adaptability we refer to the agent’s way of determining what action to take on an abstract level, specifically deciding which trading strategy to implement at any given instance of time. Our research question is therefore: Can a sophisticated trading agent, which decides which investment strategy to use at any given point in time, be designed and implemented for the stock market? Furthermore what conditions must that agent meet to be considered a legitimate trader in real life? Page 5
  11. 11. Hence, our work will consist of researching the current environment of stock trading, what properties a stock trading agent has to have to meet the requirements of real life, and what environment such an agent must exist in. 1.2.3 Related work Real life stock traders have been mixing trading strategies together for over one hundred years. Agents for trading stocks on real life stock markets have not yet, to our knowledge, been designed to select appropriate strategies, from an arsenal of trading strategies, to maximize their effectiveness. In the coming chapters we will discuss the Agent Trade Server (ATS), a prototype platform which was designed to allow software agents to trade on the Stockholm stock exchange (Boman and Sandin 2005). For an agent running on the ATS, using only one strategy has proved problematic as shown in a previous masters thesis by Daniel Hilmersson (2005). In Hilmersson’s case the strategy chosen was not appropriate for specific states of the market. It is our belief that giving the agent the ability to adapt strategy choice dependent on market conditions would address this problem. Research into the field of designing agents which can employ a variety of strategies has been done before (Kendall and Su 2003; Homme 2005; LeBaron 2005). In those cases, when implementing the adaptation of the choice of strategies, artificial neural networks (ANN) were readily employed. For example, Kendall and Su designed a stock market model, with ANN-based agents, where a number of agents developed strategies. They also showed the necessity of social learning to improve the overall efficiency. There is however, one large drawback to using artificial neural networks; there is no easily understandable way to analyze the network’s knowledge after it has been trained. The network’s Page 6
  12. 12. synapses strengths are usually represented as a set of matrices of signed numbers called weights. A matrix of numbers cannot convey a methodology, not even a strategy such as “buy low and sell high”. Another approach to deploying multiple strategies does not involve ANN’s. This approach relies on conventional programming methods. For example, this approach has been taken in trading platform software such as TradeStation, using scripts and specialized command languages (TradeStation Group Inc 2004). We will address a problem not directly targeted before. To our knowledge, the work done so far has been focused towards the implementation, discovery or evolution of specific trading strategies. Since previous work has shown that there might be benefits of having a trading agent implementing different trading strategies based on the state of the market, we will try to devise a methodology to address this problem. This has not been researched in conjunction with trading agents before to our best knowledge. 1.2.4 Feasibility of the solution We will analyze the requirements put forth by the industry which a real life stock trading agent must meet. Our main effort will however be spent towards creating a methodology for running complex trading agents in today’s technical environment and creating a design which meets both our functional requirements and the non-functional requirements imposed by the industry. We will build on the work done by Hilmersson (2004) and Johansson et al. (2003), the analysis performed by Boman and Lybäck (2002) along with various other sources. Page 7
  13. 13. 1.3 Goal Our goal with this project is to build an understanding of the requirements and difficulties associated with developing complex agents which can trade alongside their human counterparts on the real stock market. We will seek to accomplish this by attempting to design an agent capable of investing using an arsenal of different investment strategies. By assessing the financial industry standards, conventions and legal requirements we will consider the barriers to the practical use of agents in the real world and propose robust and secure solutions to overcome these barriers. 1.4 Purpose By allowing the programmed strategies to be complex in nature if desired, we will show that agents allow for a new channel of access to investing on the stock-market. Such software could enable the professional stock trader to spend more time thinking about a course of action for managing and planning the trading of stocks, instead of spending efforts towards monitoring a list of orders on his computer screen. Allowing the home investor to create his, or her, own strategies and leave the implementation of these to the agents will also improve the public’s accessibility to the market, levelling the edge that the large financial institutes have on the public. Automating the decision of which strategy to use to trade stocks can also empower the average day user to develop strategies with a degree of security, since the “best” strategy is used at any given time. The client can rest assured that his trader is always investing using its optimal strategy, without him having to monitor his investment constantly. Page 8
  14. 14. 1.5 Method This section describes the methodology we will use to design our trading agent. We will base our work in part on software engineering lifecycle models, such as the waterfall model and the spiral model but only to a certain extent. The work will be split and carried out in two main phases: the research phase and the design phase. We will continue our research throughout the project, addressing design issues as they arise. The model that we have chosen is an iterative version of the waterfall model (Bennett, McRobb et al. 2002). The reason behind our choice of the iterative waterfall method is two pronged. On one hand we both have good knowledge of this method and have used it in our previous projects, on the other hand we felt that an easily understandable and well defined model would bring structure to our otherwise unstructured research. Following is a description of each phase. 1.5.1 Research phase The research phase consists of two parts, literature research and a quick and dirty ethnography research. The two parts are carried out in parallel and will be continued throughout the duration of the thesis work. The literature research phase consists of reading and reviewing literature related to the field. The topics of the literature cover all fields related to our thesis, such as technical and fundamental analysis for stock trading, stock trading practices, strategies for stock trading, agent design and programming, anthropology research and software engineering. Page 9
  15. 15. Quick and dirty ethnographic research is used to gain knowledge of the environment and practices of stock trading. It consists of a series of short interviews and observations, even a questionnaire, deploying a semi-structured interview technique to capture as much peripheral information as possible. The contents of the questionnaire sent out to Íslandsbanki and modified version used to interview Ludvig Sandhagen at Hagströmer & Qviberg consisted of questions regarding their disposition to their work and workplace, their day to day routines, their job definition, their actual responsibilities at work and their experience and knowledge of computer systems. By capturing this peripheral information we discovered what we could not read in books, but is common knowledge in the field. This builds up our overall understanding and enables our design to conform better to the requirements of real life. 1.5.2 Design phase When all the basic information has been collected and analyzed we will follow a software design methodology. Since software agent design is a relatively new field, we will mainly adhere to the Object Oriented design methodology (Bennett, McRobb et al. 2002), but modify it, were we find necessary. 1.6 Limitations The focus of our thesis will be the development of agent software to choose which strategy to use while investing money, although these strategies are based on specifics of stock trading, we will not go into specific strategies in any detail. Further, we will only consider the trading of company stock and by trading we refer to the process of first buying then selling (also known as “going long”). Page 10
  16. 16. We will design an environment for the stock trading agent’s execution, based on the information we have collected. It is important to point out that this thesis is a demonstration of our knowledge in design with respect to social and humanity factors as well as external requirements. We will present our design as a blueprint, or a guideline for whomever wants to implement such a design, we will not delve into implementation specific issues or present the result of any programming efforts. Page 11
  17. 17. Chapter 2 - Research and requirements The existing methods of trading stocks have a well defined social structure. This allows us to look at how a trade is executed through the main players involved in the market. These are the client, the trader, the analyst, the broker and the investment houses. Figure 1: The main players in the stock market are the client, the traders, brokers and analysts. There is a constant flow of resources and information between these actors and varying shifts in responsibility depending on the task being undertaken. 2.1 The Social Environment Following is a discussion of the social environment of stock trading. 2.1.1 Clients There are many entities that could be referred to as clients in the world of stock investment. These range from private individuals who choose their own stocks and trade directly with a broker in order to buy or sell, to large investment banks putting forward money to be invested by a team of professionals. When regarding Page 13
  18. 18. the individual as the client, investing a sum of money with an institutional investment house, perhaps as a part of a mutual fund or an investment product such as a private pension, we can see the client as filling two roles. Firstly, the clients are the providers of funds to be risked upon the stock market in the hope of increased returns. They provide the fuel that drives the engine of the stock market and as such when acting on mass are a very powerful group. Secondly, the clients are courted by the investment houses and suppliers of investment products by using a multitude of marketing techniques. Probably the most effective of these techniques is the ability to show potential clients good past returns in order to tempt them to invest. This puts pressure on investment house managers to get the best returns and this pressure is passed down to the traders, often with severe consequences for failure and high rewards for success (Hasselström 2003). The individual client in these scenarios may well be the catalyst for the whole process, but is however likely to be the least knowledgeable about the mechanisms of the market and the implications of different events on the market. 2.1.2 Analysts Analysts are employed either internally by investment houses or by specialist companies who sell their results as services to investment houses. It is the analyst’s job to perform various examinations of a stock’s potential and to report this back to a trader. If a trader makes good investments from recommendations from a particular analyst, he is more likely to trust him and use him in the future, which is good for the analyst’s career. Analysts tend to see the traders as gamblers while they think of themselves more as scientists (ibid.). Page 14
  19. 19. 2.1.3 Traders The traders have a two way relationship with the managers of the investment houses. These managers decide which traders to recruit and which traders to promote or fire, but the careers and businesses of the managers also depend on the success of the traders. The professional traders themselves tend to know only about 15 or 20 companies in great detail and continually monitor these companies stocks for investment opportunities, perhaps trading the same stock several times a day (Schwager 2001). The traders make the decision about what stocks to buy and sell and when, but they have to use an intermediary called a broker for the execution of the trade on the stock exchange. 2.1.4 Brokers The brokers earn commission for every trade whether it is a profitable one or not. As such, it is in the broker’s interest to try and ensure that a trader uses him for each trade and to achieve this broker’s work hard to build a bond between themselves and traders. They do this through trying to pass traders profitable information and also through a more social scene of entertainment and expense accounts. Traders too, work at building a bond between brokers that they trust in order to be in line when the broker gets some useful information. However, traders tend to hold brokers in quite low regard and consider them as being of lower status than themselves (Hasselström 2003). Information thus tends to flow towards the trader as he makes the decisions on where the money is spent. Analysts take their information from financial reports, stock price trends, etc and construct recommendations for traders to use. Brokers use knowledge of trades that are going through, rumours and word of Page 15
  20. 20. mouth in order to make their recommendations to the traders. The traders have to evaluate all the time the quality of the information they receive and learn which sources to trust and which to ignore. Once the trades have been placed, the financial house managers evaluate the traders’ performance and decide which ones get bigger portfolios to manage and which ones are no longer employed. Generally after fixed periods of time, the clients are informed of their investments’ performance. They then evaluate this information and decide whether to invest more money or withdraw their funds and invest elsewhere. 2.2 Hierarchy and information flow We can present the institutional hierarchy and the flow of information using a rather simplistic schematic diagram, see Figure 2. Figure 2: Information flows between the actors in the stock market, with a hierarchy of decision making. Page 16
  21. 21. The brokers interact with the exchange placing sell and buy orders. They receive their directions from the traders, who are acting on behalf of the clients. We can also visualize the flow of information, starting at the brokerage and propagating outwards toward the client. The information usually propagates through the layers of the brokers and the traders at the same instance, but the client only receives information a while after the events happened on the stock market. However using today’s technological environment, information can be retrieved from the stock market much faster than it propagates through the different layers of brokers, traders and clients. 2.3 The technical environment In the following subsections we will have a look at the technical environment of today’s stock trading. 2.3.1 Analyst information providers Prior to the widespread acceptance of the Internet, the individual investor would have to rely upon sources such as newspapers, end of year reports and advice from stockbrokers when researching a share. Now, the private investor can access a range of continually updated financial information from his or her desktop for free or low cost subscriptions (Allgood 2001). Web portals such as Yahoo ( and more specialist sites such as The Motley Fool ( offer huge amounts of historical and 15 minute delayed market data, charts, news, broker recommendations, trends, technical analysis, income statements, balance sheets, end of year reports, cash flows, analyst estimates, research reports and much more, all for free. New innovations such as a stock screener that allows investors to Page 17
  22. 22. narrow down the thousands of stocks that exist on a market to those that match the individuals basic prerequisites ( allow the investor to complete at the touch of a button a previously unfeasible research task (by the time the individual had researched through thousands of stocks some data may have changed, rendering his research erroneous). The constant supply of high quality financial information available to all those with a modem has in many ways levelled the playing field between individual and institutional investors and has certainly fuelled a belief in many individual investors that they no longer have to rely on brokers or brokerage firms to decide about their market transactions. 2.3.2 Online Brokers According to an article in the Economist magazine (The Economist Newspaper Limited 2000), in the mid 1990s clients of full-service brokers were regularly paying between $100 to $400 USD per trade. In May of 2000, clients of the major off and on-line broker Charles Schwab could place a trade for $14.95 while accessing all the previously mentioned information for free. The ability of an online broker to cope with fluctuations of demand and deliver instant price quotes for thousands of stocks across many markets means that online stock broking provides more than just an automation of the telephone based execution services (Allgood 2001), but actually hides the brokerage stage from the investor and allows him to feel he is dealing with the market directly. 2.3.3 Trading Platforms A step on from the online brokerage and research is the emergence of trading platforms for both institutional and individual Page 18
  23. 23. investors. An example of such a trading platform for institutional investors is SunGard’s Front Arena (SunGard 2005) which combines front and back office supportive software as well as tools for analysis and trading across multiple markets. Software to support smaller companies or individual investors such as eSignal (eSignal 2005), Metastock (Equis International 2005) and most noticeably, TradeStation (TradeStation Group Inc 2004) occupy the gap between the existing normal trader/broker relationship and what we will suggest as a possible future scenario in this thesis. It will be illustrative to look at some features of these three packages. Metastock and eSignal allow the software owner to carry out technical analysis on stocks, bonds, currencies and other tradable investment opportunities. The user downloads third-party historical or real time data for the commodity he is interested in and then uses the program to perform the analysis. The programs include different indicators and tools to help in sorting and selecting stocks that meet predefined criteria. Both programs have many features but the main focus of these programs is to allow users to create their own buy and sell strategies based on technical analysis and then run them against historical data to see if they would have been successful in the past as an indicator of possible future performance. Users can also pick certain stocks and run multiple strategies in order to see which strategy is the most effective for a particular investment opportunity. The output of the program is effectively recommendations on which strategy to use, which stocks to buy and sell and importantly, when. Both programs can be linked to an online broker to allow the user to enter their trade orders directly. Page 19
  24. 24. TradeStation is similar in many ways to eSignal and Metastock allowing investors to develop and back test strategies on historical data. TradeStation allows users to write their own strategies using a proprietary pseudo-code, allowing simple or extremely complex technical strategies to be tested. One of the most interesting aspects of TradeStation is that trading can be set to be fully automated. TradeStation monitors the market in real time, tick by tick, and once market opportunities are identified that match the investor’s strategy; it can execute the trade without any interaction from a human. The buy/sell orders are sent automatically by the program to an online broker who completes the trade on the real market. The concept of TradeStation is very similar to that of agent trading using the prototype ATS. After the strategy is set, the program takes full responsibility of what stocks to buy or sell and when to make the trade. As far as the user is concerned, the interface between the trading platform and the actual market is seamless. 2.3.4 Existing exchange software At the heart of modern stock exchanges lies complex software systems matching buyers and sellers and distributing information on already executed trades known as trading systems (OMX 2005). In order to be able to trade on an OMX exchange, the broker needs a member SAXESS trade application. Each application connects to a SAXESS trade server which in turn is connected to the core. This all happens using the XTP protocol, which stands for open eXchange Transaction Protocol. The XTP is an OSI layer 7 protocol. In this case, the core is a deterministic program written in C, which matches stacks of buy and sell bids from investors. These systems are utilised by brokers who are either placing trades on their own behalf, or on behalf of traders Page 20
  25. 25. who pay them a commission to do so. A schematic description of the general system can be seen in Figure 3. Figure 3: At the heart of modern stock exchanges lies complex software systems matching buyers and sellers and distributing information on already executed trades known as trading systems. 2.3.5 The Agent Trade Server Combining both the work done in academia and the industry, an Agent Trade Server (ATS) has been developed and implemented Page 21
  26. 26. at SICS ( The work was done in cooperation with a company, now called OMX, as a proof-of-concept (Boman and Sandin 2005). An ATS is a link between trading agents and the actual stock exchange system. It executes agents, supplies them with stock data and enters their orders into the system. The ATS opens up the possibility for agents to submit complex orders and allows them to follow pre-programmed investment strategies and broker their own deals as if this was a real stock market. Some agents for the ATS have already been programmed. Jesper Johansson and Michael Poijes developed a shell for trading agents (2003). Their work resulted in the implementation of a Java package to use when implementing agents for the ATS. To test their package they developed a simple day trader agent. Their work resulted in proving their hypothesis, that a simple agent can be implemented for the ATS in a few hundred lines of code, while maintaining correct functionality. Another thesis written by Daniel Hilmersson improved previous work done for the ATS. Hilmersson’s work, based on the agent package by Johansson and Poijes, included the business logic known as “Reversal Gap”, (Hilmersson 2005). Hilmersson showed that it was feasible to have a larger, more sophisticated agent run on the ATS. The agent functioned correctly and the business logic was executed as expected. Hilmersson also modified some of the code for the ATS to enable his agent to parse historical data for evaluation. However, these agents have rather been a proof of concept, running on a limited market (for example 10 stocks) with simple single strategies. There is still the issue of complexity to address, combination of strategies and decision making based on Page 22
  27. 27. information one cannot mine from stock prices alone. More agent variants are needed, in order to display the flexibility and accessibility of the ATS (Hilmersson 2005), (Jesper Johansson 2003). 2.4 Complex trading agents For his thesis, Hilmerson programmed a simple day trader running on the ATS. One of his findings was that the strategy he used demonstrated varying efficiency depending on the state of the market. He suggested the development of an agent that can run different strategies and invest using the best one. This was the starting point for this thesis; we wanted to design an agent which has many strategies at its disposal and would invest using the strategy which yields the best return at any given point in time. There are different ways of achieving the goal of trading with multiple strategies. 2.4.1 Many strategies, one active The first approach is to create an agent which has a set of strategies and a guideline when to use each strategy. In this case the agent will follow instructions on what strategy to invest with at any point in time. The benefits of this approach are that the design of the agent is very simple, concise and neat. Strategies are active based on market indicators or other predetermined yardsticks indicating which strategy to use. This way has the drawback of being ill adaptable, or not at all. If any of the premises the master strategy uses change during the timeframe of the program, the appropriateness of the strategies changes. For example, if the financial landscape changes in a way that is unforeseen the yardstick used to select the best strategy is useless. This is especially true when many people are using the same strategy, Page 23
  28. 28. since the inefficiency in the market exploited by the strategy gets over exploited. In that case the strategy loses its edge and may not be the most appropriate one. 2.4.2 Many strategies, many active This leads us to the second way of trading using multiple strategies. As we have noted before, the selection criteria should be based on which strategy is performing best at any instance in time. To be able to determine the strategy which is performing best at any instance in time we must have some means of evaluating their return in real time. However, evaluating their return in real time implies that we need to have each of the strategies running concurrently; measuring and comparing their performance in real time. These kinds of tasks, repetitive number crunching, are exactly what a computer is best at. Therefore, we suggest that instead of running a single threaded agent, a multi threaded agent is needed to achieve these means. The agent would then have a thread running for each of the strategies, and a number of control threads evaluating the performance of the strategies and doing the actual investing. This method addresses the problems associated with using a static yardstick to determine what strategy to run. By comparing for example, portfolios for each of the strategies, we have a dynamic, adaptable yardstick which will always yield the strategy which is performing best at any point in time. This idea has some implications for the ATS. As Hilmersson work pointed out, an ATS can run day trading agents which each have a single thread of execution. When we add strategies to each of the agents running on the ATS the number of threads managed by the ATS increases considerably. As each agent consumes more Page 24
  29. 29. resources, the ATS is able to support fewer agents than before with fixed resources. If the number of agents running on the ATS should stay the same, the resources should be increased considerably, which in turn means more expenses for whomever is responsible for managing the ATS. As our research and requirement analysis progressed we saw that this approach is a simplistic one, there are number of functional requirements that we identified which imply that the software should have more sophisticated facilities for strategy selection, portfolio management and information aggregation, in addition to the evident need for the user to be able to easily express the strategies he wants to use. 2.5 Reflections on requirements Requirement identification and specification are a vital part of any design process. As we worked towards the completion of our task we used a requirement specification template created by the Atlantic systems guild, called Volare (Robertson 2004). The results of the requirement specification can be seen in Appendix A. We captured the requirements by mining them from the data collected by interviews, quick and dirty ethnographic surveys and numerous pieces of literature research, see list of references. Following is a discussion on what we found during our requirement specification steps. We examine different types of requirements and analyse their implication on our design. 2.5.1 Usability and humanity requirements Correct functionality of a system is always an important issue, especially when the stakes are as high as they are in the financial industry. It is imperative that the system provides some way to Page 25
  30. 30. analyse its actions. It is not important at this stage what ways are provided as long as they can be used efficiently to correct the system and fix errors or bugs. Another issue surfaces after we identify the need to be able to analyse the system’s actions. The system needs a way to efficiently fix its problems without having to bring the whole system down. For example, if there is a small part of the system needing changes, upgrades or bug fixes it is unacceptable that the whole system has to be stopped and started again once the work has been carried out. An implicit requirement is that the system has clear and well defined boundaries between its subsystems that have different responsibilities. The system must facilitate experimentation and research. Trading platforms in general should provide these functionalities both at the level we mentioned earlier, that the user should be able to see what the system is doing and analyse its actions, and also allow the user to experiment with new strategies and different ways of processing information. 2.5.2 Performance requirements Systems running in the financial market are “hard” real time systems. That is, there cannot be any delays when sending messages and orders back and forth. This real time propagation of information requires the system to be flexible to changes in its environment, both software changes and hardware changes. Routers, hard drives, and even software components might fail due to error correction, updates or bugs. In addition, being a “hard” real time system interacting with the stock market, the system must be available and running at all times appropriate for Page 26
  31. 31. a stock exchange. That only leaves a part of the night for maintenance and data backup. Most exchanges have regular opening hours, during which the system must be available. The system also needs to perform other jobs after opening hours, such as evaluating end of day strategies and performing maintenance on databases and perhaps logs. It has been pointed out by Boman and Lybäck that the core systems in the exchange are not allowed to become overloaded. The financial exchange is also a “hard” real time system and must be tractable, that is to carry out all its tasks within an allotted timeframe. Therefore software running on the core system is not allowed to consume too many resources and risk overloading the core system. To ensure this Boman and Lybäck pointed out that all code running on a system tightly coupled with the exchange must be inspected by the authority responsible for the core systems of the exchange. Inspecting and verifying the functionality of all the code is an immense and tedious task. It was suggested that limiting the language, methods, libraries, etc. that agents can be constructed in can be used to make the process of code inspection feasible. Even if it has been a tractable task when running simple agents, it is not an attractive task after having introduced more complexity onto the software, such as thread interaction which can result in deadlocks and other artefacts which are not popular in a tractable “hard”, real time system. Further more, no client’s code is allowed to interfere with the execution of another client’s code. As soon as a single client’s code brings down the system, because of badly written or malicious code, he might become financially responsible for the incurred losses and damage caused by his code. In a high stakes environment such as stock trading, the amount due could easily cripple any investor, Page 27
  32. 32. in addition to causing loss of trust and degrading the integrity of the authority responsible for the exchange. 2.5.3 Cultural and social requirements We must also consider requirements based upon social and cultural constraints and conventions. As pointed out by Almberg (2002), when we introduce a new system into the market, the credibility of the institution involved should not be degraded. This is especially true when dealing with an institution such as the stock exchange as it is a barometer for countries and global economic performance and affects government and individuals’ economic decision making and policy (Hasselström 2003). The consequence of a loss of credibility in the financial markets can be seen by the effect of the accounting scandals at firms such as Enron and WorldCom. This contributed to an increasing falling market and new regulation in order to try and restore client confidence (Bonello 2005). It is also imperative that the functionality of the electronic exchange continues to be deterministic and that the functionality does not change in any way. This is important because the exchange has in essence provided the same services for decades. All changes and modifications done to the exchange have been to optimize its operation, not to change its fundamental role as a double auction market, matching buy and sell bids. When any bilateral transaction is conducted, there needs to be an element of trust especially when being the first to act. This factor is increased when dealing with online systems (Kollock 1999) largely due to the inexperience in dealing with the new concept, unfamiliarity with the medium or the lack of a visible physical Page 28
  33. 33. presence of the people you are trading with. When discussing the concept of allowing a piece of software self-directing control over a large amount of an individual’s money, we believe that trust will be a major factor. To support trust in such a system, it is important that it be regulated by a trusted financial services authority, then clients know that the company itself meets certain standards of credibility. As for the concept of allowing the agents control over people’s money, we believe that we can support clients’ confidence in the system by allowing them to test their strategies on historical data. This would allow them to build an impression of how they may perform in the future. This is analogous to how a client may choose a mutual fund investment on its previous year performance. 2.5.4 Security requirements We touched on the need for code inspection when discussing performance requirements. There are also other aspects to verifying the code, mainly security reasons. Because it is a highly prominent system and the sheer number of agents running on a system that is coupled to the stock market, it would most likely become a target for hackers and other mal intended individuals. Verifying the functionality of all the code, to try to detect all attempts to break or do harm to a core system in the exchange, becomes an immense task mainly because of the following factors. Using encryption techniques and advanced coding techniques, malicious code can be hid inside seemingly harmless code. Competitions have been held where hackers have written a seemingly harmless program and had other hackers try to locate malicious code masquerading as simple harmless excessive Page 29
  34. 34. code, that is code which has no apparent task but is usually included in source code due to various reasons, such as quirks, coding conventions and even ignorance (Craver 2005). The number of clients running on the system could be huge. If we consider trading platforms such as TradeStation, which as of June 30th 2005 had 20,942 clients (TradeStation Group Inc 2005) and then consider the case that each client’s code has to be examined for malicious parts, possibly written using state-of-the-art virus techniques, the business of verifying code becomes a booming business, adding excessive costs to running a client on a centralised system. Further to this, every time the client wanted to make even the smallest of changes to her code, the whole examination process would have to start over again. There is also the issue of authentication; a common strategy used by inventors of malicious code is to impersonate a trusted partner. For example one of the computer viruses to emerge in recent years, Worm-Swen.A, impersonated an email update notification from Microsoft (Symantec 2004). The bullet asked the receiver of the email to install a patch to prevent his computer from being infected by a second virus, by installing the “patch” he infected his own computer with the first virus. This presents the problem of authenticating the programmer of the code running on the core systems. The authority responsible for the core systems must have a way of making sure that the code was programmed by whom it says it was. There are various technologies available today, such as the Java security model which prevents tinkering with the code, Public Key encryption and so on. This however becomes a tedious task if the numbers of Page 30
  35. 35. clients reach the numbers using today’s commercial solutions as we have mentioned before. And last but not least, the system must be designed so that full confidentiality is kept. There must be no way for software running on the system to examine the preferences of other programs, eavesdrop on communication between the software and the core systems, and hence gain valuable information which otherwise would not have been available. 2.6 Reflections on trading strategies Strategies are the methods used to narrow down all available stocks to the ones that should be invested in. Strategies can vary in many ways from the simple (for example only investing in stocks with price to earnings ratio greater than x), to the complex, to the seemingly bizarre (such as relying on planetary alignment). Human traders mix and match strategies dependant on market conditions so a complex trader should be able to run multiple strategies simultaneously while able to execute trades from those most likely to succeed. 2.6.1 Strategy Representation Strategies and the data they analyse are a matter of individual investment preferences, but there are four main aspects needed to have a full strategy. The Encyclopaedia of Stock Market Strategies (Katz and McCormick 2000) provides the following definition of the needs of a complete strategy. 1. When and how, and possibly at what price, to enter the market Page 31
  36. 36. 2. When and how, and possibly at what price, to exit the market with a loss 3. When and how, and possibly at what price, to exit the market with a profit. To which we add the following… 4. When and how to exit the market after a period of time. This allows for the strategies to be modularised with each strategy consisting of a maximum of four modules. The four strategy modules are the entry sub-strategy, the exit for loss sub-strategy, the exit for period sub-strategy and the exit for profit sub-strategy. Each strategy is made up of these four blocks. This allows for easy creation of multiple strategies from pre-written strategy building blocks, e.g. one for when to enter the market and one for each of the three ways to close out a deal. This could be a very simple method for novice or standard users to customise their own strategy choices by choosing slightly modifiable prewritten blocks from a strategy library. Much research was done into the make up of strategies and the different manners in which technical analysis indicators are used to signal stock buys, however, that topic would be better suited for an economics thesis. The main point of interest with regards to agent trading is how a strategy can be represented easily for processing by a strategy agent. We propose a method to overcome this problem by breaking strategies into Boolean statements that if met produce an action. This way even the most complex of strategies can be broken down into a list of simple true or false statements. For example, the Reversal Gap strategy used Page 32
  37. 37. by Daniel Hilmerson would be explained in human terms in the following manner… If the opening BUY price is higher than the highest BUY price of yesterday and the closing BUY price is over both the mean price of the day and the highest BUY price for the last two days, then that day has the potential to be a Reversal Gap Day. If the 50 and 20 day average trends are positive then a buy is entered for execution on the next day at the highest BUY price of the Reversal Gap Day. This could be broken down into a series of Boolean functions that if met produce an action, for example (where n is the stock and t is the date)… • BUY_OPENn(t) > BUY_MAXn(t-1) • BUY_CLOSEn(t) > PRICE_MEANn(t) • BUY_CLOSEn(t) > BUY_MAXn(t-1) • BUY_CLOSEn(t) > BUY_MAXn(t-2) • 50_DAY_TREND > 0 • 20_DAY_TREND > 0 • Action = BUY @ BUY_MAXn(t) If a list of stocks that match each Boolean statement is returned then any stock that is on all lists would be processed according to the action. Each variable in capitals would have to be able to Page 33
  38. 38. return a value; we discuss how this could be in section 4.2.8 where we introduce the concept of information tokens later on in the thesis. Page 34
  39. 39. Chapter 3 - The Brokerage Concept We have emphasised a number of properties and behaviours our system must possess and demonstrate. Non-vital topics have also been mentioned and in this chapter we will try to tie those vital and non-vital requirements together in a concept we have chosen to name the Agent Brokerage. The following chapter introduces certain issues our architecture addresses and in the next chapter “Design” we present our idea of a design for this brokerage. 3.1 Structural design By structuring the design to be analogous to the current human system, we can take advantage of a tested architecture that users are already familiar and comfortable with. As discussed before, there is a multitude of legal, political, technical and regulatory reasons why it would be unfortunate to allow complex traders to be run on a system tightly coupled to the core systems of the stock exchange cf. 2.5 above. We propose a solution to this problem by introducing the Agent Brokerage. The Agent Brokerage is an additional server for running trading agents. The brokerage is based at a different physical location from the exchange, allowing multiple brokerages to be run by different institutions and companies without involving the authority responsible for the exchange. Its purpose is to allow the running of trading agents on a platform where they are free to access various resources or be modified to fit the needs of a client. 3.2 Internal design We suggest that the brokerage is constructed as a multi agent system (MAS) where labour and responsibilities are clearly divided between agents analogous to the current human Page 35
  40. 40. arrangement. It is our belief that this arrangement has several advantages over traditional design approaches as we shall elucidate to in the following sub-sections. 3.3 Work segmentation By assigning different tasks to different agents we achieve a social structure similar to that in use in real life. Although ours is a simplified version of the real thing, it is our belief that it serves the purpose. We need agents that assume the roles of the trader which finds stocks that are profitable, the analyst which looks into historical trends and processes information, and the portfolio manager which manages the portfolio with regards to risk management, money management and so forth. One of the benefits of distributing responsibilities in this way is that standardised agents can be used for various tasks, relieving some of the tedious task of code verification performed by the authority running the brokerage. One of the remaining variable factors within the brokerage is the strategy agents. As we have seen in section 2.6 there are standardised ways of expressing strategies. If we include this standardised way of expressing strategies in our system, we can replace the custom built strategy agent with a standardised agent, without sacrificing the flexibility of a customised strategy agent. 3.4 Scalability One of the most common problems faced by software engineers today is to develop systems which scale gracefully. Our technique of using a MAS approach allows us to split our system up and run it on separate processors and in separate memory spaces. It is our belief that communicating over a network in today’s Page 36
  41. 41. technology environment will not pose a problem. The brokerage will be connected to the exchange over a high speed WAN connection, as often is the case. Servers will then be connected to each other, over a high speed LAN, such as a gigabit Ethernet connection. 3.5 Defining roles In order to achieve the requirement of having agents capable of placing complex trades, we suggest a multi layered architecture where recommendations of stocks to buy or sell are delivered to a central decision making agent that decides which recommendations to listen to and instructs a trade to be executed. This can be thought of as analogous to different brokers and analysts recommending stocks to the traders in the human realm. We see the major parts of the brokerage system as consisting of the following components. 3.5.1 Strategy Agent Multiple strategy agents that can be configured to recommend stocks by matching them to a list of criteria given in a strategy file. This agent is analogous to an analyst who passes recommendations to a trader. 3.5.2 Information Agent The Information Agent acts as an aggregator for information collected from the environment. All agents can register for a piece of information using a data structure describing who needs the data and what the data should be. The Information Agent will be the manager of a group of agents which are called Information Collectors. Page 37
  42. 42. 3.5.3 Information Collectors The Information Collectors retrieve data from the external data sources such as third party data providers. Each Information Collector is responsible for gathering, monitoring and reporting one particular calculation from the external data. Via the Information Agent, the Information Collectors know which agents have requested information and report directly to them. 3.5.4 Portfolio Agent The Portfolio Agent is responsible for sending buy and sell orders to the Representation Agent. It evaluates whether stock buy recommendations from the Strategy Agents are suitable and is also responsible for maintaining the portfolio of currently owned stocks and maintaining several virtual portfolios for each of the strategies so that the various strategies can be monitored and assessed. The Portfolio Agent decides when to sell a stock by setting up a monitor for every stock in the portfolio or virtual portfolio. These monitors know which Strategy Agent the stock has been recommended by and as such know the exit strategy. This agent is analogous to the human trader, taking recommendations and information from outside sources, deciding who it trusts most to offer good recommendations and then sending off orders to be executed by a broker. 3.6 Information flow By using these ideas for the design, we will achieve an information flow similar to that existing in today’s human environment; see Figure 3. Page 38
  43. 43. Figure 4: Information flows into the Agent Brokerage through Information Collectors bringing it back from third party sources and delivering it to the various agents that requested it. 3.7 Interfacing with the stock market We propose that a stock market interface such as the ATS is used to run simple and light “representative” agents that take buy or sell orders from the Agent Brokerages. Our proposal is that only simple “execution only” agent’s trade on the ATS, implementing trade orders that are requested from the Agent Brokerages. This arrangement has a number of benefits: • Only very simple agents are run on ATS which should lead to good performance. Page 39
  44. 44. • All agents on the ATS are from trusted sources. • Management of agents is no longer an issue for the ATS operators. • Legal responsibilities are placed on the brokers, just like the present set-up. We envision that the form of these agents would be similar to that outlined in the Agent Shell by Johansson and Poijes (2003). The representative agents would behave in the same way as if they were getting orders from a human source, simply executing trades. This means that only many instances of a single configurable agent have to be written and ran on the ATS, vastly improving the security and reliability. From an analogy to the present human system, the representative agent could be seen as some kind of execution only broker whose sole job is to do as he is instructed. The brokerage itself is a collection of pre-written but configurable agents that each carry out a certain function of the brokerage. We have already introduced these other agents. The major benefit of setting up the brokerage in this manner is that no outside source gets to write executable code for the brokerage. Clients are only able to configure already existing “base” agents in a manner that provides full control over the agent’s actions, but protects the brokerage from malicious attacks or unwanted agent behaviour. Page 40
  45. 45. Chapter 4 - Design In this chapter we present our proposed design for an Agent Brokerage based on our observations and analysis covered in the previous chapters, where we looked into ways to achieve our design goal while fulfilling all of our stated requirements. We will present our final design in more detail and try to capture the interactions between objects in greater detail and try to focus on the interaction between objects on a practical level. We will not present a complete implementation of our design in this thesis; however we have implemented parts of the design for exploratory purposes, such as the messaging system. 4.1 Architectural design According to our design methodology discussed in section 1.5 we start by covering the architectural design and then move on to a more detailed design, although we will not cover implementation specific issues in depth. This chapter should be considered as a guideline for those who would like to implement an Agent Brokerage in the future. The architectural design covers issues such as which components the system includes and how they interact with one another 4.2 Architecture overview A schematic diagram for the design can be seen in Figure 4, below. Page 41
  46. 46. Figure 5: We can think of the concept of the brokerage as a number of layers. Each part runs on and communicates with the layers directly above and below as well as others in its own layer. Since our design is inspired by the way real stock traders and brokers work together, we will follow the outline of the way in which human actors interact. The system consists of the following components: 4.2.1 The Brokerage The Brokerage is the backbone of our design, it serves as an execution environment for our agents, and hence needs to supply and manage logging facilities, configuration management and the messaging system, allowing each of the components to interact with each other. Detailed designs for each of the components of Page 42
  47. 47. the brokerage can be obtained from the authors upon contacting them. 4.2.2 The Information Agent The Information Agent acts as an information broker: The Information Agent manages a collection of information collectors, objects which interface with information sources and process the information presented there. 4.2.3 The Portfolio Agent The Portfolio Agent manages the client portfolios and all associated data structures. It decides what stock to invest in based on the correlation between the portfolio contents, the money management strategy and the investment strategy. The money management strategy is configurable by the client in order to give some constraints to the portfolio agent’s powers. For example, a simple money management strategy might be to never have more than 80% of the total accounts cash invested at the same time and never to invest more than 25% of the account in any single financial sector. The portfolio agent also manages a collection of exit monitors for each of the portfolios, which indicate when to sell a holding from the portfolio. 4.2.4 The Strategy Agent The Strategy Agent is a component which monitors the state of the market and recommends to the Portfolio Agent which stock to purchase and at what price. To this means, the Strategy Agent is equipped with a strategy file describing an entry strategy which the agent should follow. The strategy agent can choose from a list of stocks that are on its “preference list”, a list that is customisable Page 43
  48. 48. in order to allow the client to choose which sectors he wishes to invest in. 4.2.5 The Representative Agent And finally, we have The Representative Agent running on the ATS. The representative agent has the role of an execution only brokerage. By running the representative on the ATS we have the possibilities of sending complex orders to the execution only brokerage and transferring the computation associated with them from the brokerage over to the ATS. Once the representative has carried out his task he will respond to the brokerage with either an acknowledgement if the task was successful or an error report if the task was not successful. The representative agent will not be covered in more detail in this thesis. 4.2.6 Component communication Communication in our proposed system is based on the principle of centralised planning. The Portfolio Agent acts as a coordination agent, receiving partial plans from other agents and deciding what actions to take (Wagner 2000). Furthermore, those plans received by the Portfolio Agent are based on information collected and communicated by the meta-agent Information Collector. To address this need of information exchange, we introduce a messaging system. The messaging systems provides a clear way to exchange information for the agents, using standardised representation formats such as the KQML Agent Communication Language (Labrou, Finin et al. 1999). We propose using two layers for the agent communication. The lower layer, layer 5 according to the ISO Open Systems Interconnection reference model [ISO 7498], handles all session control for the agents. This layer is needed to address the problem of authentication and Page 44
  49. 49. connection establishment, providing the agents with a seamless communication environment. This way we achieve the illusion of all the agents occupying the same space, and hence enabling all of them to communicate with each other efficiently. (Odell, Parunak et al. 2002) The presentation layer is then reserved for clear text communication using an Agent Communication Language (ACL). This design allows for encrypted communication using the session control layer. Performing encryption on a lower layer frees the agents from having to do any decryption. Figure 6: The protocol for agent communication, KQML, operates in the presentation layer of the ISO stack. 4.2.7 Client portfolios and strategy interactions The Brokerage will be serving many client accounts, analogous to the real world brokerages. Each account will have associated with it at least one portfolio and there will be a number of strategies associated with each portfolio. Since we have all the strategies running as agents in the system, each strategy agent can easily serve a number of portfolios. Each portfolio only has to add an exit monitor for each strategy to its existing collection of exit monitors. Page 45
  50. 50. Client Account Portfolio Strategy Figure 7: Each client has at least one portfolio, which in turn runs at least one strategy. The client table includes all information related to the client, and has at least one portfolio. Each portfolio then has at least one strategy, which can be shared with other portfolios. By sharing strategies we achieve optimisation in the strategy evaluation by reducing the number of repeated tasks. 4.2.8 Information tokens As previously discussed, human traders mix and match strategies and try to apply the best one for the given market conditions. Following this methodology, we designed a system which enables us to evaluate strategies with the help of information collectors. Each strategy is expressed as a series of logic expressions, if the expression holds then the associated action is carried out. To provide unlimited extensibility we introduce information tokens. Each logic expression checks whether a set of information tokens, hereafter referred to as tokens, meets the defined criteria. These tokens can be viewed as variables in a mathematical equation which get their value from the information collectors. A token may represent, for example, a moving average for the last X days or any user defined calculation, as long there is an information collector which corresponds to that token request. By allowing the user to introduce his own Information Collectors handling his calculations and information gathering, he can have Page 46
  51. 51. the Strategy Agent, and the exit monitor respond to whatever condition he wants. This design adheres to the requirement of running secure code on both the ATS and the brokerage since all the agent communication is sent in clear text through the application layer. Furthermore; we split the strategy into two parts: An entry part handled by the Strategy Agent and then the exit part handled by a set of exit monitors managed by the Portfolio Agent. This way the Strategy Agent registers for the necessary tokens with the Information Agent which informs, and starts up the necessary Information Collectors, and starts screening stocks included in the client’s preference list. When a purchase is made using a certain strategy the holding is added to the portfolio and an exit monitor is informed of the stock. The exit monitor receives his tokens from the Information Collectors and checks whether a sell condition is met for each of the stocks he is monitoring. Once the sell condition is met, he informs the Portfolio Agent which then in turn handles the actual sale of the stock. 4.2.9 Strategy selection technique Having outlined the details of our design in the previous subchapters we now outline our proposed method of strategy selection. The problem faced in this section is how the system will determine which strategy to invest with at any given point in time. To achieve this we re-introduce the virtual portfolios. It is our belief that the best way to keep track of the progress of a strategy is to record all its recommendations in a virtual-portfolio, a portfolio which does not have any real meaning for the client except for serving as a benchmarking tool. Normally, when each strategy finds a potentially profitable stock it recommends it to the appropriate Portfolio Agents, which are Page 47
  52. 52. those who are utilising that strategy. That portfolio will consult its money management strategy to check whether an unwanted holding distribution has been reached. If the money management strategy gives a green light for the investment, the investment order is forwarded to the execution only brokerage. Once the execution only brokerage has fulfilled the order, a share certificate is returned along with an acknowledgement of the purchase. The final step is that the portfolio is updated. Figure 8: Which investment strategy to use is decided by the money management strategy looking at each investment strategy’s scorecard and assessing its merits. In our case, we record each recommendation for each strategy into a virtual strategy portfolio. The worth of each of the virtual portfolios can then be calculated and compared on a scorecard object. The money management strategy then determines which strategies to use at any given time, picking it’s strategies from Page 48
  53. 53. those who have the highest score on the scorecard. The whole process can be visualised using a block diagram notation, as can be seen in Figure 8: 4.3 Meeting the requirements As we mentioned in section 2.5 there are a number of requirements which our design must meet. We have identified four important categories of requirements and in this section we explain how our proposed design meets those requirements. 4.3.1 Usability and humanity requirements An issue we identified was the need to verify the correct functionality of the entire brokerage. By introducing logging facilities into each of our agents we will be able to trace explicitly and implicitly the execution of each part of the code. The logging facilities should support the most commonly used levels of logging. The most common levels of logging are: • Debugging mode: The log file includes every action and decision made by the software entity being logged. By recording all actions and events, a detailed history of execution can be constructed, which in turn serves as a means of verifying correct functionality of the system. • Detailed Execution mode: The log file includes every business event encountered by the system, so that a semi detailed history of execution can be constructed. This logging mode serves as a means to analyse the interaction between software components as internal execution of the objects is omitted from the log file and instead the logging is focused on the interaction between objects. Page 49
  54. 54. • Normal Execution mode: The log file includes all exceptions and errors arising in the system during execution. This logging mode serves the purpose of capturing all abnormal activity and omitting all normal activity, as defined by the designer of the brokerage. This logging mode minimises the overhead of logging, freeing up more of the systems resources for the actual execution of the agents, and their decision making processes. Combining traditional logging facilities with logging at the portfolio level, by keeping a portfolio history database for each client, we are able to support the requirement that the system is deterministic. By this we mean that every action performed by the system is traceable and each effect can be linked with a cause. Another issue surfaced after we identified the need to be able to analyse the system’s actions. The system needs a way to efficiently fix its problems without having to bring the whole system down. We believe that by segmenting our system into software components such as a message router and separate agents, individual components can be duplicated, taken offline and fixed. Once the issue has been solved the duplicate can be replaced without affecting the operation of the entire system. This provides the operators of the brokerage with means to perform software updates and improvements without having to take the entire system off-line, given that the functionality of the updates has been verified in a controlled environment, such as a research lab. Furthermore by introducing modularity we are able to facilitate experimentation and research into our system. For example, by providing a strategy only with a virtual portfolio and disregarding Page 50
  55. 55. all recommendations from the strategy agent responsible for that strategy, the user will be able to experiment with new strategies without risking his investments. 4.3.2 Performance requirements After examining the abundance of software and software services available to the general public we are of the opinion that the delays introduced because of the brokerage’s communication with an execution only brokerage is not a limiting factor (TradeStation Group Inc 2004; Equis International 2005; eSignal 2005; Yahoo! 2005). However the question remains, is the delay introduced because of the communication between agents within a brokerage a limiting factor? Even with the most sophisticated high speed Ethernet connections, such as Giga-Bit Ethernet, the answer to the question remains elusive as it is solely implementation specific, and answering that question could be another thesis in itself. As we mentioned in section 2.5.2, it has been pointed out, by Boman and Lybäck that the core systems in the exchange are not allowed to become overloaded. It is our belief that this is not an issue in our design. One of our designs core ideas is to interact with the exchange through a buffer service, such as an execution only brokerage. There are a couple of points that need further elaboration. The original design by Boman and Lybäck was partially based on the principle of locating the ATS next to the core system of the exchange. This would allow for a zero time delay for the agents when interacting with the exchange. The zero delay aspect was one of the driving points of the design as it was seen as means to Page 51
  56. 56. encourage investors to use the service, hence allowing the investors to bypass the systematic delay introduced into the system because of the rule of fair dissemination of information. Fair dissemination of information is an agreement ensuring that all those taking part in the stock market have the possibilities of receiving information at the same time, hence eliminating the advantage some investors might have on other investors. Execution only brokerage services are managed by a third party organisation, such as those we have discussed in this thesis. The Agent Brokerage introduces therefore no added strain on the exchange and no code is actually run on or around the exchange. 4.3.3 Cultural and social requirements As we pointed out in section 2.5.3, it is also imperative that the functionality of the electronic exchange continues to be deterministic and that the functionality does not change in any way. By introducing the buffering layer of the execution only brokers and not running any code on the exchange itself our design does not affect the functionality of the exchange. This in turn preserves the trust of the public in the financial institutes, such as the execution brokerages and most importantly the exchange itself. What remains is to establish trust in the public towards an Agent Brokerage, automatically investing their money. We have already discussed means to establish trust in the brokerage in section 2.5.3. 4.3.4 Security requirements We touched on the need for code inspection when discussing security requirements in section 2.5.4. We revisit that discussion here to underline the way our design addresses the code Page 52
  57. 57. inspection issue. Code inspection is not an issue in our design as each agent behaves according to instructions stored in a configuration file. The configuration file includes information about which strategies the client wishes to run on the brokerages and how his portfolio should be managed. In more detail, we have introduced the notion of information token processing in the Strategy Agents. The information tokens are products of Information Collectors, which are programmed by a third party and therefore should require code verification. However since the information tokens are ACL formatted messages including data, such as Booleans, numbers or strings, to be processed at the Strategy Agent’s discretion, a global policy can be set regarding how the tokens can be processed and what kind of messages can be processed by the agent. Since the messaging system handles all communication for the agents, the encryption of the communication can be handled by the communication layer. Simply by introducing filters which pass the encrypted message to the socket our design mitigates the risk of a third party eavesdropping on the communication between different parts of the system. We have however not investigated specific encryption techniques as a part of this. Another important point to mention is that if the brokerage malfunctions and tries to execute illegal orders or bring down the exchange all such attempts will be filtered out by the execution only brokerages, who act like a buffer, adding an extra layer of security to the overall process and strengthening the public’s trust in the design. Page 53
  58. 58. Page 54
  59. 59. Chapter 5 - Concluding Remarks 5.1 Lessons learned The original concept behind this thesis was to expand on the work carried out by previous masters students designing trading agents for the ATS. As our Interactive Systems Engineering degree work at KTH was based upon user driven design, we decided that before looking at the purely technical requirements we should build a good understanding of our wider domain of work. We started by reading a collection of masters theses and development documents obtained from our supervisor on the subject and a few books on stock trading. We spent a month just getting to know what stock broking was really about, the players involved and how they worked. We soon saw that stock trading in general is more related to sociology than to mathematics. The success of our project was dependent on human factors rather than technical. This reinforced our belief that a user-based approach to the subject was more beneficial than a purely theoretical one. We decided to include a user-study as a part of our research phase, which already included reading theoretical books and papers on the subject. We approached a few financial institutions and either met with members of their staff to speak to them and ask them questions regarding their work, or sent out a number of questionnaires. It came apparent that a quick and dirty user study would only probe the surface of the human factor so we added a book on a rather ambitious ethnographic research carried out by a Swedish PhD student to our list of reading material (Hasselström, 2003). Once we were acquainted with how real life stock brokers and traders go about their business, we decided to get better Page 55
  60. 60. acquainted with the ATS and the code developed for it by the other masters students. We downloaded the ATS, version 1.0 and had a look at the code. Analysing the code and getting the ATS up and running with a simple home made agent took about four days due to the code modifications needed, and getting the agent package by Jesper and Johansson running on the ATS took a further two days due to lack of documentation regarding the execution of agents. We spent a few weeks learning about trading strategies, what they were, how they were represented in other products and what ways we could potentially express them in our program. We came up with a method, grounded in logic expressions, of expressing complex strategies in a simple way. At this point we started to design an agent which could run on the ATS. We spent about two to three weeks drafting architecture for the agent and two weeks to program a prototype. As we were putting the finishing touch on the agent, ready to start benchmarking the agent we noticed that our design was not suitable due to conflicting requirements regarding security and legal aspects. We revisited an earlier stage in our design phase, the requirement analysis and decided to spend a week on capturing all the non-functional requirements we could think of and capture from the various written sources we had. The outcome of this work was that the focus of the design changed to concentrating more upon an Agent Brokerage which is a supportive execution environment for trading agents. We continued to develop our new idea until we were confident that our design met every requirement noted in our requirement analysis papers. We further spent a week on programming a prototype for the brokerage but it soon came apparent that programming a fully functional brokerage would exceed the timeframe we had for our Page 56
  61. 61. thesis which is 20 weeks of work per person. We decided instead of programming an experimental proof-of-concept Agent Brokerage to develop our idea and complete a detailed design up to the level of implementation. Thus anyone who is interested in developing the idea into a product has a solid base to build on. The danger of following a software development model such as the waterfall model is that the developer gets locked in to a set idea and concentrates purely on the technical problems that need to be solved. We could have realistically implemented a trader that was able to choose between multiple strategies and was capable of running on the ATS, the original plan for the thesis research. However, this would be a purely academic exercise as we have discovered that due to the complex non-functional requirements of the financial industry, it would not be viable to use this type of agent in a real world scenario. By taking a human-centred focus on the design we have highlighted many of the requirements and difficulties faced when designing new technology for the financial industry. We have also proposed a possible architecture that we believe would support systematic trading through the use of software agents. 5.2 Conclusion We have developed and presented an Agent Brokerage. The Agent Brokerage was the result of our attempt to design a fully autonomous trading agent running on the ATS developed at SICS. During our design work we noticed that running our design directly on the ATS violated some of the requirements stated by the inventors of the ATS during its development. We have presented our design as a guideline for those who wish to implement such an agent platform. Page 57
  62. 62. To be able to consider if we have properly met our initial objectives we can revisit our original goal statements from 1.3: “Our goal with this project is to build an understanding of the requirements and difficulties associated with developing complex agents which can trade alongside their human counterparts on the real stock market” To reach this goal, we performed a number of background researches, namely the “quick and dirty” ethnography research, we sent out a number of questionnaires to banks in Iceland and we did extensive reading on the subjects of stock trading and agent technology. This then enabled us to write a full requirements specification document (see Appendix A). “We will seek to accomplish this by attempting to design an agent capable of investing using an arsenal of different investment strategies“ After having carried out the aforementioned research we came to the conclusion that the single agent approach was not feasible given the complexity of the structure and environment of stock trading. To reach this goal we instead proposed a design for an Agent Brokerage, a concept invented by us to support multi strategy agents trading on the real stock market. “By assessing the financial industry standards, conventions and legal requirements we will consider the barriers to the practical use of agents in the real world and propose robust and secure solutions to overcome these barriers” Page 58
  63. 63. By analysing the requirements captured in the previous stage we were able to identify over 75 requirements which would have to be met if any trading platform is to be successful in real life. So we can clearly state that we have reached all aspects of the goals set in the beginning of our work. 5.3 Future work While we have suggested a possible theoretical solution to the issue of running trading agents, there exist many avenues down which our work could be extended. Three suggested further areas of study are included here. 5.3.1 Designing a notification service As mentioned within the thesis, trust plays a large part in the acceptance of any system which involves humans and some kind of trade or exchange of money. It is important for humans to feel in control of what is happening within the Agent Brokerage. The principle used in our design is that of having autonomous agents handle all trades and that takes a high degree of decision making out of the hands of the human. We envisage that by having the agents within the brokerage report important information and facts to the humans, it will increase the trust level between humans and trading agents. Any investigation into a notification service would need to look at factors such as the interaction device for the human and the level of detail of information sent. 5.3.2 Visualisation methods for strategies The Agent Brokerage has the potential to allow the average private investor a new window onto the stock market. The biggest stumbling block for the private investor could be the Page 59
  64. 64. implementation of strategies, especially if the method of strategy representation is complex and requires a strong degree of computer programming skills. We have already suggested a Boolean based method to represent relatively complex strategies, but suggest that it may be possible to use information visualisation techniques in order to make the representation of strategies more easily understandable and achievable. We do not wish to influence any further study by making a suggestion in this thesis on how this may be achieved. 5.3.3 Implementation of the design In order to evaluate the effectiveness of our design, the detailed design on paper should be implemented as an actual software system capable of running on a stand alone server. This would allow test agents to be written and executed and would expose many of the technical pitfalls associated with implementing a complex design. As previously mentioned, the authors have carried out work on a detailed design for the Agent Brokerage including the architecture already described and additionally a proposed messaging and agent communication system, logging system, collaboration component and the interaction sequences for each process involved in the Agent Brokerage. The authors would be delighted to hear all comments on our work and from whoever would be interested in taking the concept of the Agent Brokerage forward. We can be contacted through the details shown at the ATS web- page, Page 60
  65. 65. References Allgood, B. (2001). "Internet-Based Share Dealing In the new Global Marketplace." Journal of Global Information Management 9(1): 11-15. Almberg, W.-S. (2002). Improved Pricing on the Stock Market with Trading Agents. Department of Computer and Systems Sciences. Stockholm, Stockholm University / The Royal Institute of Technology: 26. Bennett, S., S. McRobb, et al. (2002). Object-oriented systems analysis and design using UML. London, McGraw-Hill. Boman, M. (2004). Accessible Autonomous Software. Vinnova final project report, SICS, Kista, Sweden. Boman, M. and D. Lybäck (2002). Agent Trade Servers in Financial Exchange Systems. ACM Transactions on Internet Technology 4(3): 329-339. Boman, M. and A. Sandin (2005). Implementing an Agent Trade Server. Decision Support Systems, in press. Bonello, F. (2005). Stock Exchange. Encarta Encyclopedia. Brash, D., F. Björck, et al. (2005). Master Thesis Information. D. Brash, Department of Computer and Systems Sciences at KTH/SU. Craver, S. (2005). The underhanded C contest., Binghampton University. Edwards, R. D., J. Magee, et al. (2001). Technical analysis of stock trends. Boca Raton, FL New York, St. Lucie Press, AMACOM. Equis International (2005). Metastock. Salt Lake City: Stock trading software. eSignal (2005). eSignal. Page 61