Click here to load reader

Agent Brokerage:

  • View

  • Download

Embed Size (px)

Text of Agent Brokerage:

  • 1.Agent BrokerageA human-centred approach to automatedstock trading Jn Grtar GujnssonGary Alistair MacRitchieDepartment of Computer and Systems Sciences Stockholm University / Royal Institute of TechnologyNovember 2005 The following thesis equates to 20 weeks of full work for each author

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. 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 Hagstrmer & Qviberg whose time spent assisting our research phase was much appreciated and proved invaluable. And finally to Elsabet and Maria for putting up with us spending too much time with our heads in books about the stock market.Jon and Garyiv 4. Table of ContentsCHAPTER 1 - INTRODUCTION 1 1.1Early efforts towards systematic trading11.1.1 The approach of the academics 21.1.2 The approach of the industry31.2Research Question 41.2.1 Scope of the work 41.2.2 Formulation of a general research question51.2.3 Related work61.2.4 Feasibility of the solution 71.3 Goal 81.4 Purpose81.5Method91.5.1 Research phase91.5.2 Design phase 101.6 Limitations 10 CHAPTER 2 - RESEARCH AND REQUIREMENTS 13 2.1The Social Environment 132.1.1 Clients132.1.2 Analysts 142.1.3 Traders152.1.4 Brokers152.2 Hierarchy and information flow162.3The technical environment172.3.1 Analyst information providers172.3.2 Online Brokers 182.3.3 Trading Platforms182.3.4 Existing exchange software 202.3.5 The Agent Trade Server 212.4Complex trading agents 232.4.1 Many strategies, one active232.4.2 Many strategies, many active 242.5Reflections on requirements252.5.1 Usability and humanity requirements252.5.2 Performance requirements 262.5.3 Cultural and social requirements 282.5.4 Security requirements292.6Reflections on trading strategies312.6.1 Strategy Representation31 vi 5. CHAPTER 3 -THE BROKERAGE CONCEPT 35 3.1Structural design 353.2Internal design 353.3Work segmentation 363.4Scalability 363.5Defining roles373.5.1 Strategy Agent373.5.2 Information Agent 373.5.3 Information Collectors383.5.4 Portfolio Agent 383.6Information flow383.7Interfacing with the stock market 39 CHAPTER 4 -DESIGN41 4.1Architectural design414.2Architecture overview 414.2.1 The Brokerage 424.2.2 The Information Agent 434.2.3 The Portfolio Agent 434.2.4 The Strategy Agent434.2.5 The Representative Agent444.2.6 Component communication 444.2.7 Client portfolios and strategy interactions 454.2.8 Information tokens464.2.9 Strategy selection technique474.3Meeting the requirements494.3.1 Usability and humanity requirements 494.3.2 Performance requirements514.3.3 Cultural and social requirements524.3.4 Security requirements 52 CHAPTER 5 -CONCLUDING REMARKS55 5.1Lessons learned 555.2Conclusion575.3Future work 595.3.1 Designing a notification service595.3.2 Visualisation methods for strategies595.3.3 Implementation of the design60 APPENDIX A - REQUIREMENTS SPECIFICATION I vii 6. Chapter 1 - IntroductionA stock exchange provides facilities for the trading of securitiesand other financial instruments on a stock market. Members of theexchange are known as Stock Brokers and they work to matchbuyers with sellers so that trading transactions can take place. Onmodern stock exchanges, most stock trading is completed by theexchange software matching buy and sell orders that are sent to itby brokers. The brokers are following the instructions of traders;institutional or private investors, who employ varied strategies andmethodologies in order to decide what stocks they should buy orsell. An emerging development in this relationship betweentraders, brokers and the exchange is the possible introduction of amethod to allow software agents (Kagel and Roth 1995; Weiss1999) to trade directly on the exchange. In this first section of ourthesis, we will show why there is a need for such a new service,discuss the approach currently taken by industry, introduce theprototype agent trade server (ATS) and discuss how a tradingagent can be designed to operate on this server. 1.1 Early efforts towards systematic tradingMany traders see investing in the stock market as being acompetition between them and the market, hence the term tobeat the market. In order to beat the market, investors havedevised a multitude of means and strategies in order to regulatetheir activities in the market place and protect themselves fromwhat are seen as the disrupting emotions of greed and fear(Hasselstrm 2003). Historical methods and strategies such asthose developed by Benjamin Graham, called value investing, asearly as 1928, (Vanstone, Finnie et al. 2004) or Charles H. Dows(Edwards, Magee et al. 2001) introduction of technical analysis by Page 1 7. creating indices of leading shares as indicators of future marketbehaviour, have been developed into an array of methods, tacticsand practices, which modern day investors have at their disposal.Immense amounts of work have been, and still are, spent towardscreating new and innovative methods and theories to outsmart thecompetition, to gain a competitive edge. The financial industry hasbeen relying more and more on the innovation and developmentwithin the IT industry and academia (ibid.). 1.1.1 The approach of the academicsAcademia has been industrious in producing models of thefinancial market (Kagel and Roth 1995). One of the first attemptsto model economical environments, a field within economicscalled experimental economics, explores economical theories andparadoxes using experimental setups. The method dates as farback as the 17th century and from it classic problems such as theprisoners dilemma, the free-rider problem and more originate.Experimental economics have been used to test the prediction oftheories, serving as a dialogue between experimenters andtheorists and connecting the ideal world to the real world (Kageland Roth 1995).Another field of academia, computational economics, is mainlyinterested in the behaviour of markets and many computationalmodels have evolved to simulate trade on a double auctionmarket. One of the tools academia has used to implement thesemodels is the agent oriented approach. Each investor isrepresented with a surrogate in a multi agent system whichbehaves according to the computational models prescription.These models are either homogeneous (Homme 2005) where theinteractions of a few types of traders are being researched, orPage 2 8. mixed, where the market consists of various types of tradersutilizing various strategies to benefit from the behaviour of stockprices (LeBaron 2005). For example, artificial neural networkshave been used successfully by a number of researchers toclassify different types of stock, allowing them to identifyundervalued stocks (Kendall and Su 2003; Vanstone, Finnie et al.2004). Genetic algorithms have also been used to breed artificialinvestors, in an attempt to weed out the unsuccessful and create abreed of highly successful investors, or just strategies for use byreal life traders to invest with (LeBaron 1998; Kendall and Su2003). The agent metaphor has been used with success to createautonomous software to trade stocks using simple heuristics, bothon artificial and real life markets (Sherstov and Stone 2004;Hilmersson 2005). Summarizing all the work previously done inacademia is a book in itself and will not be covered in thisintroductory chapter in detail.Besides proving to be an immensely useful tool to analyze marketbehaviour, the work done within academia has resulted inresearchers gaining insight into the inner workings of trading, andthe creation of Artificial Stock Markets, such as the Santa Feartificial stock market, and the trading agent competition (TAC)(Boman 2004), where agents can compete against each other inbusiness. Recent times have seen the development of manytechnologies to attempt to allow users to find information, createnew strategies, run complex strategies and automate the tradingprocess using the existing stock market. 1.1.2 The approach of the industryInformation technology has provided a recent revolution in the wayin which non-institutional investors gain access to the stock Page 3 9. market and surrounding information. The rapid growth of online,execution-only brokers has changed the way people are buyingstocks, not only in the way a transaction is completed, but also inthe method with which a stock is chosen and investment decisionsare made. These include various Internet-based informationproviders, stock screeners, online brokers and sophisticatedtrading platforms that shall be discussed later which allow thetesting and implementation of individual trading strategies.The rise of the online broker has not only come about due to thelower costs incurred, but also due to the fact of the increased easewith which a trade is placed. Investors can monitor their ownportfolio in real time (with more expensive accounts) or with afifteen minute delay for free. 1.2 Research QuestionWe will examine and research what conditions must be met inorder for an autonomous agent to trade stocks on the real market.We will also try to capture those conditions in a design fit to tradestocks using multiple complex strategies. Hence our thesis type isof the artefact development type overlapping the areas ofimprovement of artefact types and need for understanding, cf.(Brash, Bjrck et al. 2005). In the following subsections weformulate our general research question, setting the scope for ourwork. 1.2.1 Scope of the workMany stock traders and brokers today spend a lot of time lookingat numbers on a computer screen monitoring their investments.Their efforts are mainly spent on responding to marketfluctuations, trying to make money on these changes. Very few of Page 4 10. todays stock brokers actually make sense of all the abundance ofinformation they are presented with every day(Hasselstrm2003). The fast response time of the market and ever growingcomplexity of the exchange leave little time for the professionalstock trader to think about tactics and evaluation of actions.According to the websites of the London stock exchange (LSE2005) and the New York stock exchange (NYSE 2005), thenumber of listed companies is increasing by the week and newtechnological advances are made each year, resulting in fasterandwider dissemination of information. Furthermore, theincreased complexity and speed are straining those members ofthe public who want to monitor and do business on the stockmarket. It is our belief that the use of agents, acting on the behalfof investors, can address the complexity-and-speed issues ofmodern-day trading. We recognise that stock trading is now aglobal market and we will hence not be limiting ourselves to anylocal perspective. 1.2.2 Formulation of a general research questionWe will concentrate our work on the issue of adaptability and theenvironment of stock trading agents. With adaptability we refer tothe agents way of determining what action to take on an abstractlevel, specifically deciding which trading strategy to implement atany 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 designedand implemented for the stock market? Furthermore what conditions must that agent meet to be considered a legitimate trader in real life? Page 5 11. Hence, our work will consist of researching the currentenvironment of stock trading, what properties a stock tradingagent has to have to meet the requirements of real life, and whatenvironment such an agent must exist in. 1.2.3 Related workReal life stock traders have been mixing trading strategiestogether for over one hundred years. Agents for trading stocks onreal life stock markets have not yet, to our knowledge, beendesigned to select appropriate strategies, from an arsenal oftrading strategies, to maximize their effectiveness. In the comingchapters we will discuss the Agent Trade Server (ATS), aprototype platform which was designed to allow software agents totrade on the Stockholm stock exchange (Boman and Sandin2005). For an agent running on the ATS, using only one strategyhas proved problematic as shown in a previous masters thesis byDaniel Hilmersson (2005). In Hilmerssons case the strategychosen was not appropriate for specific states of the market. It isour belief that giving the agent the ability to adapt strategy choicedependent on market conditions would address this problem.Research into the field of designing agents which can employ avariety of strategies has been done before (Kendall and Su 2003;Homme 2005; LeBaron 2005). In those cases, when implementingthe adaptation of the choice of strategies, artificial neural networks(ANN) were readily employed. For example, Kendall and Sudesigned a stock market model, with ANN-based agents, where anumber of agents developed strategies. They also showed thenecessity of social learning to improve the overall efficiency.There is however, one large drawback to using artificial neuralnetworks; there is no easily understandable way to analyze thenetworks knowledge after it has been trained. The networks Page 6 12. synapses strengths are usually represented as a set of matrices ofsigned numbers called weights. A matrix of numbers cannotconvey a methodology, not even a strategy such as buy low andsell high. Another approach to deploying multiple strategies doesnot involve ANNs. This approach relies on conventionalprogramming methods. For example, this approach has beentaken in trading platform software such as TradeStation, usingscripts and specialized command languages (TradeStation GroupInc 2004).We will address a problem not directly targeted before. To ourknowledge, the work done so far has been focused towards theimplementation, discovery or evolutionof specific tradingstrategies. Since previous work has shown that there might bebenefits of having a trading agent implementing different tradingstrategies based on the state of the market, we will try to devise amethodology to address this problem. This has not beenresearched in conjunction with trading agents before to our bestknowledge. 1.2.4 Feasibility of the solutionWe will analyze the requirements put forth by the industry which areal life stock trading agent must meet. Our main effort willhowever be spent towards creating a methodology for runningcomplex trading agents in todays technical environment andcreating a design which meets both our functional requirementsand the non-functional requirements imposed by the industry. Wewill build on the work done by Hilmersson (2004) and Johanssonet al. (2003), the analysis performed by Boman and Lybck (2002)along with various other sources.Page 7 13. 1.3 GoalOur goal with this project is to build an understanding of therequirements and difficulties associated with developing complexagents which can trade alongside their human counterparts on thereal stock market. We will seek to accomplish this by attempting todesign an agent capable of investing using an arsenal of differentinvestment strategies. By assessing the financial industrystandards, conventions and legal requirements we will considerthe barriers to the practical use of agents in the real world andpropose robust and secure solutions to overcome these barriers. 1.4 PurposeBy allowing the programmed strategies to be complex in nature ifdesired, we will show that agents allow for a new channel ofaccess to investing on the stock-market. Such software couldenable the professional stock trader to spend more time thinkingabout a course of action for managing and planning the trading ofstocks, instead of spending efforts towards monitoring a list oforders on his computer screen.Allowing the home investor to create his, or her, own strategiesand leave the implementation of these to the agents will alsoimprove the publics accessibility to the market, levelling the edgethat the large financial institutes have on the public. Automatingthe decision of which strategy to use to trade stocks can alsoempower the average day user to develop strategies with adegree of security, since the best strategy is used at any giventime. The client can rest assured that his trader is always investingusing its optimal strategy, without him having to monitor hisinvestment constantly.Page 8 14. 1.5 MethodThis section describes the methodology we will use to design ourtrading agent. We will base our work in part on softwareengineering lifecycle models, such as the waterfall model and thespiral model but only to a certain extent. The work will be split andcarried out in two main phases: the research phase and thedesign phase. We will continue our research throughout theproject, addressing design issues as they arise. The model thatwe have chosen is an iterative version of the waterfall model(Bennett, McRobb et al. 2002). The reason behind our choice ofthe iterative waterfall method is two pronged. On one hand weboth have good knowledge of this method and have used it in ourprevious projects, on the other hand we felt that an easilyunderstandable and well defined model would bring structure toour otherwise unstructured research. Following is a description ofeach phase. 1.5.1 Research phaseThe research phase consists of two parts, literature research anda quick and dirty ethnography research. The two parts are carriedout in parallel and will be continued throughout the duration of thethesis work.The literature research phase consists of reading and reviewingliterature related to the field. The topics of the literature cover allfields related to our thesis, such as technical and fundamentalanalysis for stock trading, stock trading practices, strategies forstock trading, agent design and programming, anthropologyresearch and software engineering.Page 9 15. Quick and dirty ethnographic research is used to gain knowledgeof the environment and practices of stock trading. It consists of aseries of short interviews and observations, even a questionnaire,deploying a semi-structured interview technique to capture asmuch peripheral information as possible. The contents of thequestionnaire sent out to slandsbanki and modified version usedto interview Ludvig Sandhagen at Hagstrmer & Qvibergconsisted of questions regarding their disposition to their work andworkplace, their day to day routines, their job definition, theiractual responsibilities at work and their experience and knowledgeof computer systems. By capturing this peripheral information wediscovered what we could not read in books, but is commonknowledge in the field. This builds up our overall understandingand enables our design to conform better to the requirements ofreal life. 1.5.2 Design phaseWhen all the basic information has been collected and analyzedwe will follow a software design methodology. Since softwareagent design is a relatively new field, we will mainly adhere to theObject Oriented design methodology (Bennett, McRobb et al.2002), but modify it, were we find necessary. 1.6 LimitationsThe focus of our thesis will be the development of agent softwareto choose which strategy to use while investing money, althoughthese strategies are based on specifics of stock trading, we willnot go into specific strategies in any detail. Further, we will onlyconsider the trading of company stock and by trading we refer tothe process of first buying then selling (also known as goinglong).Page 10 16. We will design an environment for the stock trading agents 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. Chapter 2 - Research and requirementsThe existing methods of trading stocks have a well defined socialstructure. This allows us to look at how a trade is executedthrough the main players involved in the market. These are theclient, the trader, the analyst, the broker and the investmenthouses. 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 betweenthese actors and varying shifts in responsibility depending on thetask being undertaken. 2.1 The Social EnvironmentFollowing is a discussion of the social environment of stocktrading. 2.1.1 ClientsThere are many entities that could be referred to as clients in theworld of stock investment. These range from private individualswho choose their own stocks and trade directly with a broker inorder to buy or sell, to large investment banks putting forwardmoney to be invested by a team of professionals. When regardingPage 13 18. the individual as the client, investing a sum of money with aninstitutional investment house, perhaps as a part of a mutual fundor an investment product such as a private pension, we can seethe client as filling two roles. Firstly, the clients are the providers offunds to be risked upon the stock market in the hope of increasedreturns. They provide the fuel that drives the engine of the stockmarket and as such when acting on mass are a very powerfulgroup. Secondly, the clients are courted by the investment housesand suppliers of investment products by using a multitude ofmarketing techniques. Probably the most effective of thesetechniques is the ability to show potential clients good past returnsin order to tempt them to invest. This puts pressure on investmenthouse managers to get the best returns and this pressure ispassed down to the traders, often with severe consequences forfailure and high rewards for success (Hasselstrm 2003). Theindividual client in these scenarios may well be the catalyst for thewhole process, but is however likely to be the least knowledgeableabout the mechanisms of the market and the implications ofdifferent events on the market. 2.1.2 AnalystsAnalysts are employed either internally by investment houses orby specialist companies who sell their results as services toinvestment houses. It is the analysts job to perform variousexaminations of a stocks potential and to report this back to atrader. If a trader makes good investments from recommendationsfrom a particular analyst, he is more likely to trust him and use himin the future, which is good for the analysts career. Analysts tendto see the traders as gamblers while they think of themselvesmore as scientists (ibid.). Page 14 19. 2.1.3 TradersThe traders have a two way relationship with the managers of theinvestment houses. These managers decide which traders torecruit and which traders to promote or fire, but the careers andbusinesses of the managers also depend on the success of thetraders. The professional traders themselves tend to know onlyabout 15 or 20 companies in great detail and continually monitorthese companies stocks for investment opportunities, perhapstrading the same stock several times a day (Schwager 2001). Thetraders make the decision about what stocks to buy and sell andwhen, but they have to use an intermediary called a broker for theexecution of the trade on the stock exchange. 2.1.4 BrokersThe brokers earn commission for every trade whether it is aprofitable one or not. As such, it is in the brokers interest to tryand ensure that a trader uses him for each trade and to achievethis brokers work hard to build a bond between themselves andtraders. They do this through trying to pass traders profitableinformation and also through a more social scene of entertainmentand expense accounts. Traders too, work at building a bondbetween brokers that they trust in order to be in line when thebroker gets some useful information. However, traders tend tohold brokers in quite low regard and consider them as being oflower status than themselves (Hasselstrm 2003).Information thus tends to flow towards the trader as he makes thedecisions on where the money is spent. Analysts take theirinformation from financial reports, stock price trends, etc andconstruct recommendations for traders to use. Brokers useknowledge of trades that are going through, rumours and word ofPage 15 20. mouth in order to make their recommendations to the traders. Thetraders have to evaluate all the time the quality of the informationthey receive and learn which sources to trust and which to ignore.Once the trades have been placed, the financial house managersevaluate the traders performance and decide which ones getbigger portfolios to manage and which ones are no longeremployed. Generally after fixed periods of time, the clients areinformed of their investments performance. They then evaluatethis information and decide whether to invest more money orwithdraw their funds and invest elsewhere. 2.2 Hierarchy and information flowWe can present the institutional hierarchy and the flow ofinformation using a rather simplistic schematic diagram, seeFigure 2.Figure 2: Information flows between the actors in the stock market, with ahierarchy of decision making.Page 16 21. The brokers interact with the exchange placing sell and buyorders. They receive their directions from the traders, who areacting on behalf of the clients. We can also visualize the flow ofinformation, starting at the brokerage and propagating outwardstoward the client. The information usually propagates through thelayers of the brokers and the traders at the same instance, but theclient only receives information a while after the events happenedon the stock market. However using todays technologicalenvironment, information can be retrieved from the stock marketmuch faster than it propagates through the different layers ofbrokers, traders and clients. 2.3 The technical environmentIn the following subsections we will have a look at the technicalenvironment of todays stock trading. 2.3.1 Analyst information providersPrior to the widespread acceptance of the Internet, the individualinvestor would have to rely upon sources such as newspapers,end of year reports and advice from stockbrokers whenresearching a share. Now, the private investor can access a rangeof continually updated financial information from his or her desktopfor free or low cost subscriptions (Allgood 2001). Web portals suchas Yahoo ( and more specialist sites suchas The Motley Fool ( offer huge amounts ofhistorical and 15 minute delayed market data, charts, news,broker recommendations, trends, technical analysis, incomestatements, 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 toPage 17 22. narrow down the thousands of stocks that exist on a market tothosethat match theindividuals basic prerequisites( allow theinvestor to complete at the touch of a button a previouslyunfeasible research task (by the time the individual hadresearched through thousands of stocks some data may havechanged, rendering his research erroneous). The constant supplyof high quality financial information available to all those with amodem has in many ways levelled the playing field betweenindividual and institutional investors and has certainly fuelled abelief in many individual investors that they no longer have to relyon brokers or brokerage firms to decide about their markettransactions. 2.3.2 Online BrokersAccording to an article in the Economist magazine (TheEconomist Newspaper Limited 2000), in the mid 1990s clients offull-service brokers were regularly paying between $100 to $400USD per trade. In May of 2000, clients of the major off and on-linebroker Charles Schwab could place a trade for $14.95 whileaccessing all the previously mentioned information for free. Theability of an online broker to cope with fluctuations of demand anddeliver instant price quotes for thousands of stocks across manymarkets means that online stock broking provides more than justan automation of the telephone based execution services (Allgood2001), but actually hides the brokerage stage from the investorand allows him to feel he is dealing with the market directly. 2.3.3 Trading PlatformsA step on from the online brokerage and research is theemergence of trading platforms for both institutional and individualPage 18 23. investors. An example of such a trading platform for institutional investors is SunGards 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. TradeStation is similar in many ways to eSignal and Metastockallowing investors to develop and back test strategies on historicaldata. TradeStation allows users to write their own strategies usinga proprietary pseudo-code, allowing simple or extremely complextechnical strategies to be tested. One of the most interestingaspects of TradeStation is that trading can be set to be fullyautomated. TradeStation monitors the market in real time, tick bytick, and once market opportunities are identified that match theinvestors strategy; it can execute the trade without any interactionfrom a human. The buy/sell orders are sent automatically by theprogram to an online broker who completes the trade on the realmarket. The concept of TradeStation is very similar to that ofagent trading using the prototype ATS. After the strategy is set,the program takes full responsibility of what stocks to buy or selland when to make the trade. As far as the user is concerned, theinterface between the trading platform and the actual market isseamless. 2.3.4 Existing exchange softwareAt the heart of modern stock exchanges lies complex softwaresystems matching buyers and sellers and distributing informationon already executed trades known as trading systems (OMX2005). In order to be able to trade on an OMX exchange, thebroker needs a member SAXESS trade application. Eachapplication connects to a SAXESS trade server which in turn isconnected to the core. This all happens using the XTP protocol,which stands for open eXchange Transaction Protocol. The XTPis an OSI layer 7 protocol. In this case, the core is a deterministicprogram written in C, which matches stacks of buy and sell bidsfrom investors. These systems are utilised by brokers who areeither placing trades on their own behalf, or on behalf of tradersPage 20 25. who pay them a commission to do so. A schematic description ofthe 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 alreadyexecuted trades known as trading systems. 2.3.5 The Agent Trade ServerCombining both the work done in academia and the industry, anAgent Trade Server (ATS) has been developed and implemented Page 21 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. Hilmerssons 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 onPage 22 27. information one cannot mine from stock prices alone. More agentvariants are needed, in order to display the flexibility andaccessibility of the ATS (Hilmersson 2005), (Jesper Johansson2003). 2.4 Complex trading agentsFor his thesis, Hilmerson programmed a simple day trader runningon the ATS. One of his findings was that the strategy he useddemonstrated varying efficiency depending on the state of themarket. He suggested the development of an agent that can rundifferent strategies and invest using the best one. This was thestarting point for this thesis; we wanted to design an agent whichhas many strategies at its disposal and would invest using thestrategy which yields the best return at any given point in time.There are different ways of achieving the goal of trading withmultiple strategies. 2.4.1 Many strategies, one activeThe first approach is to create an agent which has a set ofstrategies and a guideline when to use each strategy. In this casethe agent will follow instructions on what strategy to invest with atany point in time. The benefits of this approach are that the designof the agent is very simple, concise and neat. Strategies are activebased on market indicators or other predetermined yardsticksindicating which strategy to use. This way has the drawback ofbeing ill adaptable, or not at all. If any of the premises the masterstrategy uses change during the timeframe of the program, theappropriateness of the strategies changes. For example, if thefinancial landscape changes in a way that is unforeseen theyardstick used to select the best strategy is useless. This isespecially true when many people are using the same strategy,Page 23 28. since the inefficiency in the market exploited by the strategy getsover exploited. In that case the strategy loses its edge and maynot be the most appropriate one. 2.4.2 Many strategies, many activeThis leads us to the second way of trading using multiplestrategies. As we have noted before, the selection criteria shouldbe based on which strategy is performing best at any instance intime. To be able to determine the strategy which is performingbest at any instance in time we must have some means ofevaluating their return in real time. However, evaluating theirreturn in real time implies that we need to have each of thestrategies running concurrently; measuring and comparing theirperformance in real time. These kinds of tasks, repetitive numbercrunching, are exactly what a computer is best at. Therefore, wesuggest that instead of running a single threaded agent, a multithreaded agent is needed to achieve these means. The agentwould then have a thread running for each of the strategies, and anumber of control threads evaluating the performance of thestrategies and doing the actual investing. This method addressesthe problems associated with using a static yardstick to determinewhat strategy to run. By comparing for example, portfolios foreach of the strategies, we have a dynamic, adaptable yardstickwhich will always yield the strategy which is performing best atany point in time.This idea has some implications for the ATS. As Hilmersson workpointed out, an ATS can run day trading agents which each havea single thread of execution. When we add strategies to each ofthe agents running on the ATS the number of threads managed bythe ATS increases considerably. As each agent consumes morePage 24 29. resources, the ATS is able to support fewer agents than beforewith fixed resources. If the number of agents running on the ATSshould stay the same, the resources should be increasedconsiderably, which in turn means more expenses for whomeveris responsible for managing the ATS.As our research and requirement analysis progressed we saw thatthis approach is a simplistic one, there are number of functionalrequirements that we identified which imply that the softwareshould have more sophisticated facilities for strategy selection,portfolio management and information aggregation, in addition tothe evident need for the user to be able to easily express thestrategies he wants to use. 2.5 Reflections on requirementsRequirement identification and specification are a vital part of anydesign process. As we worked towards the completion of our taskwe used a requirement specification template created by theAtlantic systems guild, called Volare (Robertson 2004). Theresults of the requirement specification can be seen in AppendixA. We captured the requirements by mining them from the datacollected by interviews, quick and dirty ethnographic surveys andnumerous pieces of literature research, see list of references.Following is a discussion on what we found during ourrequirement specification steps. We examine different types ofrequirements and analyse their implication on our design. 2.5.1 Usability and humanity requirementsCorrect functionality of a system is always an important issue,especially when the stakes are as high as they are in the financialindustry. It is imperative that the system provides some way toPage 25 30. analyse its actions. It is not important at this stage what ways areprovided as long as they can be used efficiently to correct thesystem and fix errors or bugs.Another issue surfaces after we identify the need to be able toanalyse the systems actions. The system needs a way toefficiently fix its problems without having to bring the whole systemdown. For example, if there is a small part of the system needingchanges, upgrades or bug fixes it is unacceptable that the wholesystem has to be stopped and started again once the work hasbeen carried out. An implicit requirement is that the system hasclear and well defined boundaries between its subsystems thathave different responsibilities.The system must facilitate experimentation and research. Tradingplatforms in general should provide these functionalities both atthe level we mentioned earlier, that the user should be able to seewhat the system is doing and analyse its actions, and also allowthe user to experiment with new strategies and different ways ofprocessing information. 2.5.2 Performance requirementsSystems running in the financial market are hard real timesystems. That is, there cannot be any delays when sendingmessages and orders back and forth. This real time propagationof information requires the system to be flexible to changes in itsenvironment, both software changes and hardware changes.Routers, hard drives, and even software components might faildue to error correction, updates or bugs. In addition, being ahard real time system interacting with the stock market, thesystem must be available and running at all times appropriate forPage 26 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 Lybck 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 Lybck 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 clients code is allowed to interfere with the execution of another clients code. As soon as a single clients 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. in addition to causing loss of trust and degrading the integrity ofthe authority responsible for the exchange. 2.5.3 Cultural and social requirementsWe must also consider requirements based upon social andcultural constraints and conventions. As pointed out by Almberg(2002), when we introduce a new system into the market, thecredibility of the institution involved should not be degraded. Thisis especially true when dealing with an institution such as thestock exchange as it is a barometer for countries and globaleconomic performance and affects government and individualseconomic decision making and policy (Hasselstrm 2003). Theconsequence of a loss of credibility in the financial markets can beseen by the effect of the accounting scandals at firms such asEnron and WorldCom. This contributed to an increasing fallingmarket and new regulation in order to try and restore clientconfidence (Bonello 2005).It is also imperative that the functionality of the electronicexchange continues to be deterministic and that the functionalitydoes not change in any way. This is important because theexchange has in essence provided the same services fordecades. All changes and modifications done to the exchangehave been to optimize its operation, not to change its fundamentalrole as a double auction market, matching buy and sell bids.When any bilateral transaction is conducted, there needs to be anelement of trust especially when being the first to act. This factoris 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. presence of the people you are trading with. When discussing theconcept of allowing a piece of software self-directing control overa large amount of an individuals money, we believe that trust willbe a major factor. To support trust in such a system, it is importantthat it be regulated by a trusted financial services authority, thenclients know that the company itself meets certain standards ofcredibility. As for the concept of allowing the agents control overpeoples money, we believe that we can support clientsconfidence in the system by allowing them to test their strategieson historical data. This would allow them to build an impression ofhow they may perform in the future. This is analogous to how aclient may choose a mutual fund investment on its previous yearperformance. 2.5.4 Security requirementsWe touched on the need for code inspection when discussingperformance requirements. There are also other aspects toverifying the code, mainly security reasons. Because it is a highlyprominent system and the sheer number of agents running on asystem that is coupled to the stock market, it would most likelybecome a target for hackers and other mal intended individuals.Verifying the functionality of all the code, to try to detect allattempts to break or do harm to a core system in the exchange,becomes an immense task mainly because of the followingfactors.Using encryption techniques and advanced coding techniques,malicious code can be hid inside seemingly harmless code.Competitions have been held where hackers have written aseemingly harmless program and had other hackers try to locatemalicious code masquerading as simple harmless excessive Page 29 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 clients 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 ofPage 30 35. clients reach the numbers using todays commercial solutions aswe have mentioned before.And last but not least, the system must be designed so that fullconfidentiality is kept. There must be no way for software runningon the system to examine the preferences of other programs,eavesdrop on communication between the software and the coresystems, and hence gain valuable information which otherwisewould not have been available. 2.6 Reflections on trading strategiesStrategies are the methods used to narrow down all availablestocks to the ones that should be invested in. Strategies can varyin many ways from the simple (for example only investing instocks 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 marketconditions so a complex trader should be able to run multiplestrategies simultaneously while able to execute trades from thosemost likely to succeed. 2.6.1 Strategy RepresentationStrategies and the data they analyse are a matter of individualinvestment preferences, but there are four main aspects neededto have a full strategy. The Encyclopaedia of Stock MarketStrategies (Katz and McCormick 2000) provides the followingdefinition of the needs of a complete strategy. 1. When and how, and possibly at what price, to enter themarketPage 31 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 usedPage 32 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 toPage 33 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. Chapter 3 - The Brokerage ConceptWe have emphasised a number of properties and behaviours oursystem must possess and demonstrate. Non-vital topics have alsobeen mentioned and in this chapter we will try to tie those vital andnon-vital requirements together in a concept we have chosen toname the Agent Brokerage. The following chapter introducescertain issues our architecture addresses and in the next chapterDesign we present our idea of a design for this brokerage. 3.1 Structural designBy structuring the design to be analogous to the current humansystem, we can take advantage of a tested architecture that usersare already familiar and comfortable with. As discussed before,there is a multitude of legal, political, technical and regulatoryreasons why it would be unfortunate to allow complex traders tobe run on a system tightly coupled to the core systems of thestock exchange cf. 2.5 above. We propose a solution to thisproblem by introducing the Agent Brokerage. The AgentBrokerage is an additional server for running trading agents. Thebrokerage is based at a different physical location from theexchange, allowing multiple brokerages to be run by differentinstitutions and companies without involving the authorityresponsible for the exchange. Its purpose is to allow the running oftrading agents on a platform where they are free to access variousresources or be modified to fit the needs of a client. 3.2 Internal designWe suggest that the brokerage is constructed as a multi agentsystem (MAS) where labour and responsibilities are clearlydivided between agents analogous to the current human Page 35 40. arrangement. It is our belief that this arrangement has severaladvantages over traditional design approaches as we shallelucidate to in the following sub-sections. 3.3 Work segmentationBy assigning different tasks to different agents we achieve a socialstructure similar to that in use in real life. Although ours is asimplified version of the real thing, it is our belief that it serves thepurpose. We need agents that assume the roles of the traderwhich finds stocks that are profitable, the analyst which looks intohistorical trends and processes information, and the portfoliomanager which manages the portfolio with regards to riskmanagement, money management and so forth. One of thebenefits of distributing responsibilities in this way is thatstandardised agents can be used for various tasks, relieving someof the tedious task of code verification performed by the authorityrunning the brokerage.One of the remaining variable factors within the brokerage is thestrategy agents. As we have seen in section 2.6 there arestandardised ways of expressing strategies. If we include thisstandardised way of expressing strategies in our system, we canreplace the custom built strategy agent with a standardised agent,without sacrificing the flexibility of a customised strategy agent. 3.4 ScalabilityOne of the most common problems faced by software engineerstoday is to develop systems which scale gracefully. Our techniqueof using a MAS approach allows us to split our system up and runit on separate processors and in separate memory spaces. It isour belief that communicating over a network in todaysPage 36 41. technology environment will not pose a problem. The brokeragewill be connected to the exchange over a high speed WANconnection, as often is the case. Servers will then be connected toeach other, over a high speed LAN, such as a gigabit Ethernetconnection. 3.5 Defining rolesIn order to achieve the requirement of having agents capable ofplacing complex trades, we suggest a multi layered architecturewhere recommendations of stocks to buy or sell are delivered to acentral decision makingagent that decideswhichrecommendations to listen to and instructs a trade to be executed.This can be thought of as analogous to different brokers andanalysts recommending stocks to the traders in the human realm.We see the major parts of the brokerage system as consisting ofthe following components. 3.5.1 Strategy AgentMultiple strategy agents that can be configured to recommendstocks by matching them to a list of criteria given in a strategy file.Thisagent is analogous to an analyst whopassesrecommendations to a trader. 3.5.2 Information AgentThe Information Agent acts as an aggregator for informationcollected from the environment. All agents can register for a pieceof information using a data structure describing who needs thedata and what the data should be. The Information Agent will bethe manager of a group of agents which are called InformationCollectors. Page 37 42. 3.5.3 Information CollectorsThe Information Collectors retrieve data from the external datasources such as third party data providers. Each InformationCollector is responsible for gathering, monitoring and reportingone particular calculation from the external data. Via theInformation Agent, the Information Collectors know which agentshave requested information and report directly to them. 3.5.4 Portfolio AgentThe Portfolio Agent is responsible for sending buy and sell ordersto the Representation Agent. It evaluates whether stock buyrecommendations from the Strategy Agents are suitable and isalso responsible for maintaining the portfolio of currently ownedstocks and maintaining several virtual portfolios for each of thestrategies so that the various strategies can be monitored andassessed. The Portfolio Agent decides when to sell a stock bysetting up a monitor for every stock in the portfolio or virtualportfolio. These monitors know which Strategy Agent the stockhas been recommended by and as such know the exit strategy.This agent is analogous to the human trader, takingrecommendations and information from outside sources, decidingwho it trusts most to offer good recommendations and thensending off orders to be executed by a broker. 3.6 Information flowBy using these ideas for the design, we will achieve an informationflow similar to that existing in todays human environment; seeFigure 3.Page 38 43. Figure 4: Information flows into the Agent Brokerage through InformationCollectors bringing it back from third party sources and delivering it to thevarious agents that requested it. 3.7 Interfacing with the stock marketWe propose that a stock market interface such as the ATS is usedto run simple and light representative agents that take buy or sellorders from the Agent Brokerages. Our proposal is that onlysimple execution only agents trade on the ATS, implementingtrade orders that are requested from the Agent Brokerages. Thisarrangement has a number of benefits: Only very simple agents are run on ATS which should leadto good performance.Page 39 44. All agents on the ATS are from trusted sources. Management of agents is no longer an issue for the ATSoperators. Legal responsibilities are placed on the brokers, just likethe 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 agents actions, but protects the brokerage from malicious attacks or unwanted agent behaviour.Page 40 45. Chapter 4 - DesignIn this chapter we present our proposed design for an AgentBrokerage based on our observations and analysis covered in theprevious chapters, where we looked into ways to achieve ourdesign goal while fulfilling all of our stated requirements. We willpresent our final design in more detail and try to capture theinteractions between objects in greater detail and try to focus onthe interaction between objects on a practical level. We will notpresent a complete implementation of our design in this thesis;however we have implemented parts of the design for exploratorypurposes, such as the messaging system. 4.1 Architectural designAccording to our design methodology discussed in section 1.5 westart by covering the architectural design and then move on to amore detailed design, although we will not cover implementationspecific issues in depth. This chapter should be considered as aguideline for those who would like to implement an AgentBrokerage in the future. The architectural design covers issuessuch as which components the system includes and how theyinteract with one another 4.2 Architecture overviewA schematic diagram for the design can be seen in Figure 4,below.Page 41 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. the brokerage can be obtained from the authors upon contactingthem. 4.2.2 The Information AgentThe Information Agent acts as an information broker: TheInformation Agent manages a collection of information collectors,objects which interface with information sources and process theinformation presented there. 4.2.3 The Portfolio AgentThe Portfolio Agent manages the client portfolios and allassociated data structures. It decides what stock to invest inbased on the correlation between the portfolio contents, themoney management strategy and the investment strategy. Themoney management strategy is configurable by the client in orderto give some constraints to the portfolio agents powers. Forexample, a simple money management strategy might be to neverhave more than 80% of the total accounts cash invested at thesame time and never to invest more than 25% of the account inany single financial sector. The portfolio agent also manages acollection of exit monitors for each of the portfolios, which indicatewhen to sell a holding from the portfolio. 4.2.4 The Strategy AgentThe Strategy Agent is a component which monitors the state ofthe market and recommends to the Portfolio Agent which stock topurchase and at what price. To this means, the Strategy Agent isequipped with a strategy file describing an entry strategy whichthe agent should follow. The strategy agent can choose from a listof stocks that are on its preference list, a list that is customisable Page 43 48. in order to allow the client to choose which sectors he wishes toinvest in. 4.2.5 The Representative AgentAnd finally, we have The Representative Agent running on theATS. The representative agent has the role of an execution onlybrokerage. By running the representative on the ATS we have thepossibilities of sending complex orders to the execution onlybrokerage and transferring the computation associated with themfrom the brokerage over to the ATS. Once the representative hascarried out his task he will respond to the brokerage with either anacknowledgement if the task was successful or an error report ifthe task was not successful. The representative agent will not becovered in more detail in this thesis. 4.2.6 Component communicationCommunication in our proposed system is based on the principleof centralised planning. The Portfolio Agent acts as a coordinationagent, receiving partial plans from other agents and deciding whatactions to take (Wagner 2000). Furthermore, those plans receivedby the Portfolio Agent are based on information collected andcommunicated by the meta-agent Information Collector. Toaddress this need of information exchange, we introduce amessaging system. The messaging systems provides a clear wayto exchange information for the agents, using standardisedrepresentation formats such as the KQML Agent CommunicationLanguage (Labrou, Finin et al. 1999). We propose using twolayers for the agent communication. The lower layer, layer 5according to the ISO Open Systems Interconnection referencemodel [ISO 7498], handles all session control for the agents. Thislayer is needed to address the problem of authentication and Page 44 49. connection establishment, providing the agents with a seamlesscommunication environment. This way we achieve the illusion ofall the agents occupying the same space, and hence enabling allof them to communicate with each other efficiently. (Odell,Parunak et al. 2002)Thepresentationlayer is then reservedfor clear textcommunication using an Agent Communication Language (ACL).This design allows for encrypted communication using the sessioncontrol layer. Performing encryption on a lower layer frees theagents from having to do any decryption.Figure 6: The protocol for agent communication, KQML, operates in thepresentation layer of the ISO stack. 4.2.7 Client portfolios and strategy interactionsThe Brokerage will be serving many client accounts, analogous tothe real world brokerages. Each account will have associated withit at least one portfolio and there will be a number of strategiesassociated with each portfolio. Since we have all the strategiesrunning as agents in the system, each strategy agent can easilyserve a number of portfolios. Each portfolio only has to add an exitmonitor for each strategy to its existing collection of exit monitors. Page 45 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, andhas at least one portfolio. Each portfolio then has at least onestrategy, which can be shared with other portfolios. By sharingstrategies we achieve optimisation in the strategy evaluation byreducing the number of repeated tasks. 4.2.8 Information tokensAs previously discussed, human traders mix and match strategiesand try to apply the best one for the given market conditions.Following this methodology, we designed a system which enablesus to evaluate strategies with the help of information collectors.Each strategy is expressed as a series of logic expressions, if theexpression holds then the associated action is carried out. Toprovide 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. Thesetokens can be viewed as variables in a mathematical equationwhich get their value from the information collectors. A token mayrepresent, for example, a moving average for the last X days orany user defined calculation, as long there is an informationcollector which corresponds to that token request.By allowing the user to introduce his own Information Collectorshandling his calculations and information gathering, he can havePage 46 51. the Strategy Agent, and the exit monitor respond to whatevercondition he wants. This design adheres to the requirement ofrunning secure code on both the ATS and the brokerage since allthe agent communication is sent in clear text through theapplication layer. Furthermore; we split the strategy into two parts:An entry part handled by the Strategy Agent and then the exit parthandled by a set of exit monitors managed by the Portfolio Agent.This way the Strategy Agent registers for the necessary tokenswith the Information Agent which informs, and starts up thenecessary Information Collectors, and starts screening stocksincluded in the clients preference list. When a purchase is madeusing a certain strategy the holding is added to the portfolio andan exit monitor is informed of the stock. The exit monitor receiveshis tokens from the Information Collectors and checks whether asell condition is met for each of the stocks he is monitoring. Oncethe sell condition is met, he informs the Portfolio Agent which thenin turn handles the actual sale of the stock. 4.2.9 Strategy selection techniqueHaving outlined the details of our design in the previoussubchapters we now outline our proposed method of strategyselection. The problem faced in this section is how the system willdetermine which strategy to invest with at any given point in time.To achieve this we re-introduce the virtual portfolios. It is our beliefthat the best way to keep track of the progress of a strategy is torecord all its recommendations in a virtual-portfolio, a portfoliowhich does not have any real meaning for the client except forserving as a benchmarking tool.Normally, when each strategy finds a potentially profitable stock itrecommends it to the appropriate Portfolio Agents, which are Page 47 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 strategys scorecard andassessing 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 its strategies fromPage 48 53. those who have the highest score on the scorecard. The wholeprocess can be visualised using a block diagram notation, as canbe seen in Figure 8: 4.3 Meeting the requirementsAs we mentioned in section 2.5 there are a number ofrequirements which our design must meet. We have identified fourimportant categories of requirements and in this section weexplain how our proposed design meets those requirements. 4.3.1 Usability and humanity requirementsAn issue we identified was the need to verify the correctfunctionality of the entire brokerage. By introducing loggingfacilities into each of our agents we will be able to trace explicitlyand implicitly the execution of each part of the code. The loggingfacilities should support the most commonly used levels oflogging. 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. Normal Execution mode: The log file includes all exceptionsand errors arising in the system during execution. Thislogging mode serves the purpose of capturing all abnormalactivity and omitting all normal activity, as defined by thedesigner of the brokerage. This logging mode minimisesthe overhead of logging, freeing up more of the systemsresources for the actual execution of the agents, and theirdecision 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 systems 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. all recommendations from the strategy agent responsible for thatstrategy, the user will be able to experiment with new strategieswithout risking his investments. 4.3.2 Performance requirementsAfter examining the abundance of software and software servicesavailable to the general public we are of the opinion that thedelays introduced because of the brokerages communication withan execution only brokerage is not a limiting factor (TradeStationGroup Inc 2004; Equis International 2005; eSignal 2005; Yahoo!2005). However the question remains, is the delay introducedbecause of the communication between agents within a brokeragea limiting factor? Even with the most sophisticated high speedEthernet connections, such as Giga-Bit Ethernet, the answer tothe question remains elusive as it is solely implementationspecific, and answering that question could be another thesis initself.As we mentioned in section 2.5.2, it has been pointed out, byBoman and Lybck that the core systems in the exchange are notallowed to become overloaded. It is our belief that this is not anissue in our design. One of our designs core ideas is to interactwith the exchange through a buffer service, such as an executiononly brokerage. There are a couple of points that need furtherelaboration.The original design by Boman and Lybck was partially based onthe principle of locating the ATS next to the core system of theexchange. This would allow for a zero time delay for the agentswhen interacting with the exchange. The zero delay aspect wasone of the driving points of the design as it was seen as means to Page 51 56. encourage investors to use the service, hence allowing theinvestors to bypass the systematic delay introduced into thesystem because of the rule of fair dissemination of information.Fair dissemination of information is an agreement ensuring that allthose taking part in the stock market have the possibilities ofreceiving information at the same time, hence eliminating theadvantage some investors might have on other investors.Execution only brokerage services are managed by a third partyorganisation, such as those we have discussed in this thesis. TheAgent Brokerage introduces therefore no added strain on theexchange and no code is actually run on or around the exchange. 4.3.3 Cultural and social requirementsAs we pointed out in section 2.5.3, it is also imperative that thefunctionality of the electronic exchange continues to bedeterministic and that the functionality does not change in anyway. By introducing the buffering layer of the execution onlybrokers and not running any code on the exchange itself ourdesign does not affect the functionality of the exchange. This inturn preserves the trust of the public in the financial institutes,such as the execution brokerages and most importantly theexchange itself. What remains is to establish trust in the publictowards an Agent Brokerage, automatically investing their money.We have already discussed means to establish trust in thebrokerage in section 2.5.3. 4.3.4 Security requirementsWe touched on the need for code inspection when discussingsecurity requirements in section 2.5.4. We revisit that discussionhere to underline the way our design addresses the code Page 52 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 Agents 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 publics trust in the design.Page 53 58. Page 54 59. Chapter 5 - Concluding Remarks5.1 Lessons learnedThe original concept behind this thesis was to expand on the workcarried out by previous masters students designing trading agentsfor the ATS. As our Interactive Systems Engineering degree workat KTH was based upon user driven design, we decided thatbefore looking at the purely technical requirements we shouldbuild a good understanding of our wider domain of work. Westarted by reading a collection of masters theses and developmentdocuments obtained from our supervisor on the subject and a fewbooks on stock trading. We spent a month just getting to knowwhat stock broking was really about, the players involved and howthey worked. We soon saw that stock trading in general is morerelated to sociology than to mathematics. The success of ourproject was dependent on human factors rather than technical.This reinforced our belief that a user-based approach to thesubject was more beneficial than a purely theoretical one. Wedecided to include a user-study as a part of our research phase,which already included reading theoretical books and papers onthe subject. We approached a few financial institutions and eithermet with members of their staff to speak to them and ask themquestions regarding their work, or sent out a number ofquestionnaires. It came apparent that a quick and dirty user studywould only probe the surface of the human factor so we added abook on a rather ambitious ethnographic research carried out by aSwedish PhD student to our list of reading material (Hasselstrm,2003).Once we were acquainted with how real life stock brokers andtraders go about their business, we decided to get better Page 55 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. thesis which is 20 weeks of work per person. We decided insteadof programming an experimentalproof-of-concept AgentBrokerage to develop our idea and complete a detailed design upto the level of implementation. Thus anyone who is interested indeveloping the idea into a product has a solid base to build on.The danger of following a software development model such asthe waterfall model is that the developer gets locked in to a setidea and concentrates purely on the technical problems that needto be solved. We could have realistically implemented a trader thatwas able to choose between multiple strategies and was capableof running on the ATS, the original plan for the thesis research.However, this would be a purely academic exercise as we havediscovered that due to the complex non-functional requirements ofthe financial industry, it would not be viable to use this type ofagent in a real world scenario. By taking a human-centred focuson the design we have highlighted many of the requirements anddifficulties faced when designing new technology for the financialindustry. We have also proposed a possible architecture that webelieve would support systematic trading through the use ofsoftware agents. 5.2 ConclusionWe have developed and presented an Agent Brokerage. TheAgent Brokerage was the result of our attempt to design a fullyautonomous trading agent running on the ATS developed atSICS. During our design work we noticed that running our designdirectly on the ATS violated some of the requirements stated bythe inventors of the ATS during its development. We havepresented our design as a guideline for those who wish toimplement such an agent platform.Page 57 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. By analysing the requirements captured in the previous stage wewere able to identify over 75 requirements which would have to bemet if any trading platform is to be successful in real life.So we can clearly state that we have reached all aspects of thegoals set in the beginning of our work. 5.3 Future workWhile we have suggested a possible theoretical solution to theissue of running trading agents, there exist many avenues downwhich our work could be extended. Three suggested further areasof study are included here. 5.3.1 Designing a notification serviceAs mentioned within the thesis, trust plays a large part in theacceptance of any system which involves humans and some kindof trade or exchange of money. It is important for humans to feelin control of what is happening within the Agent Brokerage. Theprinciple used in our design is that of having autonomous agentshandle all trades and that takes a high degree of decision makingout of the hands of the human. We envisage that by having theagents within the brokerage report important information and factsto the humans, it will increase the trust level between humans andtrading agents. Any investigation into a notification service wouldneed to look at factors such as the interaction device for thehuman and the level of detail of information sent. 5.3.2 Visualisation methods for strategiesThe Agent Brokerage has the potential to allow the averageprivate investor a new window onto the stock market. The biggeststumblingblock for the private investor could be the Page 59 64. implementation of strategies, especially if the method of strategyrepresentation is complex and requires a strong degree ofcomputer programming skills.We have already suggested a Boolean based method to representrelatively complex strategies, but suggest that it may be possibleto use information visualisation techniques in order to make therepresentation of strategies more easily understandable andachievable. We do not wish to influence any further study bymaking a suggestion in this thesis on how this may be achieved. 5.3.3 Implementation of the designIn order to evaluate the effectiveness of our design, the detaileddesign on paper should be implemented as an actual softwaresystem capable of running on a stand alone server. This wouldallow test agents to be written and executed and would exposemany of the technical pitfalls associated with implementing acomplex design.As previously mentioned, the authors have carried out work on adetailed design for the Agent Brokerage including the architecturealready described and additionally a proposed messaging andagent communication system, logging system, collaborationc