No preview image

1 collaborator

Default-person Andrew Deitch (Author)


(This model has yet to be categorized with any tags)
Model group EECS 372-Spring 2011 | Visible to everyone | Changeable by the author
Model was written in NetLogo 4.1.3 • Viewed 226 times • Downloaded 14 times • Run 10 times
Download the 'Deitch_Andrew_Trading' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


This is a simplified model of stock trading. In the model, agents take turns pairing up and trading stocks. Each agent has beliefs about how much the stock is worth, in addition to knowledge of the last price it sold for. A simple set of rules determines whether the agents sell stocks to one another on a given turn, and the selling price. The goal to see what kinds of endogenous conditions can cause extreme variation in the stock price. In real life, these extreme variations are sometimes called stock bubbles. Therefore, almost all fluctuation in the stock price is due to agents reacting to each other's actions, and to movements and patterns that the agents detect in the price itself. The exception to this rule is the 'news' feature, which is the only "outside" mechanism affecting the stock price. As agents trade with each other turn by turn, they constantly update their individual beliefs about the stock price.

This model attempts to examine how a stock price can change based only on the aggregate effects of individual interactions. In real markets, a bubble and the subsequent crash are usually attributed to some combination of speculation, misinformation, and cognitive bias. The implicit assumption is that when the price quickly rises by one hundred percent or more, and then falls rapidly to the original level or below, this rapid and extreme fluctuation represents a false belief about what the asset is "really" worth. Famous bubbles include the recent housing bubble, but there are examples reaching as far back as the 18th century South Sea Shipping Company stock bubble. People scoff at those caught up in the speculation, wondering how--knowing what they know about markets--anyone could honestly think the asset's value could rise so quickly and dramatically. But if people are not using outside information about the world to determine what the asset worth in comparison to other assets, how does the price change so much? Modern behavioral economists attribute much of this speculative behavior to groupthink, bandwagon effects, endowment effects, and other cognitive biases. This model asks whether these extreme price fluctuations can be replicated using endogenous factors that imitate real-life cognitive biases.


During set-up, each agent is given some shares, some money, a price (the price they currently believe the stock to be worth), and a news-sensitivity.

The action of the model takes place during trading turns. At the beginning of each turn, each agent creates a link with another agent how has not yet traded for that turn. Then, the agents attempt to trade with one another. One agent (randomly chosen from the pair) offers to buy one share from the other agent.

Rules for trading:

If both agents have at least one share and sufficient money to trade, then

1. The offering agent offers to buy a share for his price (my-price).

2. If the offering agent's price is higher than his partner's price, the offering agent exchanges money (equal the offering price) for a share of the trade partner's stock.

3. If the offering agent's price is lower than his partner's price, the partner counters, offering $1 more than the original offer, and exchanges his money for one share of the offering agent's stock.

4. If both agents have the same my-price, no shares are exchanged.

5. Both agents set their traded? value to true for this turn.

After each transaction, the stock-price is updated to reflect the latest sale price. Once all the pairs have finished trading, the links are broken, all agents set their traded? values to false, and a new round is begun.

When agents are not trading, they observe the stock-price's movement and use it, as well as other information, to update their my-price value. As many agents constantly update their beliefs about what the stock is worth, different fluctuation patterns in stock-price patterns emerge.

Rules for updating my-price:

1. If the endowment effect is turned on (endowment-effect? = true), agents have a certain (user-selected) probability of refusing to trade for a given turn.

2. If news is turned on (react-to-news? = true), adjust my-price up or down depending on the magnitude of the news and my news-sensitivity.

3. If the agents are trying to spot trends (apparent-trends? = true), adjust my-price upward if the stock-price has risen several times in a row and down if the stock-price has fallen several times in a row.

4. If the bandwagon effect is turned on (bandwagon-effect? = true), then some turtles will pick another turtle to set their my-price equal to.


