Last active
February 9, 2021 02:20
-
-
Save riceissa/3e9c043b6943ee5f1b053e6d8324985a to your computer and use it in GitHub Desktop.
For my question at https://economics.stackexchange.com/questions/42481/understanding-vernon-smiths-1962-an-experimental-study-of-competitive-market-b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
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)] | |
price_deltas = [0.01 * x for x in range(0, 1000)] | |
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.choice(price_deltas) | |
buyer_price = max(0, buyers[b] - 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. | |
s = np.random.choice(sellers_still_in_market) | |
delta = np.random.choice(price_deltas) | |
seller_price = sellers[s] + 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment