Simple double auction market
No preview image
Model was written in NetLogo 6.2.0
•
Viewed 216 times
•
Downloaded 14 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Click to Run Model
breed [buyers buyer] breed [sellers seller] breed [farmers farmer] breed [speculators speculator] breed [firms firm] ;breed [happiest happy] ; to take out fulfilled buyers out of the market ;breed [no-stocks no-stock] ;breed [unhappiest_buyers unhappy_buyer] ;breed [unhappiest_sellers unhappy_seller] Globals [b-price s-price bid_schedule ask_schedule last_price round_price number_of_buyers_left highest_bid lowest_ask number_of_sellers_left rounds periods] buyers-own [bid stock_demanded Own_ID Money_Holdings] sellers-own [ask_offer inventory Own_ID Money_Holdings] farmers-own [ask_offer inventory Own_ID Money_Holdings] speculators-own [bid stock_demanded ask_offer inventory Own_ID Money_Holdings] firms-own [bid stock_demanded Own_ID Money_Holdings] to Setup clear-all create-firms Number-of-Firms [ set Own_ID 0 set color blue ask firms [find_patch] set bid random bid-variation set stock_demanded random demand-variation set Money_Holdings 500 ] ; create a sort-of demand curve, placeholder, will be more 'adaptive' in the future where bids are endogenously generated instead of exogenously determined create-farmers Number-of-Farmers [ set Own_ID 1 set color red ask farmers [find_patch] set ask_offer random ask-variation set inventory random inventory-variation set Money_Holdings 500 ] ; create a sort-of supply curve create-speculators Number-of-Speculators [ set Own_ID 2 set color green ask speculators [find_patch] set bid 0 set ask_offer 0 set inventory 0 set Money_Holdings 500 ] set s-price [] set bid_schedule [] set ask_schedule [] set last_price 0 set number_of_buyers_left 0 set number_of_sellers_left 0 set rounds 1 set periods 1 reset-ticks end ;;;; setup stuff ;;;;;;; to find_patch setxy random-xcor random-ycor while [any? other turtles-here] [find_patch] end ;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;; To go ;;;;;;;;;;; to go ;;if round = 1 [ ;; do accounting, this is a new period afterall. Determine performance in the last period. This is where period-to-period readjustment will happen ;; farmer harvest and decide how much to plant based on past. After this they decide on initial bid ;; speculators see how much is planted, and decide whether to bid, or ask, and at what price and quantity ;; firm determines bid based on whether current income can afford it] create_buyers create_sellers create_bid_schedule create_ask_schedule ;; print last first ask_schedule - when want to know the lowest asking price ;; print last first bid_schedule - when want to know the highest bid price ;; print last first bid_schedule ;; print first first bid_schedule - when want to know who is the higest bidder auction_round readjustment ; need to readjust based on rounds in the future if all? buyers [stock_demanded = 0][ stop] if all? sellers [inventory = 0][ stop] plot_stuff ; we do plot stuff first because of we are monitoring the more 'general breeds' return_to_original_breed round_accounting tick end to create_sellers ask farmers [ set breed sellers] ; ask speculators [ This is to let speculators become sellers under certain condition, yet to be introduced ; if .... [ ; set breed sellers] end to create_buyers ask firms [ set breed buyers] ; ask speculators [ This is to let speculators become buyers under certain condition, yet to be introduced ; if .... [ ; set breed buyers] end to create_bid_schedule let d [] set d sort ([who] of buyers) foreach d [ ID -> let temp2 [] set temp2 lput ID temp2 set temp2 lput ([bid] of buyer ID) temp2 set bid_schedule lput temp2 bid_schedule] set bid_schedule sort-by [ [x y] -> last x > last y] bid_schedule ; ordering the schedule from the highest bidder to the lowest bidder ; print bid_schedule end to create_ask_schedule let d [] set d sort ([who] of sellers) foreach d [ ID -> let temp2 [] set temp2 lput ID temp2 set temp2 lput ([ask_offer] of seller ID) temp2 set ask_schedule lput temp2 ask_schedule] set ask_schedule sort-by [ [x y] -> last x < last y] ask_schedule ; ordering the schedule from the lowest ask offer to the highest ; print ask_schedule end to auction_round if empty? bid_schedule [stop] ; highly unlikely while [(last first bid_schedule) >= (last first ask_schedule)] [ ask buyer (first first bid_schedule) [ ; the highest bidder has the right to buy first, she will of course buy from the lowest asker let bid_price [] let Q_bid [] let ask_price [] let Q_ask [] set bid_price bid set Q_bid stock_demanded ask seller (first first ask_schedule) [ ; gathering info from the seller we face set ask_price ask_offer set Q_ask inventory ] ;;;; Auction starts for real ;;;;;;;; ifelse stock_demanded = 0 [ ; if buyer already exit the market, still has nothing to buy, she will leave the market again. This is admitedly a convoluted way of eliminating bidders who exit from previous rounds set bid_schedule remove-item 0 bid_schedule ] [;;;;;;; if bidder really has something to buy ifelse Q_bid <= Q_ask [ ; when quantity needed is more than quantity offered by seller set stock_demanded stock_demanded - Q_bid set Money_Holdings Money_Holdings - ((bid_price + ask_price) / 2) * Q_bid ; buyers have to pay, which takes away her money holdings ask seller (first first ask_schedule) [ set Money_Holdings Money_Holdings + ((bid_price + ask_price) / 2) * Q_bid ; sellers got paid, it's money holdings are increased set inventory inventory - Q_bid if inventory = 0 [set ask_schedule remove-item 0 ask_schedule] ; sellers only exit when they run out of inventory ] set bid_schedule remove-item 0 bid_schedule ; if bid is fulfilled, then they exit the auction set last_price ((bid_price + ask_price) / 2) ] ;;;;;;;; when initial bid cannot be fulfilled by initial ask. This is the case where Q_bid > Q_ask [ ifelse Q_ask = 0 [ ; eliminate sellers that already have nothing to sell set ask_schedule remove-item 0 ask_schedule] [ set stock_demanded stock_demanded - Q_ask set Money_Holdings Money_Holdings - ((bid_price + ask_price) / 2) * Q_ask ask seller (first first ask_schedule) [ set Money_Holdings Money_Holdings + ((bid_price + ask_price) / 2) * Q_ask set inventory 0 ] set ask_schedule remove-item 0 ask_schedule ; eliminate sellers that already have nothing to sell, won't eliminate buyer yet as full ordernot yet fufilled set last_price ((bid_price + ask_price) / 2) ]] ; in usual times, this just makes sure buyers gets their orders fulfilled. If askers already left, this just eliminates them from the ask schedule until bidder can deal with asker with something to sell ]] if empty? bid_schedule [stop] ; after all current demand and supply orders are filled , which would result in the end of this procedure, and move on to 'readjustment' if empty? ask_schedule [stop]] end to readjustment ; A placeholder for now, should be more complicated in the future foreach (bid_schedule) [Buyer_ID -> ask buyer first Buyer_ID[ ; change the bid, and remove them from the list so a new list can be generated in the future set bid bid + random U_readjustment_rate ] set bid_schedule remove-item 0 bid_schedule ] foreach (ask_schedule) [Seller_ID -> ask seller first Seller_ID [ set ask_offer ask_offer - random D_readjustment_rate ] set ask_schedule remove-item 0 ask_schedule ] end to plot_stuff set number_of_buyers_left count buyers with [stock_demanded > 0] set number_of_sellers_left count sellers with [inventory > 0] set highest_bid max [bid] of buyers with [stock_demanded > 0] set lowest_ask min [ask_offer] of sellers with [inventory > 0] end to return_to_original_breed ask turtles [ if Own_ID = 0 [ set breed firms] if Own_ID = 1 [ set breed farmers] if Own_ID = 2 [ set breed speculators] ] end to round_accounting ifelse rounds < 12 [ set rounds rounds + 1] [set rounds 1 ; when current round is already 12 set periods periods + 1] end
There are 2 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
interface.png | jpeg | Preview image | about 3 years ago, by Per Hung Yap | Download |
This model does not have any ancestors.
This model does not have any descendants.
Per Hung Yap
On Questions
Hi, still new to the website and don't really know how to edit it yet. If you have any questions, just ask them here
Posted about 3 years ago