{"data":{"markdownRemark":{"html":"<!-- TODO: fix visual bug (footer navigation appearing in wrong place) on this page -->\n<div class=\"ui segment info message\">\nThe model is based on the following paper by Professor Rama Cont:\n<a href=\"http://content.simudyne.com/$web/ramacont.pdf\" target=\"_blank\" rel=\"noopener\">Volatility Clustering in Financial Markets: Empirical Facts and Agent–Based Models</a>\n</div>\n<p>In this introductory tutorial, we will cover all the components needed to make a simple agent-based model of traders trading in a stylised financial market such as a stock market. The model is comprised of traders and a common information signal observed by all traders, which we can think of as a 'news arrival' process. All traders compare this information signal to an internal trading threshold.</p>\n<p>Traders place a buy order when they believe the trading signal is positive and a sell order when they believe the signal is negative. The net volume of buy and sell orders is then mapped through a function that generates a change in the asset price (e.g. stock price).</p>\n<p>Realistic price dynamics (e.g. stylised facts) emerge from the model based on simple behavioural rules and the interaction of heterogeneous agents.</p>\n<p>The code for this tutorial is available as a zip download, containing a complete model as a Maven project. This project should be able to be run from any Maven or Java IDE environment.</p>\n<p><a href=\"https://simudynecontent.blob.core.windows.net/$web/tutorials/zips/trading-tutorial-v2.4.zip\" class=\"ui button primary\" download>Download Tutorial Files</a></p>\n<p>From a command line you can then run (with Maven installed globally) <code class=\"language-text\">mvn package exec:java</code> to run the server. This will download all library dependencies, build the project, run any tests and then run the Simudyne server locally with the web console. You can then open the server at <a href=\"http://localhost:8080/\">http://localhost:8080/</a>.</p>\n<h2 id=\"console\"><a href=\"#console\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Console</h2>\n<p>Once you've opened the local server, you will be greeted by the model selection landing page:</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 238px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 68.93939393939394%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABJ0AAASdAHeZh94AAABcUlEQVQ4y61TTU/CQBDlKhhFBSwFChQEJOHDz4s3L6KAJbSAUECkAU56ICZE40c0IdGEm4m/wP/53F1sgzFCMR5eOjuZzr43b9ay7i2BwuVRoMfTMKvOMlnk5BUGh1tmoPlxTmZfvW5aU4se0B+CkTr8YRWBjTqCBLxQhidwBp9YBe+vwE3Os5oaDSmj9F4PsUQbmdM7XLRHkJRHdHoj1M+HULUXZKVbrLoK4Hyl2QzpjZSJN1iFEKoh8MU0Em8hHGuSWGXsXfwcM6Qs7U4J1uUsbCt5LBLY7DmscUVjrnr9VMmcr8wa7R9c4Wn4gZb2isv+G/rX76jVnpkpc7k8ZleEGG3iMDNAQXmAJN/jOH+Do5MBOBPr9IvkIpGZw8JSlsFK5DLJJG9mZX6sDTVkM6khudtFPK0htd1BYquD1E4XAjFsUropl+kshZDK9jFEnBUjDea2GG2QnayYek3fJI9fhmw46jDiP0g2c7tphv+JT+uYubSmZF1HAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-9e9ba.webp 173w,\n/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-67aa8.webp 345w,\n/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-6fbc6.webp 396w\"\n          sizes=\"(max-width: 238px) 100vw, 238px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-ef06f.png 173w,\n/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-c78d7.png 345w,\n/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-0796c.png 396w\"\n          sizes=\"(max-width: 238px) 100vw, 238px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-0796c.png\"\n          alt=\"trading landing\"\n          title=\"\"\n          src=\"/static/trading_landing-fed4a6ae9fd7ea231f96a7001e6dfb86-0796c.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>Clicking on \"Trading Model\" will take you into the console for that model. When the console is first opened, a model is not setup, and so there isn't much to show. The sidepanel contains the main controls for interacting with a models configuration/inputs.</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 690px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 51.85589519650655%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAABJ0AAASdAHeZh94AAABAklEQVQoz6WSyU7DMBRFswQW6eB4iJ26AeUfYFGa0GERWghDA+LfKP3Uy4vVgoKslsLiyJbsd3z99IIs3MBmUzA5Q9gfQ+g5UUKZClwtERG79Qu5AI/voO0jVFJB6srtpb5HcH62gRrOqKh0InvxDGkeIEwNmexHmNUP6q3QlkizN+IV8YBk9KK/oI3vkSA9XaOnrhD2cvryNTECU7d0+HJQ6IMSflDCnHo4Rze6ARMTcL1sCQ99vZWwEcZpgT6fosMKkubU8H8KIzNCl01cwkYYqcXfhcOTNTr8koSNrKCUY+rht1Amx0HCd4QeoXDC+mi8wohmUtuVm8ff0tyPB0/4BFlmLdFtn1nXAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-8e416.webp 173w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-0b506.webp 345w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-58be5.webp 690w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-59b8d.webp 1035w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-4a474.webp 1380w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-bb358.webp 1832w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-7e3fa.png 173w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-7f1d4.png 345w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-13856.png 690w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-045bb.png 1035w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-f46ab.png 1380w,\n/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-81ea4.png 1832w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-13856.png\"\n          alt=\"trading sidepanel\"\n          title=\"\"\n          src=\"/static/trading_sidepanel-85292bc764b758a14b33f6cfccd839ae-13856.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p><strong>Initialise</strong> will setup your model using the defined parameters. After setup, some things cannot be changed (such as the seed, or constants for the model). You can open types of inputs using the headers. In this model we have a single constant, defining the number of traders in the simulation, along with 3 inputs controlling parameters of the trading process.</p>\n<div class=\"ui segment info message\">\nWhen working with iterative development of your models you will likely change the inputs and variables multiple times rapidy when building and working with the console or your own code via the REST API. Modern browsers however are likely to cache changes from your previous builds or changes which could cause issues where code doesn't render, or variables are missing. It's recommend to either use a private/incongnito mode when testing, or to modify your browsers settings such that on close cache is cleared. You are free to keep things like history, passwords as those won't be affected by model changes.\n</div>\n<p>For now we can leave things as they are, and click <strong>Initialise</strong>, upon which a few more elements become active.</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 690px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 52.51798561151079%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABJ0AAASdAHeZh94AAACA0lEQVQoz1VSy3LTQBDUF1jRY7WSVq8Q4xQXqqCowhycxI8kxLIky44JjyquOeSv+AE+selZQUwOUzs7M9s90ztOMV5CJUuM/At40Zz+NUzRI8m3CHQNFW8YaxDSD+lbox+lra2LTQuddjDljrEGTlq1LNrCUyto85mP11CpFO6RZPeM7Vm4Q5zt6fMR7/Ff04xL7RDvbc55N/2FD9PfOJs84e37RzIdSFAjkw4SstP3o1sCbCxZyG5Ta609JaeTmuBshDEnH2+QVWTMWpRnB3azseaGVxgFl/Y8obn0ZYrIdPA1JQoujjmbvyIZAZPyEr5aUMMZgzN2d0P9Oj4eio82AMbZlrpeDwT/5y0gNVRmhiBa2aCn5gjiW9uhAAqrGw5dyj3Qkut4rp67l/xJOOfoC47cwTGnCxYvn5k8gosEk1cP1JBaEUB0FI3y0y/QWY/J668oOLroGLMmiu+QVztOdoDjqk8EWhwBOVaS3yMvHxCoGxTVNzLLuqy5JgcrfFF9RxjdISaZ1Hnhyua02cIZhR85/9xq4FLoQXhZhc6KLJ8gIFKsRT9ZqayzecVNkH2UfMy9jbg+zkhNB8B/P8mRI2oRcYF9diEWaHZjGj6U5aYMpobJahsP9JoEjV2pgLkXgPKT4mdljzRvOFJNoJeW8rGYaCr3vOpt3fmbnxif/8Af+ytDy75s4MQAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-8e416.webp 173w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-0b506.webp 345w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-58be5.webp 690w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-59b8d.webp 1035w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-4a474.webp 1380w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-50963.webp 1807w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-7e3fa.png 173w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-7f1d4.png 345w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-13856.png 690w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-045bb.png 1035w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-f46ab.png 1380w,\n/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-e58eb.png 1807w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-13856.png\"\n          alt=\"trading initialised\"\n          title=\"\"\n          src=\"/static/trading_initialised-3bbe46d202391374789a3dbfe40aa922-13856.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>We now have a set of charts, showing different outputs of our model. Because we have only just setup, there is only a single tick of data to inspect. However, some of these charts are showing top level values, whereas others are showing aggregations over agent attributes. You can tell the difference by colour, and by the information in the lower left of agent level charts, showing the type of agent, and how many agents of that type are present.</p>\n<p>In this model, there is a single <code class=\"language-text\">Market</code> agent, which holds a price. A more interesting chart is the <code class=\"language-text\">TradingThres</code> on the <code class=\"language-text\">Trader</code> agents. Each agent gets their own trading threshold from a distribution, and we can see this is the case by changing the aggregation mode of the chart, available through the <code class=\"language-text\">···</code> menu to the right of the name.</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 372px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 96.45161290322581%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAATCAYAAACQjC21AAAACXBIWXMAABJ0AAASdAHeZh94AAADz0lEQVQ4y31Uy25bVRQ1lRAtxLGv7Xtt39hOXDtObKfOw5UIcRM7ft+HH4ndPJqEoEpAJyBUJRWCqBOokIpQQUI0s2aMUCcdAD9Q4Af4BsQcIUaLdc5xShASg3XPPa+91957ne0xzA2Eoh0Ewh1ohgst7MpRzMW6/j8IRRSCYVvODbMPj/gJGC3MpLtYzPWRn+mhkO0jO92FHmnLvYDR5iWF8//Z7AZS0wOeqSJiFuS5UNQVBrvQ9BaMqAUz5iA6oRAxHV60eNCSh/2hBnzBOsc6501EYxbCpoWgUSfLdelIkPMEGWJsqo/J1CbGeUHjYb/epJOmvKhQw9zCFgpLO5ib3+J8HeOBNToo01iNd+rSqTQochCecOnR5oE1Mqj8BwGjSocu4klbGlPrZVzxrqh9vSodh/5lMO5IrxcN+YIVjPlXpcE8mS1cv8UwG/Kcpq+jsLgNr3aDKI9yODIYjXdgJhxo9BokA4GAXmFea0hlxH4LKRYre20oWXq1NelkuH1CJ/vcb8scvwg5GiNLhuy5/AYuvVqSeOlKCS97V2HELURiLWRym9KIV1uV7DU6TFzdxu7+J1go3sJrPhIwu8qgwZCzuSH2rEMcOG9hnxDjnn2ITnkHiUQTOYYsWI4HyrIYIpdvv/uAkYkU1BCfuq1kY5Cmz7DRXN0Dnn8D/HwK/PRY4flj/Pb0c6wvD5BI96i5mjR2jpP7p3hy9gwzuZucW2TYGRnULVRXdvHnD4/w149fcfxS4o/vH+HXs09RKvYxRmYiTGFIVFiM8aSDyauulJWmj3IoPn4+nXZZMPyaDMnsl1MF/v/+9KFkOJ0fIsGCXFSBUIAYg+EaiziSjUhkOruD0ut7+PbBCb777D7OPj6SePLREb54730U8l1M8SkKUYuKK9lUZLVnWKyJSVu+IsWQBsWzSWa2oCf4Wlgkz+WKwisVXBqrIxhpUasNWW1RDBW20qlh1gmy4/sORVzF0BtooLh0EytLPRTnuihe62Ex38N8rodMqkExVzG/tIv54i7ZWLLS/tAapbIs5TQ9u0mHNh2PmoNQeXr2HiaTBwhHmzDZHFSjaLOj3IEZP+DlVYZYpfj53vUaWQ0omUPmkUy5JjpQSBVFdZvryw9p9A7z0Jb9TdMtqa9M/h6ycx+QQVs+UdF9RMeJTb3J53gsmUVi7j/dRuTQF2ygVLmN/uAYtnMXyfSAl0TLarIQOxhufQi7c5dvd59sRCdqI5bsYmP7GE73CCs33rnYD3uy74lcCmGGIg5hS5aqE7tyXY86cu98XfyrdffFuoj2b7V9ZgdyQ/3RAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-f4e85.webp 173w,\n/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-cc5fc.webp 345w,\n/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-efb1e.webp 620w\"\n          sizes=\"(max-width: 372px) 100vw, 372px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-a29a2.png 173w,\n/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-f343f.png 345w,\n/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-598d5.png 620w\"\n          sizes=\"(max-width: 372px) 100vw, 372px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-598d5.png\"\n          alt=\"trading histogram setting\"\n          title=\"\"\n          src=\"/static/trading_histogram_setting-b86597fa21a871699498500456f05ace-598d5.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 356px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 75.04215851602024%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABJ0AAASdAHeZh94AAAClUlEQVQ4y5WUS0wTURSGJ1FAhb6mM20F2imtLY/gQuMjTUqB0jJFCu2ASNioCwkxMSnVEBNNDMEFLJRi28TG6FJj3KlBJfHtChNj3OvCvUYjvjb6e+4dqG1TFy7+3Dn38d3/nJkzgmiLQXYMwK3EoazL5Yqj2TkIq30AbJ2N1bSxtt05BMlxgMeCRY5Bssewsy2JztYEOvwJtPsS8HmHyw5JDl0srpTXfxD2pkEdaGuMw9E8BKMUg2lDdIlZ/uuMPTeIKraZ+6s6ZaY2LhacLRq/wSKHabJPl6zLQjJLYUq/H7s6hxHYrVE2ET5fKdGm6sAmhdJrP0QHe0jdZZLsvRDqApibnAIeZ/HuxjwMYggNlhBByveLNt290OhKQPFq68ByMWBNQxCFmRSwWsDb6/MI79fgaOyDyVq+t+iwWUmixTdaFch0a24Gn+8u4tv9DNfXexn07NNQawgSpLcK0J2Eh2pYDWYQu7F6eRZ4mseX5UV8f7CEnytLCO1JYnN9ENZ/Af3FGupi9RHlXn7gRe4cfj/KYo2c/SDgpzsX8ebaeYyrE2Uui0CnW4O/Y7wIY5B6cwieln68LMziw+0LHMTSZe4+UszqefboJDaRS9kRrgDSZ9NaAtxqCmGLqQuhvUmeZqkYlF2wtpzB+5sL/O0LNQFuwmovSdm9YwQGSxdfcCtRnDlyDHiSo08lx9PFszzVkeLnefx6eEl/fnUFr6/O0fdJHSJ301uP6ECjGIWvbQx+artoYAynD08hm04jfyqN3Mk0llLTPM6mp3mcSaWK83kaF46fQDQ4QedHeUfxXla8I3B5NN4+BquKWmMUNYYIHytVVzlH+1jZPLzbVAi8VyWV6CrE9d5kf5//EQOZJb1T/gB+GRJg7HDLigAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-43f56.webp 173w,\n/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-9c7bf.webp 345w,\n/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-83b1e.webp 593w\"\n          sizes=\"(max-width: 356px) 100vw, 356px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-ffd75.png 173w,\n/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-d9274.png 345w,\n/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-73ca4.png 593w\"\n          sizes=\"(max-width: 356px) 100vw, 356px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-73ca4.png\"\n          alt=\"trading histogram\"\n          title=\"\"\n          src=\"/static/trading_histogram-159a365a0738b0b5c29f041e622acb8c-73ca4.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>If your charts view gets cluttered, you can turn on and off different charts from the data search bar at the top.</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 690px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 58.902077151335305%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAABJ0AAASdAHeZh94AAACnElEQVQoz31TS2gTURQNLbqw7TSZ/y9vEps0sR9wYVFjf7ZNZtJMJmk+Wm2pRVqKYKluBD/oSqi0G1G6ci8UqisXrroRF7rRlUvBldSliMvjfZNYRMHFYe57786Zc887E5F1F4m+OdhOAFnzICoF6NYsJNUlFP+BrBWhmQH1V2HYZSj6LPVXwrVm+Ygohg/LmYXJPOh2AT2xMWQGGkhlL0IyatDsZgi9/VSsBlSCHm8env2JkNBOlEIyju7oGLJE2J9pwrLmwJw6fbkC2WgpSiariDNa6z4pJYX0vsRrO4BCyiOyXgoJneMliOoUkUyBpakp6aJDyOGIOIpeJU+kVRqtRCO6ISTNxVFhClGySFIL4Vqm8UlhGarJPZsm/6bRLY3BG1rH/ZkdrJ/dxEbuEU4kliCTSs0qQhAnEJMn0RUbRyM/D8by6I619iSNE5JMWffQK01AVmcQ6TmF7fwz4NZPfN84wI8b3+AO34RAkxg2//AkOrtGUZ5oAvtPcHtphdbnaP88jd4m5HJ/E3YIp3FnfBtf1j7hw5V3+Lj8HtPD1xE1uGdFdJHHx6Lj2H98D3i7g4OXWyjkaiGpYpRahHxk7h8fuTN6Bqsjd/G6+Qq71V28qO9hJL2CmBEg7vjIpDw8XLtGRNv4/HwTX/e28ObpA5wc9CHykfkNJfpq5EUAk/xk5FXSrCDLLmDQmUdu6Cr6U5ch6gGlgCIW95HqC2DZpRAGXRRjPliC7sIqI8JZWXIB6fQydL1IpAEy/atwWA06nSWcS9S8EEZDVD26VReCRBbJblhz8JpDainksWkgO7RIkovU4CE9sAgn1YAgUzZZlUJfoxxWwljwl/jzb7T2/ZaHitkgBXOHaee1YtTDWjXrdN6u23/J//ALYpmG85dV+igAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_search-052c0522d28af0c2826049da3c18a261-8e416.webp 173w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-0b506.webp 345w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-58be5.webp 690w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-59b8d.webp 1035w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-b3190.webp 1348w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_search-052c0522d28af0c2826049da3c18a261-7e3fa.png 173w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-7f1d4.png 345w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-13856.png 690w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-045bb.png 1035w,\n/static/trading_search-052c0522d28af0c2826049da3c18a261-b7e96.png 1348w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_search-052c0522d28af0c2826049da3c18a261-13856.png\"\n          alt=\"trading search\"\n          title=\"\"\n          src=\"/static/trading_search-052c0522d28af0c2826049da3c18a261-13856.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>What also become active once the model was setup, was the top right View selector. By default we are on the <strong>Variables</strong> view, showing the numeric outputs of the model. The other two views available are the <strong>Network</strong> and the <strong>Agents</strong>. <strong>Agents</strong> shows a tabular view of the agents within the model, which can be useful with small numbers of agents to check their exact properties. <strong>Network</strong> is useful to see the overall structure of the agents and their links. In this particular model, there is a single central agent, with all other agents connected, giving a hub and spoke layout.</p>\n<p>\n  <span\n    class=\"gatsby-resp-image-wrapper\"\n    style=\"position: relative; display: block; padding: 20px; max-width: 690px; margin-left: auto; margin-right: auto;\"\n  >\n    <span\n      class=\"gatsby-resp-image-background-image\"\n      style=\"padding-bottom: 71.86311787072242%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABJ0AAASdAHeZh94AAAC20lEQVQ4y3VTWU9TURDum4kRZWl7e7uxWQER8R+YGIWgKdDlli0k4m7AGKMRRcUlod5euiABhboABSw2RIL6gEoiSgwKEXCFyGp8IVEfNfHpc+6pVUvkYTJnztxv7vfNzFEkp9iRahKQsqEY2mQBalMZOL0NWqOAWM4K3iBQbMcapQX6RAEqrR0autMlOqDRyzmBxbwxHCtkgAyWLzg6q8nL8ao4Cyzb98F/6jS6zp9B68lqDPou4uqJagaM19iYV+vs/xgVjL6gvzM2VpSbD2K604WhJieeNYuY7vbgXYeEyVsiaiqOsm9VZJw+rCDiFX8DgcmLUVlRsvMAZm9LeNvuwgN3HZ63SFi848FUpxvzPfVYuutBVVEVtcTG5EbwsikiByaDtyEtrQQLBJKLTbZJ+Nzrw6uOJkwHmzDX48WXfh/LPSb5qaZiJBBm5YLUl4z0EpIqMkZDzRImAs3o6x1Hb99HjAX8+NbvxWJIZutCRcEh1h7esELBOCqYubEUUwERs0EvRm9ImOrxY+DpVzwc+Y7h9k6S68Zgo4gfA1dQ6ajE6gQLDXSlgtST7E1leNFSh1G/iKU+H953NeBJWxdeh7qxEGrAXNBDg5Hw6roT2VlljITmf5K53ysg0x9qvETNd+MN9WqGmH4KeTHRVo8RvxvjN0XWwxZao3VcdLFwQXn0kZUxhGVvJpb3xFrMdEt42eokiZcxfE3CfNBNA3Oj/WwNsjJL2RCX7+IyhuGtl9fBmORA4FwNxvxOfAhI+PmokfX2vqsW62m6a1XhYciYMN4RZsgWVGtbttwCWwf5nLd1D+qPHMeF/cdg3rYXSt7OcvKPIzjZx3OFlLPS09NbkEzvl9cXQGuw/DGdkaZnKESsOp/Y5CNGaaah5UflElOKYEiyw0g+a8thmNLLoVCqc8DrdkGl3gEVlxNlajJOQ8bnQkPGaXLZXSTP8XnMaw1mZGTuRlKqHb8AEQgprFuuWM0AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n    >\n      <picture>\n        <source\n          srcset=\"/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-8e416.webp 173w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-0b506.webp 345w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-58be5.webp 690w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-59b8d.webp 1035w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-95090.webp 1315w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/webp\"\n        />\n        <source\n          srcset=\"/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-7e3fa.png 173w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-7f1d4.png 345w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-13856.png 690w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-045bb.png 1035w,\n/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-427c7.png 1315w\"\n          sizes=\"(max-width: 690px) 100vw, 690px\"\n          type=\"image/png\"\n        />\n        <img\n          class=\"gatsby-resp-image-image\"\n          style=\"width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px white;\"\n          src=\"/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-13856.png\"\n          alt=\"trading network\"\n          title=\"\"\n          src=\"/static/trading_network-ade66a64ef4b3f7ef2a8aa555efdafb5-13856.png\"\n        />\n      </picture>\n      </span>\n  </span>\n  </p>\n<p>The top left menu allows to specify an attribute of each agent type to use as the scale factor for each node in the visualisation, and the top right allows to switch between different layout approaches.</p>\n<h2 id=\"project-structure\"><a href=\"#project-structure\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Project Structure</h2>\n<p>The downloaded zip consists of files defining a Maven build. Some of these files will be common to every Simudyne model project, while others are specific to the model being built.</p>\n<div class=\"gatsby-highlight\" data-language=\"shell\"><pre class=\"language-shell\"><code class=\"language-shell\">/README.md                <span class=\"token comment\"># Human readable description</span>\n/pom.xml                  <span class=\"token comment\"># Maven configuration (dependencies, etc)</span>\n/simudyneSDK.properties   <span class=\"token comment\"># Simudyne SDK configuration</span>\n/.gitignore               <span class=\"token comment\"># Git version control ignore rules</span>\n\n/src/main/resources/log4j.properties              <span class=\"token comment\"># Logging configuration</span>\n\n/src/main/java/Main.java                          <span class=\"token comment\"># Application entrypoint</span>\n/src/main/java/models/trading/TradingModel.java   <span class=\"token comment\"># Model class</span>\n/src/main/java/models/trading/Trader.java         <span class=\"token comment\"># Agent class</span>\n/src/main/java/models/trading/Market.java         <span class=\"token comment\"># Agent class</span>\n/src/main/java/models/trading/Messages.java       <span class=\"token comment\"># Message classes</span>\n/src/main/java/models/trading/Links.java          <span class=\"token comment\"># Link classes</span>\n\n/src/test/java/models/trading/MarketTest.java     <span class=\"token comment\"># Market behavioural tests</span>\n/src/test/java/models/trading/TraderTest.java     <span class=\"token comment\"># Trader behavioural tests</span></code></pre></div>\n<h3 id=\"project-configuration-and-documentation\"><a href=\"#project-configuration-and-documentation\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Project configuration and documentation</h3>\n<p>The top level files define some project configuration and helpful documentation.</p>\n<ul>\n<li><code class=\"language-text\">README.md</code> is a markdown file, and a good place to put documentation relating to the model for others (and yourself) to refer to. If hosted on version control services such as GitHub or BitBucket then it will display nicely to other users.</li>\n<li><code class=\"language-text\">pom.xml</code> contains the Maven configuration, and is where you can change or add dependencies to your project. This is important for changing version of the SDK, as well as adding additional libraries you may need for modelling.</li>\n<li><code class=\"language-text\">simudyneSDK.properties</code> allows configuration of the SDK libraries, such as enabling, disabling or tuning certain features.</li>\n<li><code class=\"language-text\">.gitignore</code> is a file for the Git version control system, to ignore certain files from being tracked. These files include files generated by compilation (inside the <code class=\"language-text\">target</code> folder) as well as caches created by IDE programs such as IntelliJ or Eclipse.</li>\n<li><code class=\"language-text\">log4j.properties</code> inside resources defines a default logging setup, writing helpful information to the console. More information on configuration of logging can be found in the <a href=\":version/reference/logging\">reference</a>.</li>\n</ul>\n<h3 id=\"model-definition\"><a href=\"#model-definition\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model definition</h3>\n<p>The files under <code class=\"language-text\">/src/main/java</code> define your project.</p>\n<p><code class=\"language-text\">Main.java</code> defines the entrypoint for your application. The included file is setup to simply register the <code class=\"language-text\">TradingModel</code> (with a name) and start the server. Your project can include multiple models, but you should think carefully if you need to collaborate with others. A separate project per model will make collaborating and versioning each individual model easier.</p>\n<p>The model files themselves are then inside <code class=\"language-text\">models/trading</code>. The Java convention is to use packages, where a package matches the folder structure to the file itself. So the model class <code class=\"language-text\">models.trading.TradingModel</code> is located at <code class=\"language-text\">models/trading/TradingModel.java</code>.</p>\n<ul>\n<li><code class=\"language-text\">TradingModel.java</code> defines the model itself (referred to as the <strong>Model class</strong>).</li>\n<li>Agents are then defined in their own files, each defining a single <strong>Agent class</strong> of the same name.</li>\n<li>By convention, message and link classes are nested inside a wrapping class, to help reduce the number of files.</li>\n</ul>\n<h3 id=\"model-testing\"><a href=\"#model-testing\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model testing</h3>\n<p>The final files are tests for the Market and Trader agent behaviours. The Simudyne SDK includes utilities called TestKit for helping test <strong>Actions</strong> (the unit of behaviour). These can help you verify that your actions operate as expected, especially helpful when making later changes that could introduce errors.</p>\n<h1 id=\"model\"><a href=\"#model\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model</h1>\n<p>The Model class (<code class=\"language-text\">TradingModel</code>, inside <code class=\"language-text\">TradingModel.java</code>) is the root of your model. Broadly, it ties together 3 concerns:</p>\n<ul>\n<li>\n<p>Initialisation</p>\n<ul>\n<li>Define global state, including accumulators</li>\n<li>Define inputs and outputs of the model</li>\n<li>Register Agent and Link types</li>\n</ul>\n</li>\n<li>\n<p>Setup</p>\n<ul>\n<li>Create the agents within the model (from the console, this is what happens when the <strong>Initialise</strong> button is pressed).</li>\n</ul>\n</li>\n<li>\n<p>Simulation</p>\n<ul>\n<li>Define a <code class=\"language-text\">step</code> method which moves the simulation from one tick to the next.</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"initialisation\"><a href=\"#initialisation\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initialisation</h2>\n<p>Initialisation covers any top level fields on the model, the <code class=\"language-text\">Globals</code> class, as well as an implementation of the <code class=\"language-text\">init</code> method.</p>\n<div class=\"ui segment warning message\" ><h4>Constructors</h4>\n<p>If you're familiar with Java (or other languages with classes) then you may be tempted to do initialisation within a constructor. If you do define a constructor, then it must take no arguments. Also, if you want to use any contextual APIs (through <code class=\"language-text\">getContext()</code>) this must be done inside <code class=\"language-text\">init</code> and not within the constructor or during field declaration.</p></div>\n<h3 id=\"model-fields\"><a href=\"#model-fields\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Model Fields</h3>\n<p>Defining inputs and outputs can be done through fields on your Model class. These define model-level properties that only the top level model has access to (agents cannot access these). These fields are useful for defining model constants needed for <code class=\"language-text\">setup</code>, as well as variables that are computed by the model at the top level.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Constant</span><span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"Number of Traders\"</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">long</span> nbTraders <span class=\"token operator\">=</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Fields (on the model, as well as within Globals or on Agents or Links) can be annotated to make them visible to the SDK. There are 3 common annotations needed for most models:</p>\n<ul>\n<li><code class=\"language-text\">@Input</code> denotes a field as being accessible by the outside world, and available at any time during the simulation. This is useful for parameters that may be controlled by an end user, or exogeneous factors to be varied by scenarios.</li>\n<li><code class=\"language-text\">@Constant</code> denotes an <code class=\"language-text\">@Input</code> which can only be changed prior to <code class=\"language-text\">setup</code>. This is useful for fixed parameters of the model, such as the initial number of agents, which will make no difference after <code class=\"language-text\">setup</code> has been called.</li>\n<li>\n<p><code class=\"language-text\">@Variable</code> denotes an output of the model, which is available only after <code class=\"language-text\">setup</code> has been called. This means it is safe for fields marked as <code class=\"language-text\">@Variable</code> to be uninitialised, as long as they are initialised by the <code class=\"language-text\">setup</code> method.</p>\n<ul>\n<li><code class=\"language-text\">@Variable</code> can also be used to annotate methods. The method must take no argument, and return a supported type. The method will only be called after <code class=\"language-text\">setup</code> has been run, and so can depend on internal state such as agents being initialised.</li>\n</ul>\n</li>\n</ul>\n<div class=\"ui segment info message\" ><h4>Public vs Private fields</h4>\n<p>If you are using Java version 9 or above, you will need to make all annotated fields or methods <code class=\"language-text\">public</code>. On Java version 8, fields and methods can also be private or package-private.</p></div>\n<h3 id=\"globals\"><a href=\"#globals\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Globals</h3>\n<p>A Simudyne ABM makes visible to all agents a single instance of a class extending <code class=\"language-text\">simudyne.core.abm.GlobalState</code>, as defined by the type in <code class=\"language-text\">extends AgentBasedModel&lt;TradingModel.Globals&gt;</code>. This class may exist in another file, but by convention it is placed inside the Model class as a <code class=\"language-text\">public static final</code> class.</p>\n<p>Fields on the <code class=\"language-text\">Globals</code> class can be annotated as with fields. The console interface will treat any annotated fields on the <code class=\"language-text\">Globals</code> just like fields on the Model class itself.</p>\n<p>The <code class=\"language-text\">Globals</code> class is accessible to all agents within the system, however agents should <strong>not</strong> mutate (change) any fields in this object. Because agents operate in parallel, the results of agents modifying any information in the <code class=\"language-text\">Globals</code> class is undefined. Agents should instead contribute to global statistics either eagerly (through <code class=\"language-text\">Accumulators</code>) or lazily (through model-level queries into agent state).</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">final</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Globals</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">GlobalState</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token annotation punctuation\">@Input</span><span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"Update Frequency\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> updateFrequency <span class=\"token operator\">=</span> <span class=\"token number\">0.01</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Input</span><span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"Lambda\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> lambda <span class=\"token operator\">=</span> <span class=\"token number\">10</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Input</span><span class=\"token punctuation\">(</span>name <span class=\"token operator\">=</span> <span class=\"token string\">\"Volatility of Information Signal\"</span><span class=\"token punctuation\">)</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> volatilityInfo <span class=\"token operator\">=</span> <span class=\"token number\">0.001</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> informationSignal<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Note that informationSignal does not have an annotation. This field will be available inside the system and the agents, but will not be available on the console, or in any data export. The other fields are marked as <code class=\"language-text\">@Input</code>, allowing you to change these values from the console. These parameters are taken from the Rama Cont paper, and are used to tune the behaviour of the agents in the model. By using <code class=\"language-text\">Globals</code> these parameters can then be used by behaviours on the agents.</p>\n<div class=\"ui segment info message\" ><h4>Setting Globals During Setup</h4>\n<p>Globals allows you to define variables that can be accessed and modified by both the model and agents within the system. However, during the setup process when you are creating agents via an injector, you should not by modifying globals. This is due to Java 8 lambda's. If you wish to properly modify Globals, make sure it is part of the message passing action of an agent, or make usage of an accumulator.</p></div>\n<h3 id=\"accumulators\"><a href=\"#accumulators\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Accumulators</h3>\n<p>Accumulators can be thought of as named numeric counters that agents can read, add or remove from. As agents act in parallel, they will not see updates to the accumulator within a single phase (even their own), but every agent will see the same value of the counter on the next phase (with all changes to the accumulator from all agents summed together).</p>\n<p>Accumulators can be either <code class=\"language-text\">Long</code> (64bit integer) or <code class=\"language-text\">Double</code> (64bit floating point), created through <code class=\"language-text\">createLongAccumulator</code>/<code class=\"language-text\">createDoubleAccumulator</code>.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token function\">createLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"buys\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Number of buy orders\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">createLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"sells\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Number of sell orders\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">createDoubleAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"price\"</span><span class=\"token punctuation\">,</span> <span class=\"token string\">\"Price\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We have here created 3 accumulators, identified by a key, e.g. <code class=\"language-text\">buys</code>, and a friendly display name for the console, e.g. <code class=\"language-text\">Number of buy orders</code>. Note that the display name is optional, so you could have <code class=\"language-text\">createDoubleAccumulator(&quot;price&quot;)</code> if you were happy with that name appearing on the console.</p>\n<p>The <code class=\"language-text\">buys</code> and <code class=\"language-text\">sells</code> accumulators are used to report on when individual traders are buying and selling, while the <code class=\"language-text\">price</code> accumulator is used by the Market to report the changing price.</p>\n<h3 id=\"type-registration\"><a href=\"#type-registration\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Type registration</h3>\n<p>As part of initialisation, you also need to register all <code class=\"language-text\">Agent</code> and <code class=\"language-text\">Link</code> types that will be used in the simulation. This allows the SDK to properly handle and output data for these types, even if they might be created dynamically.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token function\">registerAgentTypes</span><span class=\"token punctuation\">(</span>Market<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> Trader<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">registerLinkTypes</span><span class=\"token punctuation\">(</span>Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In this model we have two agent types, and a single link type, as shown above. We'll see how these Agent and Link types are brought to life next, in setup.</p>\n<h2 id=\"setup\"><a href=\"#setup\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setup</h2>\n<h3 id=\"topology\"><a href=\"#topology\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Topology</h3>\n<p>Where <code class=\"language-text\">init</code> is concerned with declaring the component pieces of a model, the <code class=\"language-text\">setup</code> method is concerned with declaring an initial state for our model using those pieces. At the time that <code class=\"language-text\">setup</code> is called, a user on the console (or other client to the model) will have had the chance to change inputs and constants. The <code class=\"language-text\">setup</code> method can then take these inputs and customise the creation of the model accordingly.</p>\n<p>Creating the initial agents is done through the concept of a topology of groups. A group represents a parameterised set of agents, where each group has a type of agent, a number of agents in that group, and optionally an initialiser, which can customise the state for each agent.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\">Group<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Trader<span class=\"token punctuation\">></span></span> traderGroup <span class=\"token operator\">=</span> <span class=\"token function\">generateGroup</span><span class=\"token punctuation\">(</span>Trader<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> nbTraders<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nGroup<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Market<span class=\"token punctuation\">></span></span> marketGroup <span class=\"token operator\">=</span> <span class=\"token function\">generateGroup</span><span class=\"token punctuation\">(</span>Market<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">,</span> market <span class=\"token operator\">-</span><span class=\"token operator\">></span> market<span class=\"token punctuation\">.</span>nbTraders <span class=\"token operator\">=</span> nbTraders<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>In this model we have a group of traders, the size of which is taken as an input, and a group of markets, just the one. As part of its logic, the Market also needs to know how many traders there are. We could place this information into the <code class=\"language-text\">Globals</code>, however as it doesn't change then we can place it directly into the market. This also allows a possible extension later, where the Market can maintain this information itself, should we make the number of traders dynamic. We use a Java lambda function, which takes the created market and updates its attribute.</p>\n<p>We're programmatically defining agents here, as it's quick to get started, but you can also load groups from external data sources.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\">traderGroup<span class=\"token punctuation\">.</span><span class=\"token function\">fullyConnected</span><span class=\"token punctuation\">(</span>marketGroup<span class=\"token punctuation\">,</span> Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nmarketGroup<span class=\"token punctuation\">.</span><span class=\"token function\">fullyConnected</span><span class=\"token punctuation\">(</span>traderGroup<span class=\"token punctuation\">,</span> Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With the groups in place, we now need to give them knowledge of each other. This is done through links, which represent knowledge agents have of other agents. In the simple case, the link itself has no attributes, which means it simply represents knowledge that another agent exists. Here we use a pre-defined connector, which gives every agent in that group a link to every agent to the target group. There are many other strategies for linking agents together, including loading from data sources, detailed in the reference on <a href=\":version/reference/agents/topologies\">topologies</a>.</p>\n<p>Here we give each trader a link to the market, and the market links to all traders. Links are unidirectional, and only visible to the originating group.</p>\n<h3 id=\"global-information-update\"><a href=\"#global-information-update\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Global Information Update</h3>\n<p>In this model, there is a global information signal, which is drawn from a gaussian distribution, parameterised on its variance by the volatilityInfo global <code class=\"language-text\">@Input</code>. As this needs to be initialised at setup, and at each step of the model, we pull that logic out into a separate method, and then call it within both <code class=\"language-text\">setup</code> and <code class=\"language-text\">step</code>.</p>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">private</span> <span class=\"token keyword\">void</span> <span class=\"token function\">updateSignal</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>informationSignal <span class=\"token operator\">=</span>\n      <span class=\"token function\">getContext</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getPrng</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">gaussian</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>volatilityInfo<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sample</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We use the PRNG from our models context to sample from a gaussian distribution. Using the context means our PRNG seed can be controlled automatically by the Simudyne SDK, allowing for guarantees around reproducibility.</p>\n<h3 id=\"super\"><a href=\"#super\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Super</h3>\n<p>A vital final part of <code class=\"language-text\">setup</code> is to call <code class=\"language-text\">super.setup()</code>. This tells the underlying system to actually initialise and setup the topology we have described. Usually this will be the last part of your setup method, however a useful pattern can be to call <code class=\"language-text\">step</code> at the final part of <code class=\"language-text\">setup</code>. This runs the model forward a step, and can be very useful to avoid a jump on a chart for example, should the agents need to run forwards initially to produce sensible values.</p>\n<h2 id=\"step\"><a href=\"#step\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Step</h2>\n<p>Step is called once every time the model is run forwards a step. Step takes care of the logic that happens between each tick, in an ABM this is mostly concerned with running behavioural sequences over the system to move the system forwards through time.</p>\n<h3 id=\"super-1\"><a href=\"#super-1\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Super</h3>\n<p>The start of <code class=\"language-text\">step</code> calls <code class=\"language-text\">super.step</code>, signalling to the system that another step is beginning. This performs general lifecycle hooks necessary for agents, and other tasks such as resetting any non-persistent accumulators back to <code class=\"language-text\">0</code>.</p>\n<h3 id=\"run-sequences\"><a href=\"#run-sequences\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Run Sequences</h3>\n<p class=\"code-header\">TradingModel.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token function\">updateSignal</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">run</span><span class=\"token punctuation\">(</span>Trader<span class=\"token punctuation\">.</span><span class=\"token function\">processInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Market<span class=\"token punctuation\">.</span><span class=\"token function\">calcPriceImpact</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> Trader<span class=\"token punctuation\">.</span><span class=\"token function\">updateThreshold</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>As mentioned before, this is also the time to update our information signal. Along with that, we run a <a href=\":version/reference/agents/actions-and-sequencing\">sequence of actions</a>. In this model, this consists of running the <code class=\"language-text\">Trader#processInformation</code>m <code class=\"language-text\">Market#calcPriceImpact</code> and <code class=\"language-text\">Trader#updateThreshold</code> actions in sequence. The general idea is that this allows all traders to run <code class=\"language-text\">processInformation</code>, and then any markets that receive message will get to process during the <code class=\"language-text\">calcPriceImpact</code>, and again any traders receiving information from the market will get to update. We'll look at these behaviours in depth soon.</p>\n<p>The important thing to note above is that <strong>only agents that receive messages get to act</strong>. The first action in any sequence is special, as at that point every agent gets to act (otherwise no agent would ever get to act, which would be unfortunate).</p>\n<h2 id=\"behaviours\"><a href=\"#behaviours\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Behaviours</h2>\n<p>We'll run through the actions in this sequence in order, to see how they progress. When we see each agent for the first time, we'll also have a quick look at how it's defined.</p>\n<h3 id=\"traderprocessinformation\"><a href=\"#traderprocessinformation\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Trader#processInformation</h3>\n<p class=\"code-header\">Trader.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token annotation punctuation\">@Variable</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> tradingThresh<span class=\"token punctuation\">;</span>\n\n<span class=\"token annotation punctuation\">@Override</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  tradingThresh <span class=\"token operator\">=</span> <span class=\"token function\">getPrng</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">gaussian</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sample</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Our Trader is defined as an agent, which has a <code class=\"language-text\">tradingThreshold</code>. This trading threshold is initialised separately per agent, through its own <code class=\"language-text\">init</code> method, drawing their initial threshold from a gaussian of mean = 1, standard deviation = 1. Each agent has their own PRNG, available through <code class=\"language-text\">getPrng()</code>, which is similarly carefully controlled by the Simudyne SDK to be a good source of randomness, and controllable for repeatability.</p>\n<p class=\"code-header\">Trader.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> Action<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Trader<span class=\"token punctuation\">></span></span> <span class=\"token function\">processInformation</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token function\">action</span><span class=\"token punctuation\">(</span>\n      trader <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">double</span> informationSignal <span class=\"token operator\">=</span> trader<span class=\"token punctuation\">.</span><span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>informationSignal<span class=\"token punctuation\">;</span>\n\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>Math<span class=\"token punctuation\">.</span><span class=\"token function\">abs</span><span class=\"token punctuation\">(</span>informationSignal<span class=\"token punctuation\">)</span> <span class=\"token operator\">></span> trader<span class=\"token punctuation\">.</span>tradingThresh<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>informationSignal <span class=\"token operator\">></span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            trader<span class=\"token punctuation\">.</span><span class=\"token function\">buy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            trader<span class=\"token punctuation\">.</span><span class=\"token function\">sell</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Our action is a function that operates on a given trader. In this models formulation, each agent observes the global information signal. If the signal is above their threshold (either higher or lower) then the agent executes a buy or sell trade, depending on if the signal is negative or positive.</p>\n<p class=\"code-header\">Trader.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">private</span> <span class=\"token keyword\">void</span> <span class=\"token function\">buy</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">getLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"buys\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">getLinks</span><span class=\"token punctuation\">(</span>Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>BuyOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">private</span> <span class=\"token keyword\">void</span> <span class=\"token function\">sell</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">getLongAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"sells\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">getLinks</span><span class=\"token punctuation\">(</span>Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>SellOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>These helper methods pull the logic of the trader out, so they are easier to see in isolation, separate from the logic of whether it is a buy or sell that is executed. In each case, we update the global information on buys or sells occuring. We then also send the actual message through to the market. We do this by selecting our links (knowing that the only <code class=\"language-text\">TradeLink</code> the trader has is to the market), and send a message along that link.</p>\n<p class=\"code-header\">Messages.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">BuyOrderPlaced</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Message<span class=\"token punctuation\">.</span>Empty</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span>\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">SellOrderPlaced</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Message<span class=\"token punctuation\">.</span>Empty</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>These message are empty messages, as defined in the <code class=\"language-text\">Messages</code> container class, serving as signal messages to the market. In a more elaborate model you could add properties to these messages, indicating the amount to buy, at what price, etc.</p>\n<h3 id=\"marketcalcpriceimpact\"><a href=\"#marketcalcpriceimpact\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Market#calcPriceImpact</h3>\n<p class=\"code-header\">Market.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">Market</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Agent</span><span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>TradingModel<span class=\"token punctuation\">.</span>Globals<span class=\"token punctuation\">></span></span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token annotation punctuation\">@Variable</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">double</span> price <span class=\"token operator\">=</span> <span class=\"token number\">4.0</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">int</span> nbTraders<span class=\"token punctuation\">;</span>\n\n  <span class=\"token keyword\">private</span> <span class=\"token keyword\">static</span> Action<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Market<span class=\"token punctuation\">></span></span> <span class=\"token function\">action</span><span class=\"token punctuation\">(</span>SerializableConsumer<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Market<span class=\"token punctuation\">></span></span> consumer<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> Action<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>Market<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> consumer<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> Action<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Market<span class=\"token punctuation\">></span></span> <span class=\"token function\">calcPriceImpact</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">return</span> <span class=\"token function\">action</span><span class=\"token punctuation\">(</span>\n        market <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n          <span class=\"token keyword\">int</span> buys <span class=\"token operator\">=</span> market<span class=\"token punctuation\">.</span><span class=\"token function\">getMessagesOfType</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>BuyOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token keyword\">int</span> sells <span class=\"token operator\">=</span> market<span class=\"token punctuation\">.</span><span class=\"token function\">getMessagesOfType</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>SellOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">size</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n          <span class=\"token keyword\">int</span> netDemand <span class=\"token operator\">=</span> buys <span class=\"token operator\">-</span> sells<span class=\"token punctuation\">;</span>\n\n          <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>netDemand <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n            market<span class=\"token punctuation\">.</span><span class=\"token function\">getLinks</span><span class=\"token punctuation\">(</span>Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>MarketPriceChange<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span> <span class=\"token keyword\">else</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">double</span> lambda <span class=\"token operator\">=</span> market<span class=\"token punctuation\">.</span><span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>lambda<span class=\"token punctuation\">;</span>\n            <span class=\"token keyword\">double</span> priceChange <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>netDemand <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">double</span><span class=\"token punctuation\">)</span> market<span class=\"token punctuation\">.</span>nbTraders<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> lambda<span class=\"token punctuation\">;</span>\n            market<span class=\"token punctuation\">.</span>price <span class=\"token operator\">+=</span> priceChange<span class=\"token punctuation\">;</span>\n\n            market<span class=\"token punctuation\">.</span><span class=\"token function\">getDoubleAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"price\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">.</span>price<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            market\n                <span class=\"token punctuation\">.</span><span class=\"token function\">getLinks</span><span class=\"token punctuation\">(</span>Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span>\n                <span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>MarketPriceChange<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">,</span> priceChange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n          <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The Market is solely defined by two fields (one a reported <code class=\"language-text\">@Variable</code>) and single action, and this is shown in full above (less imports). Again the behaviour is represented as a function of the market. This time we pull out the trade messages the market has received. In this formulation from the paper, the net demand (difference in buys and sells) is used to calculate an impact on the price. The resulting <em>change</em> in the price is then sent to all agents (remembering the Market is fully connected to all traders) using a <code class=\"language-text\">MarketPriceChange</code> message.</p>\n<p class=\"code-header\">Messages.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MarketPriceChange</span> <span class=\"token keyword\">extends</span> <span class=\"token class-name\">Message<span class=\"token punctuation\">.</span>Double</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>The message itself is defined similarly as before. This time however, it extends a helper class <code class=\"language-text\">Message.Double</code>, which represents a message containing a single <code class=\"language-text\">double</code> (64 bit floating point) variable.</p>\n<h3 id=\"traderupdatethreshold\"><a href=\"#traderupdatethreshold\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Trader#updateThreshold</h3>\n<p class=\"code-header\">Trader.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">boolean</span> <span class=\"token function\">shouldUpdateThreshold</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">double</span> updateFrequency <span class=\"token operator\">=</span> <span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>updateFrequency<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">return</span> <span class=\"token function\">getPrng</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">uniform</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">sample</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">&lt;=</span> updateFrequency<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> Action<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>Trader<span class=\"token punctuation\">></span></span> <span class=\"token function\">updateThreshold</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token function\">action</span><span class=\"token punctuation\">(</span>\n      trader <span class=\"token operator\">-</span><span class=\"token operator\">></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>trader<span class=\"token punctuation\">.</span><span class=\"token function\">shouldUpdateThreshold</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n          trader<span class=\"token punctuation\">.</span>tradingThresh <span class=\"token operator\">=</span>\n              trader<span class=\"token punctuation\">.</span><span class=\"token function\">getMessageOfType</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>MarketPriceChange<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">getBody</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n        <span class=\"token punctuation\">}</span>\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>The traders then receive the change in the price. Depending on some update frequency (defined globally), the trader will update its threshold to be equal to the change in the price.</p>\n<h2 id=\"tests\"><a href=\"#tests\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tests</h2>\n<p>Using the Simudyne TestKit, we have created the following tests to check the behavior of the trader and market is as required. To read more about the TestKit and how you can use it to test the actions you created in your models, see <a href=\":version/reference/test_kit\">Test Kit</a>.</p>\n<p>TestKit (and unit testing in general) helps to confirm that small units of logic are correct, so that building larger models from smaller tested componients is easier.</p>\n<p class=\"code-header\">MarketTest.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\"><span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">MarketTest</span> <span class=\"token punctuation\">{</span>\n\n  <span class=\"token keyword\">private</span> TestKit<span class=\"token generics function\"><span class=\"token punctuation\">&lt;</span>TradingModel<span class=\"token punctuation\">.</span>Globals<span class=\"token punctuation\">></span></span> testKit<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">private</span> Market market<span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">static</span> <span class=\"token keyword\">final</span> <span class=\"token keyword\">int</span> TARGET_LINK_ID <span class=\"token operator\">=</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n\n  <span class=\"token annotation punctuation\">@Before</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">init</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    testKit <span class=\"token operator\">=</span> TestKit<span class=\"token punctuation\">.</span><span class=\"token function\">create</span><span class=\"token punctuation\">(</span>TradingModel<span class=\"token punctuation\">.</span>Globals<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    market <span class=\"token operator\">=</span> testKit<span class=\"token punctuation\">.</span><span class=\"token function\">addAgent</span><span class=\"token punctuation\">(</span>Market<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">createDoubleAccumulator</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"price\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    market<span class=\"token punctuation\">.</span><span class=\"token function\">addLink</span><span class=\"token punctuation\">(</span>TARGET_LINK_ID<span class=\"token punctuation\">,</span> Links<span class=\"token punctuation\">.</span>TradeLink<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token comment\">// ...</span></code></pre></div>\n<p>In our Market tests, we setup a helper <code class=\"language-text\">init</code> method, which is run <code class=\"language-text\">@Before</code> all tests. This creates a new testing model environment, adds a single agent, accumulator, and a testing link.</p>\n<p class=\"code-header\">MarketTest.java</p>\n<div class=\"gatsby-highlight\" data-language=\"java\"><pre class=\"language-java\"><code class=\"language-java\">  <span class=\"token comment\">// ...</span>\n\n  <span class=\"token annotation punctuation\">@Test</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">should_handle_zero_netDemand</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>BuyOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">to</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>SellOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">to</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    TestResult testResult <span class=\"token operator\">=</span> testKit<span class=\"token punctuation\">.</span><span class=\"token function\">testAction</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">,</span> Market<span class=\"token punctuation\">.</span><span class=\"token function\">calcPriceImpact</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    Messages<span class=\"token punctuation\">.</span>MarketPriceChange expectedMessage <span class=\"token operator\">=</span>\n        testResult<span class=\"token punctuation\">.</span><span class=\"token function\">getMessagesOfType</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>MarketPriceChange<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">assertEquals</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> expectedMessage<span class=\"token punctuation\">.</span><span class=\"token function\">getBody</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n\n  <span class=\"token annotation punctuation\">@Test</span>\n  <span class=\"token keyword\">public</span> <span class=\"token keyword\">void</span> <span class=\"token function\">should_handle_priceChange</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token comment\">// Two buys and one sell makes a netDemand of 1</span>\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>BuyOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">to</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>BuyOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">to</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    testKit<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>SellOrderPlaced<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">to</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">double</span> startingPrice <span class=\"token operator\">=</span> market<span class=\"token punctuation\">.</span>price<span class=\"token punctuation\">;</span>\n\n    TestResult testResult <span class=\"token operator\">=</span> testKit<span class=\"token punctuation\">.</span><span class=\"token function\">testAction</span><span class=\"token punctuation\">(</span>market<span class=\"token punctuation\">,</span> Market<span class=\"token punctuation\">.</span><span class=\"token function\">calcPriceImpact</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    Messages<span class=\"token punctuation\">.</span>MarketPriceChange expectedMessage <span class=\"token operator\">=</span>\n        testResult<span class=\"token punctuation\">.</span><span class=\"token function\">getMessagesOfType</span><span class=\"token punctuation\">(</span>Messages<span class=\"token punctuation\">.</span>MarketPriceChange<span class=\"token punctuation\">.</span><span class=\"token keyword\">class</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">get</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token keyword\">double</span> expectedPriceChange <span class=\"token operator\">=</span>\n        <span class=\"token punctuation\">(</span><span class=\"token number\">1</span> <span class=\"token operator\">/</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">double</span><span class=\"token punctuation\">)</span> testKit<span class=\"token punctuation\">.</span><span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>nbTraders<span class=\"token punctuation\">)</span> <span class=\"token operator\">/</span> testKit<span class=\"token punctuation\">.</span><span class=\"token function\">getGlobals</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span>lambda<span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">assertEquals</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">,</span> expectedMessage<span class=\"token punctuation\">.</span><span class=\"token function\">getBody</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span> startingPrice <span class=\"token operator\">+</span> expectedPriceChange<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>We then define two test cases, once for the case of there being no net demand, and the other for there being a net demand of 1 (2 - 1). In each case, we check that the sent price change (out of our test result) equals the right value. In the future, when we make changes, if this logic should break, then this test will start failing. When using the build command at the start (<code class=\"language-text\">mvn package exec:java</code>) the tests will be automatically run each time.</p>\n<p>The tests for the trader proceed similarly, testing their behaviour in regards to the information signal.</p>\n<h1 id=\"summary\"><a href=\"#summary\" aria-hidden=\"true\" class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h1>\n<p>Through this tutorial we have walked through the initial features to get started with, both on the console and in the definition of the models themselves. The next tutorial, based around building a model of mortgages issued by banks, goes much further into more advanced behaviours, as well as through the initial model building steps, when starting from scratch.</p>","headings":[{"value":"Console","depth":2},{"value":"Project Structure","depth":2},{"value":"Project configuration and documentation","depth":3},{"value":"Model definition","depth":3},{"value":"Model testing","depth":3},{"value":"Model","depth":1},{"value":"Initialisation","depth":2},{"value":"Model Fields","depth":3},{"value":"Globals","depth":3},{"value":"Accumulators","depth":3},{"value":"Type registration","depth":3},{"value":"Setup","depth":2},{"value":"Topology","depth":3},{"value":"Global Information Update","depth":3},{"value":"Super","depth":3},{"value":"Step","depth":2},{"value":"Super","depth":3},{"value":"Run Sequences","depth":3},{"value":"Behaviours","depth":2},{"value":"Trader#processInformation","depth":3},{"value":"Market#calcPriceImpact","depth":3},{"value":"Trader#updateThreshold","depth":3},{"value":"Tests","depth":2},{"value":"Summary","depth":1}],"frontmatter":{"title":"Synthetic Market Tutorial","toc":true,"experimental":null}},"site":{"siteMetadata":{"title":"Simudyne Docs","latestVersion":"2.6"}}},"pageContext":{"absolutePath":"/home/vsts/work/1/s/content/2.4/docs/tutorials/trader.md","versioned":true,"version":"2.4","kind":"docs","pagePath":"/tutorials/trader","chronology":{"prev":{"name":"Tutorials","path":"/tutorials"},"next":{"name":"Mortgage Portfolio Tutorial","path":"/tutorials/mortgage"}},"lastUpdated":"2026-04-21T13:56:54.849Z"}}