The setup button creates the specified number of turtles. do-layout? and show-my-price? are optional settings that can be turned on to improve the model's animation, or turned off to increase running speed. do-layout? shows the turtles moving around the view as they pair up and trade. show-my-price? creates a label displaying each individual turtle's my-price.

The population slider specifies the number of turtles created at setup. The switches react-to-news?, apparent-trends?, endowment-effect?, and bandwagon-effect? each control a different strategy that the turtles use to update their my-price as they trade. These switches can all be turned on, or they can be turned on in any combination to observe the different effects. See the HOW IT WORKS section and the procedures tab for more information about these strategies.

Each strategy switch, other than react-to-news?, has a corresponding slider to control the strength of its effect:

- trend-spotting-prob determines the probability that a given agent will notice each trend.

- endowment-frequency determines how often an agent will refuse to trade in a each trading round

- bandwagon-stength determines how likely it is that an agent sets his my-price equal to another agent's my-price in a given trading turn.

The share-distribution plot gives a histogram plotting the number of turtles possessing a given number of shares.


There are two main ways to judge what is going on in the model. First, there is the share distribution plot. This plot shows how evenly distributed the shares are across all the people in the model. Most sets of parameters tend toward a very uneven distribution - many people with no shares and a few with most of the shares.

Second, there is the stock price plot. It is easy to judge visually when something that could be characterized as a bubble has occurred. Notice that, as in real life, it is only possible to define a give time span as a bubble after it has 'burst.'


See what happens to the stock-price and the share-distribution as you turn on different combinations of switches. For each effect, try moving the sliders for a strong effect or a weak effect.

For a more stable stock-price, try turning on only react-to-news? and bandwagon-effect?

To see some big fluctuations that look like bubbles, try turning on only react-to-news? and apparent-trends? and setting trend-spotting-prob around the mid-range.


This model assumes some fixed values for the magnitudes of agents' my-price adjustments. To make the model more realistic, try having the agents react in percentages of the stock price, rather than in fixed dollar amounts.

Also, the model sometimes allows the stock price to fall below zero. This does not present a problem for analyzing price fluctuations, but for aesthetic purposes, try preventing the stock price from falling below zero.

Currently, some of the global variables can only be adjusted in the procedures tab. Sliders for money, my-price, and news-sensitivity could be added. I refrained from adding this to keep the model simpler.


To implement trend-spotting by the agents, I needed them to have a 'memory' of the stock-price movement. This is the list up-down-history. It keeps track of whether the stock-price goes up or down at each trade. The agents use this list to react to trends. To analyze the results of the model in BehaviorSpace, I also needed a history of the actual prices. This is the list price-history. After each trade, the stock-price is recorded in this list.


This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


Thanks to Forrest and Winston for all help, both with programming problems and modeling decisions.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [shares money my-price news-sensitivity traded?]
globals [ stock-price up-down-history price-history]

