<p><a href="https://www.jstor.org/stable/2138676?seq=1" rel="nofollow noreferrer">Gode and Sunder (1993)</a> recorded a result similar to yours. The abstract of the paper reads:</p>
<blockquote>
<p>We report market experiments in which human traders are replaced by &quot;zero-intelligence&quot; programs that submit random bids and offers. Imposing a budget constraint (i.e., not permitting traders to sell below their costs or buy above their values) is sufficient to raise the allocative efficiency of these auctions close to 100 percent. Allocative efficiency of a double auction derives largely from its structure, independent of traders' motivation, intelligence, or learning. Adam Smith's invisible hand may be more powerful than some may have thought; it can generate aggregate rationality not only from individual rationality but also from individual irrationality.</p>
</blockquote>
<p>Specifically, Gode and Sunder consider two algorithms of trade. The first algorithm generates bids and asks from a uniform distribution on a fixed interval, say <span class="math-container">$[L,U]$</span>, irrespective of the traders' reservation values. The authors refer to these traders as unconstrained zero intelligence (ZI-U) traders. In the second algorithm, bids are drawn from <span class="math-container">$\mathrm{unif}[L,v]$</span> and asks are drawn from <span class="math-container">$\mathrm{unif}[c,U]$</span>, where <span class="math-container">$v,c$</span> are the reservation values for buyers and sellers respectively. The traders following this second algorithm are referred to as constrained zero intelligence (ZI-C) traders.</p>
<p>The following figure (along with several others in the paper with different market parameters) shows that ZI-U traders generate more sustained price volatility than ZI-C traders, who in turn resemble human traders in the same market condition. So I suspect that the sustained volatility you observed in your code was due to the fact that you used uniform bounds on the random bid/ask generation instead of imposing a budget constraint for the traders.</p>
<p><a href="https://i.sstatic.net/rVEK2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rVEK2.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-02-10T21:23:49.927Z
Thanks, I appreciate this reference! (I found Smith's paper mentioned in my econ 101 textbook without any reference to other literature since then, and I am too much of an econ noob to quickly find the relevant papers.)
IssaRice
CC BY-SA 4.0
2021-02-10T22:32:19.070Z
@riceissa: You're welcome. You may also refer to Duffy's [chapter in the *Handbook of Computational Economics*](https://www.sciencedirect.com/science/article/pii/S1574002105020198) for other related developments in the literature.
Herr K.
CC BY-SA 4.0
2021-02-09T15:43:50.383Z
2021-02-10T22:34:38.453Z
2021-02-10T22:34:38.453Z
Herr K.
<p>Smith's human traders adapted their behavior, learning from experience between successive market periods, which is another reason why their transaction-price time-series is so much smoother than yours (or Gode &amp; Sunder's ZIC results).</p>
<p>For a free open-source detailed Python simulation of a financial exchange populated with traders that do adapt over time, learning from experience, see:</p>
<p><a href="https://github.com/davecliff/BristolStockExchange/wiki" rel="nofollow noreferrer">https://github.com/davecliff/BristolStockExchange/wiki</a></p>
<p>Especially the Jupyter notebook here, which is a walkthrough of recreating Smith's 1962 results (his <em>Chart 1</em> graph) with simulated traders:</p>
<p><a href="https://github.com/davecliff/BristolStockExchange/blob/master/BSE_VernonSmith1962_demo.ipynb" rel="nofollow noreferrer">https://github.com/davecliff/BristolStockExchange/blob/master/BSE_VernonSmith1962_demo.ipynb</a></p>

CC BY-SA 4.0
2022-10-17T18:43:32.467Z
2022-10-17T18:43:32.467Z
Dave Cliff
<p>I suspect that the reason for that result is the way how you modeled the situation is by having the prices to be offered at random from a sample of numbers in uniform fashion (unless I am misreading the code) but this is unrealistic.</p>
<p>As mentioned in the paper Smith's 1962:</p>
<blockquote>
<p>each sequence of experiments was conducted over sequences five to ten minutes long</p>
</blockquote>
<p>So the students had only 5-10 minutes to actually conclude the trades. Students knew their own valuation of the item and they wanted to get it.</p>
<p>In such situation it is not in students interest to just choose random price from the sample of prices. Rather students will be choosing from some distribution that will have more mass closer to the their own valuation.</p>
<p>My prediction is that if instead of random sampling of prices from the array you will let the program generate numbers from some distribution that has more mass closer to the right price you will see less volatility in the data.</p>
<p>For example, instead of using <code>random.choice(price_deltas)</code> you could use <code>random.choice(price_deltas, p=weights)</code> that allows you to assign weights to numbers so some are more likely than others.</p>
<hr />
<p>EDIT:</p>
<p>You could use the weight approach above but I also discovered much simpler one. If you are just fine assuming prices can be continuous (which from point of economic theory is fine 0.01c is really just practical limit in real life), then what you can do is skip the creation of deltas at the start:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
buyers = [3.25 - 0.25*n for n in range(0, 11)]
sellers = [3.25 - 0.25*n for n in range(0, 11)] 
</code></pre>
<p>Next what you can do is to replace <code>random.choice()</code> with some distribution that has most mass at zero - like the <a href="https://en.wikipedia.org/wiki/Wrapped_exponential_distribution" rel="nofollow noreferrer">exponential distribution</a>. In python this can be done using <code>random.exponential()</code>, the code would thus change only minimally, and will generate deltas that are closer to the actual valuation of the traders:</p>
<pre><code>trading_prices = []
trading_counts = []

for _ in range(5):
    buyers_still_in_market = list(range(len(buyers)))
    sellers_still_in_market = list(range(len(sellers)))

    transactions = []

    for _ in range(1000):
        # First, a random buyer offers to buy at some price below their number on
        # their card
        b = np.random.choice(buyers_still_in_market)
        delta = np.random.exponential(400)
        buyer_price = max(0, buyers[b] - abs(delta))
        s = np.random.choice(sellers_still_in_market)
        if buyer_price &gt;= sellers[s]:
            transactions.append((b, buyers[b], s, sellers[s], buyer_price))
            buyers_still_in_market.remove(b)
            sellers_still_in_market.remove(s)
            trading_prices.append(buyer_price)

        # Then, a random seller offers to sell at some price above their number on
        # their card. #0.65 - for log normal
        s = np.random.choice(sellers_still_in_market)
        delta = np.random.exponential(400)
        seller_price = sellers[s] + abs(delta)
        b = np.random.choice(buyers_still_in_market)
        if seller_price &lt;= buyers[b]:
            transactions.append((b, buyers[b], s, sellers[s], seller_price))
            buyers_still_in_market.remove(b)
            sellers_still_in_market.remove(s)
            trading_prices.append(seller_price)

    trading_counts.append(len(trading_prices))

    print(len(transactions), &quot;transactions&quot;)

plt.plot(list(range(len(trading_prices))), trading_prices)
plt.ylim(0, 4.00)
for x in trading_counts:
    plt.axvline(x=x-1, ymin=0, ymax=4.0, color='red')
    print(&quot;line drawn at x =&quot;, x)
plt.show()

print(trading_prices)
</code></pre>
<p>This new code produces results that are much less 'jagged'. Here are some examples, of behavior of price with the exponential distribution (possibly different types of distribution would yield better result but its beyond scope of SE answer to examine that). For example, here are 8 graphs generated when the prices depend on exponential distribution:</p>
<p><a href="https://i.sstatic.net/meVI8m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/meVI8m.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/24IDPm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/24IDPm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/mZT2hm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mZT2hm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/s2fKnm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/s2fKnm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/pwwbtm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pwwbtm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/8NnTFm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8NnTFm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/1uwOwm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1uwOwm.png" alt="enter image description here" /></a>
<a href="https://i.sstatic.net/wkFX4m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wkFX4m.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-02-10T21:21:31.177Z
Thanks! I feel convinced that it is indeed the way the deltas are chosen that is causing the jaggedness. When I use exponential deltas though, the trading prices seem to still range around 1.5 to 2.5, the same as my original graph. I think the reduced jaggedness in your graph is coming not from prices being more stable around the equilibrium price, but instead from there being fewer trades (there's not much room to be jagged when only 2-3 trade are made in a single period).
IssaRice
CC BY-SA 4.0
2021-02-10T21:27:01.683Z
@riceissa I did not save the further output, but  I know for sure volatility of prices dropped because I actually calculated the volatility of prices based on the list at the end, compared it to the original and, and it was lower in this new one than in original script.
1muflon1
CC BY-SA 4.0
2021-02-09T02:50:01.123Z
2021-02-09T16:30:18.400Z
2021-02-09T16:30:18.400Z
1muflon1
<p>Vernon Smith's 1962 paper &quot;An Experimental Study of Competitive Market Behavior&quot; simulates a market using students (who have piece of paper giving their reservation prices). In one of the experiments, the demand/supply curves look like the graph on the left, with the corresponding market activity on the right:</p>
<p><a href="https://i.sstatic.net/JWv9J.png" rel="noreferrer"><img src="https://i.sstatic.net/JWv9J.png" alt="chart 1 from Smith's paper" /></a></p>
<p>Since there seems to be nothing special about using students in the experiment (i.e. as far as I can tell, they are just performing simple computations), I decided to code up the experiment in Python. My script is <a href="https://gist.github.com/riceissa/3e9c043b6943ee5f1b053e6d8324985a" rel="noreferrer">here</a>.</p>
<p>When I run the script (which has the same demand/supply curves as above), the market activity typically looks like this:</p>
<p><a href="https://i.sstatic.net/Qrm6g.png" rel="noreferrer"><img src="https://i.sstatic.net/Qrm6g.png" alt="my plot" /></a></p>
<p>The market price does indeed hover around $2.00, but my graph seems noticeably more jagged than the graph in the original paper. I'm trying to figure out what's going on, in particular whether:</p>
<ol>
<li>I'm understanding the paper incorrectly somehow, or</li>
<li>My Python script has some error in it, or</li>
<li>There's some kind of error or unwritten assumption in the paper.</li>
</ol>

CC BY-SA 4.0
2021-02-09T02:52:10.293Z
I'm not an expert in parsing Python codes, but I suspect that the particular decision/trading algorithm(s) was the reason for the sustained volatility. It would help if you could describe verbally the decision algorithms in your script.
Herr K.
CC BY-SA 4.0
2021-02-09T10:43:51.163Z
May be renamed "reproducing distribution" instead of "understanding" to get more specialist feedback.
Michal Gajda
CC BY-SA 4.0
2021-02-09T16:33:47.230Z
one can only answer question that was being asked not question that was meant to be asked - that does not make feedback any less specialist - this being said I made some adjustment to your code that reduced the 'jaggedness'  - however, as the HerK answer explain there is not much you can do with pure random trading - an alternative would be to specify the agents through some model + AI/learning algorithm - however that is too time consuming to code it all from nothing for an SE answer
1muflon1
<supply-and-demand><markets><experimental-economics>
Understanding Vernon Smith's 1962 "An Experimental Study of Competitive Market Behavior"
IssaRice
# Understanding Vernon Smith's 1962 "An Experimental Study of Competitive Market Behavior"

(Asked by: username_0 on 2021-02-09)

Vernon Smith's 1962 paper "An Experimental Study of Competitive Market Behavior" simulates a market using students (who have piece of paper giving their reservation prices). In one of the experiments, the demand/supply curves look like the graph on the left, with the corresponding market activity on the right:

[![chart 1 from Smith's paper](https://i.sstatic.net/JWv9J.png)](https://i.sstatic.net/JWv9J.png)

Since there seems to be nothing special about using students in the experiment (i.e. as far as I can tell, they are just performing simple computations), I decided to code up the experiment in Python. My script is [here](https://gist.github.com/riceissa/3e9c043b6943ee5f1b053e6d8324985a).

When I run the script (which has the same demand/supply curves as above), the market activity typically looks like this:

[![my plot](https://i.sstatic.net/Qrm6g.png)](https://i.sstatic.net/Qrm6g.png)

The market price does indeed hover around $2.00, but my graph seems noticeably more jagged than the graph in the original paper. I'm trying to figure out what's going on, in particular whether:

1. I'm understanding the paper incorrectly somehow, or
2. My Python script has some error in it, or
3. There's some kind of error or unwritten assumption in the paper.

**Tags:** supply-and-demand, markets, experimental-economics

> **Comments:**
> **username_1**: I'm not an expert in parsing Python codes, but I suspect that the particular decision/trading algorithm(s) was the reason for the sustained volatility. It would help if you could describe verbally the decision algorithms in your script.  
> **username_2**: May be renamed "reproducing distribution" instead of "understanding" to get more specialist feedback.  
> **username_3**: one can only answer question that was being asked not question that was meant to be asked - that does not make feedback any less specialist - this being said I made some adjustment to your code that reduced the 'jaggedness'  - however, as the HerK answer explain there is not much you can do with pure random trading - an alternative would be to specify the agents through some model + AI/learning algorithm - however that is too time consuming to code it all from nothing for an SE answer  

---

## 3 answers

### Answer by username_3 on 2021-02-09. Score: 3 | Accepted answer

I suspect that the reason for that result is the way how you modeled the situation is by having the prices to be offered at random from a sample of numbers in uniform fashion (unless I am misreading the code) but this is unrealistic.
As mentioned in the paper Smith's 1962:

each sequence of experiments was conducted over sequences five to ten minutes long

So the students had only 5-10 minutes to actually conclude the trades. Students knew their own valuation of the item and they wanted to get it.
In such situation it is not in students interest to just choose random price from the sample of prices. Rather students will be choosing from some distribution that will have more mass closer to the their own valuation.
My prediction is that if instead of random sampling of prices from the array you will let the program generate numbers from some distribution that has more mass closer to the right price you will see less volatility in the data.
For example, instead of using random.choice(price_deltas) you could use random.choice(price_deltas, p=weights) that allows you to assign weights to numbers so some are more likely than others.

EDIT:
You could use the weight approach above but I also discovered much simpler one. If you are just fine assuming prices can be continuous (which from point of economic theory is fine 0.01c is really just practical limit in real life), then what you can do is skip the creation of deltas at the start:
import numpy as np
import matplotlib.pyplot as plt
buyers = [3.25 - 0.25*n for n in range(0, 11)]
sellers = [3.25 - 0.25*n for n in range(0, 11)] 

Next what you can do is to replace random.choice() with some distribution that has most mass at zero - like the exponential distribution. In python this can be done using random.exponential(), the code would thus change only minimally, and will generate deltas that are closer to the actual valuation of the traders:
trading_prices = []
trading_counts = []

for _ in range(5):
    buyers_still_in_market = list(range(len(buyers)))
    sellers_still_in_market = list(range(len(sellers)))

    transactions = []

    for _ in range(1000):
        # First, a random buyer offers to buy at some price below their number on
        # their card
        b = np.random.choice(buyers_still_in_market)
        delta = np.random.exponential(400)
        buyer_price = max(0, buyers[b] - abs(delta))
        s = np.random.choice(sellers_still_in_market)
        if buyer_price >= sellers[s]:
            transactions.append((b, buyers[b], s, sellers[s], buyer_price))
            buyers_still_in_market.remove(b)
            sellers_still_in_market.remove(s)
            trading_prices.append(buyer_price)

        # Then, a random seller offers to sell at some price above their number on
        # their card. #0.65 - for log normal
        s = np.random.choice(sellers_still_in_market)
        delta = np.random.exponential(400)
        seller_price = sellers[s] + abs(delta)
        b = np.random.choice(buyers_still_in_market)
        if seller_price <= buyers[b]:
            transactions.append((b, buyers[b], s, sellers[s], seller_price))
            buyers_still_in_market.remove(b)
            sellers_still_in_market.remove(s)
            trading_prices.append(seller_price)

    trading_counts.append(len(trading_prices))

    print(len(transactions), "transactions")

plt.plot(list(range(len(trading_prices))), trading_prices)
plt.ylim(0, 4.00)
for x in trading_counts:
    plt.axvline(x=x-1, ymin=0, ymax=4.0, color='red')
    print("line drawn at x =", x)
plt.show()

print(trading_prices)

This new code produces results that are much less 'jagged'. Here are some examples, of behavior of price with the exponential distribution (possibly different types of distribution would yield better result but its beyond scope of SE answer to examine that). For example, here are 8 graphs generated when the prices depend on exponential distribution:

> **Comments:**
> **username_0**: Thanks! I feel convinced that it is indeed the way the deltas are chosen that is causing the jaggedness. When I use exponential deltas though, the trading prices seem to still range around 1.5 to 2.5, the same as my original graph. I think the reduced jaggedness in your graph is coming not from prices being more stable around the equilibrium price, but instead from there being fewer trades (there's not much room to be jagged when only 2-3 trade are made in a single period).  
> **username_3**: @riceissa I did not save the further output, but  I know for sure volatility of prices dropped because I actually calculated the volatility of prices based on the list at the end, compared it to the original and, and it was lower in this new one than in original script.  

---

### Answer by username_1 on 2021-02-09. Score: 4

[Gode and Sunder (1993)](https://www.jstor.org/stable/2138676?seq=1) recorded a result similar to yours. The abstract of the paper reads:

> We report market experiments in which human traders are replaced by "zero-intelligence" programs that submit random bids and offers. Imposing a budget constraint (i.e., not permitting traders to sell below their costs or buy above their values) is sufficient to raise the allocative efficiency of these auctions close to 100 percent. Allocative efficiency of a double auction derives largely from its structure, independent of traders' motivation, intelligence, or learning. Adam Smith's invisible hand may be more powerful than some may have thought; it can generate aggregate rationality not only from individual rationality but also from individual irrationality.

Specifically, Gode and Sunder consider two algorithms of trade. The first algorithm generates bids and asks from a uniform distribution on a fixed interval, say $[L,U]$, irrespective of the traders' reservation values. The authors refer to these traders as unconstrained zero intelligence (ZI-U) traders. In the second algorithm, bids are drawn from $\mathrm{unif}[L,v]$ and asks are drawn from $\mathrm{unif}[c,U]$, where $v,c$ are the reservation values for buyers and sellers respectively. The traders following this second algorithm are referred to as constrained zero intelligence (ZI-C) traders.

The following figure (along with several others in the paper with different market parameters) shows that ZI-U traders generate more sustained price volatility than ZI-C traders, who in turn resemble human traders in the same market condition. So I suspect that the sustained volatility you observed in your code was due to the fact that you used uniform bounds on the random bid/ask generation instead of imposing a budget constraint for the traders.

[![enter image description here](https://i.sstatic.net/rVEK2.png)](https://i.sstatic.net/rVEK2.png)

> **Comments:**
> **username_0**: Thanks, I appreciate this reference! (I found Smith's paper mentioned in my econ 101 textbook without any reference to other literature since then, and I am too much of an econ noob to quickly find the relevant papers.)  
> **username_1**: @riceissa: You're welcome. You may also refer to Duffy's [chapter in the *Handbook of Computational Economics*](https://www.sciencedirect.com/science/article/pii/S1574002105020198) for other related developments in the literature.  

---

### Answer by username_4 on 2022-10-17. Score: 2

Smith's human traders adapted their behavior, learning from experience between successive market periods, which is another reason why their transaction-price time-series is so much smoother than yours (or Gode & Sunder's ZIC results).

For a free open-source detailed Python simulation of a financial exchange populated with traders that do adapt over time, learning from experience, see:

<https://github.com/davecliff/BristolStockExchange/wiki>

Especially the Jupyter notebook here, which is a walkthrough of recreating Smith's 1962 results (his *Chart 1* graph) with simulated traders:

<https://github.com/davecliff/BristolStockExchange/blob/master/BSE_VernonSmith1962_demo.ipynb>


---

