JonathanBohrer-PredatoryTrading-project-EECS-372
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This project models the behavior of a stock market with predatory trading occuring in the market. Normal traders will hold stock, and try to buy and sell stock with others. Predatory traders try to get in between a buyer and a seller to take advantage of the bid-ask spread.
HOW IT WORKS
In the model, traders have different levels of wealth and stock. Stock is appreciated for each turtle on each day based on a random-normal value around the annual growth rate (converted to daily growth rate).
Trader rules followed in a single tick:
- If I have any wealth, I consider buying stock
- If I decide to buy stock, I decide the amount of stock I want to buy, and the price at which I am willing to buy it
- Try to find another trader that has that amount of stock, and have that trader set the price at which they are willing to sell
- If I am the seller, I only sell if I have already made money on the stock or lost at least 10%, and if the bid price is higher than my ask price, I will sell the stock
- If a trade takes place, create a grey link between the two traders
Predatory Trader rules followed in a single tick:
- If the amount of stock being traded is high enough, I will hijack the trade, gaining the spread between the bid and the ask price as profit, and allowing the trade to be completed
- If I hijack a trade, create two yellow links, one between the buyer and me, and one between the seller and me
HOW TO USE IT
The Setup button sets up the model, using the current values of the sliders. It changes patch color for a white background, resets ticks and global variables, and creates agents spread out randomly across the world.
The Go button starts the model, and causes agents to begin trying to trade with each other.
The number-people slider adjusts how many people are in the model. Select the value before clicking Setup.
The market-annual-growth-rate is how much stock is expected to grow, on average, in a year. Select the value before clicking Setup.
The person-initial-wealth slider adjusts how much wealth each person starts with. A person will start out with a small random amount of stock taken from this initial wealth value. Select the value before clicking Setup.
The predatory-trading? switch determines whether there are predatory traders in the market or not. Select the value before clicking Setup.
The amount-predatory-traders slider adjusts what percentage of people in the market are predatory traders. Select the value before clicking Setup.
THINGS TO NOTICE
Notice how the average wealth of predatory traders increases. Follow the histogram as well as the monitor to see how the process is riskless
Notice how the wealth of regular traders quickly becomes distributed. See the skewed right distribution quickly form once trading begins.
Notice how after long enough growth, the market can start to experience some large swings in growth.
THINGS TO TRY
The market-annual-growth-rate sets the annual growth rate of stock in the market. Try setting the value initially, and adjusting the slider as the model runs.
Adjust the amount-predatory-traders value to see how a saturation of predatory traders affects the market.
Adjust the bid-ask-spread to see how a tighter spread can affect profits for predatory trading, and reduction of wealth in the market.
Adjust the person-initial-wealth slider to see how smaller amounts of wealth can lead to smaller negative effects from predatory trading.
Run the model both with predatory-trading? on and off. Do you notice a difference after 1200 ticks, 2500?
EXTENDING THE MODEL
Right now the model focuses on the basic effect of predatory trading on the basic market. The model doesn't have a way of increasing or decreasing stability of the market, so it could be extended to include this.
In addition, this model could be extended to include random shocks to the market, such as recessions or booms. This would make the market more accurate, and allow observation of predatory trading during these specialized periods. Currently, only manually changing the market-annual-growth-rate slider during running can simulate this
NETLOGO FEATURES
The most interesting netlogo feature used for me was the random-normal function, a built-in way to get a random number from a normal distribution with specified mean and standard deviation. I had no idea Netlogo had this functionality, and the model didn't work nearly as well without it. Bryan Head guided me to this feature.
One more interesting feature is the ability to change global slider variables in the code, and have it be reflected in the interface. I didn't realize that altering a variable in the Setup code would actually show the updated value in the slider without the user adjusting the value manually.
RELATED MODELS
Exponential Growth Wealth Distribution
CREDITS AND REFERENCES
Inspiration for this model, as well as background information on high frequency trading from Flash Boys by Michael Lewis.
Volatility value from http://finance.yahoo.com/q?s=%5EVIX and was accurate for day of writing.
This model would not have been possible without the help of Dr. Uri Wilensky, Bryan Head, Arthur Hjorth, and Elham Beheshti
Link to model: http://modelingcommons.org/browse/one_model/4663
Comments and Questions
; the regular traders in the market breed [traders trader] ; traders who don't hold stock, and only attempt ; to make money off hijacking trades between traders breed [pred-traders pred-trader] ; wealth is money owned not in stock ; stock is money owned in stock ; wps is the sum of the two ; gain is the difference from initial cost of stock to current cost ; bid-ask is the bid price or ask price for that turtle traders-own [stock wps gain bid-ask] turtles-own [wealth] ; avg-wealth is the average wealth of traders ; avg-stock is the average stock of the traders ; num-trades is the total number of trades that have occured ; avg-pred-wealth is the average wealth of pred-traders ; total-wealth is total wealth of the market globals [avg-wealth avg-stock num-trades avg-pred-wealth total-wealth] to setup clear-all ask patches [set pcolor white] ifelse not predatory-trading? [ create-traders number-people [setxy random-xcor random-ycor set shape "circle" set color green] set amount-predatory-traders 0 ; make slider reflect no predatory traders ] [ ; as the system sets amount-predatory-traders to 0 if the switch is off ; reset the slider to default value of 5 in case user forgets to (otherwise there will be errors) if amount-predatory-traders = 0 [ set amount-predatory-traders 5 ] ; keep number of people same, but make amount-predatory-traders % pred-traders create-traders (number-people * (1 - (amount-predatory-traders / 100))) [setxy random-xcor random-ycor set shape "circle" set color green] create-pred-traders (number-people * (amount-predatory-traders / 100)) [setxy random-xcor random-ycor set shape "circle" set color red] ] ask traders [ set-initial-wealth set-initial-stock set gain 0 set wps wealth + stock ] if predatory-trading? [ ask pred-traders [ set-initial-wealth ]] set avg-wealth person-initial-wealth ifelse predatory-trading? ; don't need avg-pred-wealth value for market when they don't exist [ set avg-pred-wealth person-initial-wealth ] [ set avg-pred-wealth "N/A" ] set total-wealth person-initial-wealth * number-people set num-trades 0 reset-ticks end to go ask traders [ if wealth > 0 [ ; can't buy stock without money buy-stock appreciate-stock set wps wealth + stock ] ] if one-of links != nobody [ ; get rid of links showing current trades, as they have finished ask links [die] ] get-avg-wealth get-avg-stock get-total-wealth if predatory-trading? [get-avg-pred-wealth] tick end ;; handles the entire buy/sell transaction between 2 traders to buy-stock ;; turtle procedure if random 100 < 10 [ let amt ((random 15) / 100) * wealth ; amount of stock turtle wishes to purchase set bid-ask (random-normal 1 (bid-ask-spread / 10000)) * amt ; set bid price to a small spread around the amount let success? false ; variables to handle the predatory trading let bid-price bid-ask let asking-price 0 let hijacked? false let pred-turtle nobody ; only want traders with that much stock to sell it - avoid negative stock ask other traders with [stock > amt] [ set bid-ask (random-normal 1 (bid-ask-spread / 10000)) * amt ; set offer price ; not success? is to make sure only one turtle gets rid of its stock ; the gain checks are if turtle has either made money or lost a good amount from stock if random 100 < 10 and not success? and (gain > 0 or gain < -1 * .10 * stock) and bid-ask <= bid-price [ set asking-price bid-ask ; makes handling scope easier ifelse predatory-trading? and amt > .05 * avg-wealth [ ; if the trade is large enough, the predatory traders will intercept ask one-of pred-traders [ create-link-from myself [set color yellow] ; different color to highlight trade hijacking set wealth wealth + (bid-price - asking-price) ; predatory traders pocket the spread set hijacked? true set pred-turtle self ] set wealth wealth + asking-price ; seller gains money equal to their offer value for the stock ] [ set wealth wealth + asking-price + (bid-price - asking-price) ; if there wasn't an interception, seller can benefit from buyer crossing the spread create-link-to myself ] set stock stock - amt ; amt of stock is ultimately sold set num-trades num-trades + 1 set success? true ; trade was successful ] ] ; if seller found, update turtle's wealth and stock if success? [ set gain 0 set wealth wealth - bid-price ; buyer pays money equal to their bid price, as they are crossing the spread in this model if hijacked? [ create-link-from pred-turtle [set color yellow] ; if trade is intecepted, complete the hijacked trade link set num-trades num-trades + 1 ; predatory trader performs 2 trades, first buying, then selling ] set stock stock + amt ; amt of stock is ultimately purchased regardless of the bid-ask spread ] ] end ; this method gives each turtle's stock a different growth rate ; which simulates traders holding different stocks in the market to appreciate-stock ; turtle procedure ; convert growth rate to daily rate let growth-difference (market-annual-growth-rate / (100 * 250)) let growth-rate 1 + growth-difference set gain gain - stock ; this subtracts the stock's initial amount from gain ; want a normal distribution around the growth rate set stock (random-normal growth-rate .02 ) * stock ; .02 is taken from S&P 500 volatility set gain gain + stock ; add the new stock amount to complete (new - old) calculation end ;;; SETUP PROCEDURES ;;; ;; set traders initial wealth to around initial wealth specified to set-initial-wealth set wealth (random-normal person-initial-wealth (.05 * person-initial-wealth)) end ; set initial stock to be a random number around a normal distribution of 30% of wealth to set-initial-stock set stock (random-normal (.3 * wealth) (.1 * wealth)) set wealth wealth - stock end ;;; AVERAGE OUTPUT PROCEDURES ;;; ;; get average wealth of traders for display to get-avg-wealth set avg-wealth 0 ask traders [ set avg-wealth avg-wealth + wealth + stock ] set avg-wealth (avg-wealth / (count traders)) end ; get average wealth of predatory traders to get-avg-pred-wealth set avg-pred-wealth 0 ask pred-traders [ set avg-pred-wealth avg-pred-wealth + wealth ] set avg-pred-wealth avg-pred-wealth / (count pred-traders) end ; get average stock for each trader to get-avg-stock set avg-stock 0 ask traders [ set avg-stock avg-stock + stock ] set avg-stock (avg-stock / (count traders)) end ; get total wealth in the market to get-total-wealth set total-wealth 0 ask traders [ set total-wealth total-wealth + wealth + stock ] if predatory-trading? [ ask pred-traders [ set total-wealth total-wealth + wealth ]] end ; report the average wealth of all agents to-report avg-total-wealth let total 0 ask traders [ set total total + wealth + stock ] if predatory-trading? [ ask pred-traders [ set total total + wealth ]] ifelse predatory-trading? [ set total total / ((count traders) + (count pred-traders)) ] [ set total total / (count traders) ] report total end
There are 3 versions of this model.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Final poster.pdf | Final poster | about 9 years ago, by Jonathan Bohrer | Download | |
final report.pdf | Final Report | about 9 years ago, by Jonathan Bohrer | Download | |
firehose slides.pdf | Firehose Slides | about 9 years ago, by Jonathan Bohrer | Download | |
JonathanBohrer-PredatoryTrading-project-EECS-372.png | preview | View | about 9 years ago, by Jonathan Bohrer | Download |
JonathanBohrer_May16.docx | background | Progress Report 2 | about 9 years ago, by Jonathan Bohrer | Download |
JonathanBohrer_May24.docx | background | Progress Report 3 | about 9 years ago, by Jonathan Bohrer | Download |
JonathanBohrer_May9.docx | background | Progress Report 1 | about 9 years ago, by Jonathan Bohrer | Download |
This model does not have any ancestors.
This model does not have any descendants.