to setup
  set-default-shape turtles "Person"
  crt population
  ask turtles [
    set xcor random-xcor
    set ycor random-ycor
    set shares 1
    set money 10000
    set my-price 50 + random 30
    set news-sensitivity random-normal 1 0
  set stock-price mean [my-price] of turtles
  set up-down-history n-values 10 [0]
  set price-history []
  if show-my-price? [
    ask turtles [set label my-price]

to go
  ask turtles [ set traded? false ]
  ;;find a partner for this round
  ask turtles [pair-up]
  ;;if layout animation is on, move toward your partner
  if do-layout? [
    repeat 20 [layout-spring turtles links .1 .5 .1] 
  ;;trade for this round
  ask turtles [
    ;;if the endowment-effect is on, some turtles will refuse to trade each turn
    if endowment-effect? [
      if random 100 < endowment-frequency [
        set traded? true
    ask other turtles [ update-my-price ]
  ask links [die]

to pair-up
  if count link-neighbors = 0 [
    create-link-with one-of other turtles with [
    count link-neighbors = 0] [set color red]

to trade 
  if not traded? [
    ;;do the transaction
    let trade-partner one-of link-neighbors
    let offer-price my-price
    let counter-price [my-price] of trade-partner
    ;;if your offer is higher than partner's price, 
    ;;and you have at least one share,
    ;;you try to sell to your partner
    if offer-price > counter-price [
      ask trade-partner [ try-to-sell-to myself offer-price ]
    ;;if your offer is lower than partner's price, 
    ;;your partner tries to sell to you
    if offer-price + 1 <= counter-price [
      try-to-sell-to trade-partner (offer-price + 1)
    ;;if offer-price = counter-price, no shares exchanged
    ;;each turtle can only trade once per round
    ;;then, they must form new links with new trade-partners
    set traded? true
    ask link-neighbors [ set traded? true ]

;;general selling procedure, the turtle with the 
;;lower price tries to sell to his trade partner

to try-to-sell-to [ buyer buying-price ]
  if shares > 0 [
    if [money] of buyer > buying-price [
      set money money + buying-price
      set shares shares - 1
      ask buyer [ set money money - buying-price ]
      ask buyer [ set shares shares + 1 ]
      ;;create a list reflecting the movement of the stock-price
      if buying-price > stock-price [
        set up-down-history fput 1 up-down-history
      if buying-price < stock-price [
        set up-down-history fput -1 up-down-history
      if buying-price = stock-price [
        set up-down-history fput 0 up-down-history
      if length up-down-history > 100 [
        set up-down-history sublist up-down-history 0 99
      ;;each time a transaction happens, the stock-price is updated
      set stock-price buying-price
      set price-history fput stock-price price-history
  ;    do-plots

to update-my-price
  if stock-price < 1 [
    set my-price my-price + 1
  if react-to-news? [
    let good-news random 5
    let bad-news random -5 
    let news good-news + bad-news
    set my-price my-price + news * news-sensitivity 
  if apparent-trends? [
    let last5 sublist up-down-history 0 5
    let last10 sublist up-down-history 0 10
    if sum last5 = 5 [
      if random 100 < trend-spotting-prob [
        set my-price my-price + 5
    if sum last5 = -5 [
      if random 100 < trend-spotting-prob [ 
        set my-price my-price - 5
    ;;put some downward pressure on the price if it is stagnant
    if mean last10 = 0 [
      if random 100 < trend-spotting-prob [ 
        set my-price my-price - 1
  if bandwagon-effect? [
    let neighbor-price [my-price] of one-of other turtles
    if random 100 < bandwagon-strength [
    set my-price neighbor-price 

to do-plots
  set-current-plot "current-price"
  set-current-plot-pen "Price" 
  plot stock-price 
  set-current-plot "share-distribution"
  set-current-plot-pen "default"
  histogram [shares] of turtles   

There are 15 versions of this model.

Uploaded by When Description Download
Andrew Deitch almost 8 years ago Spell checked info tab Download this version
Andrew Deitch almost 8 years ago With more cosmetic changes Download this version
Andrew Deitch almost 8 years ago With cosmetic changes Download this version
Andrew Deitch almost 8 years ago with procedure comments Download this version
Andrew Deitch almost 8 years ago with information tab Download this version
Andrew Deitch almost 8 years ago With biases Download this version
Andrew Deitch almost 8 years ago With switches for trends and news, and more realistic price fluctuation. Download this version
Andrew Deitch almost 8 years ago With agents able to spot and react to 'trends' and 'good' or 'bad' news by adjusting their prices Download this version
Andrew Deitch almost 8 years ago More efficient trading procedure, generalized to both possible trading outcomes Download this version
Andrew Deitch almost 8 years ago With plots, floating stock prices, and random price fluctuation Download this version
Andrew Deitch almost 8 years ago Updated version, with links and trading procedures in place, and preliminary stock-price-monitor Download this version
Andrew Deitch almost 8 years ago Updated version, with links and trading in place Download this version
Andrew Deitch almost 8 years ago Updated version, with links instead of patch-based pairings Download this version
Andrew Deitch almost 8 years ago No description provided Download this version
Andrew Deitch almost 8 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.