Mark Xue Market Model
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This model stimulates agent behavior in the financial markets. Through this model, we will see how certain marcoeconomic/news events and agent buying/selling affect an index price on the financial markets. In particular, we are interested to see what events would stimulate a market rally or crash.
HOW IT WORKS
The agents will react based on what others around them do. Like in real life, agents will not be able to tell what will happen until it has occurred, so any “information” the agents gets from others will be based on the previous tick's trades.The agents can do two things each tick, buy or sell. Their actions are based on their confidence in the market.If more agents buy than sell, the market price of the index rises. If more agents sell than buy, the market price of the index falls.
Each agent will have a confidence level which affects whether if it is more prone to buy or sell. This level will be affected by how the market moves. For example, if the market rallies, confidence of the agents will increase. If the market crashes, the confidence of the agents decreases. This confidence level reflects the volatility factor within the equity markets.
There are 100 agents lined up next to each other in the middle of the world. This reflects a financial community of 100 traders. If an agent is confident in the market (confidence level > 0), their color would be set to green. If the agent is not confident in the market (confidence level < 0), their color would be set to red. If the agent is neutral (confidence level = 0), then their color would be set to white. The y-coordinate of the agent reflects the magnitude of their confidence. The more confident the agent is, the higher up the agent will move in their world and vice versa.
moving-average? turns on the moving-average function. This tracks the 50-tick moving average price of the market. In real life, there are many agents follow mean reversion trading algorithms. Therefore, short-run market-prices may be effected by the moving-average.
The Market Price Graph displays the historical index price. The Market Volatility Graph displays the calculated index price volatility using a trailing 50-tick price data. This volatility is annualized assuming 252 trading ticks (or days) per year. Price and volatility graphs are heavily used by finance professionals to gain insight on how the market behaves. What does this tell you?
HOW TO USE IT
Press setup and go. You can introduce an external shock to the market (simulating external news) by clicking the add-shock button.
Turn on moving-average? to set up the mean-reversion effect in the market.
THINGS TO NOTICE
How do the agents behave? Do you notice any emergent behaviors within the markets? What happens when an external shock is introduced? Are there any apparent support or resistence levels in the markets? How does volatility behave? How does the volatility behavior correlate to it's actual behavior in the markets?
THINGS TO TRY
See how the market evolves over time. Adjust the shock level and introduce it into the market. What level is required to spark a rally or crash? How easily are the support or resistence levels broken?
What happens when you turn on the moving-average? function? How des the market behave differently?
EXTENDING THE MODEL
What happens if the agents are in networks (e.g. large bank vs. small trading firm)? How would rumors and actions of agents within the size of networks effect the overall market? What happens if market makers are introduced? Would they decrease the overall volatility of the market?
A hubnet extension can test how confidence level changes with stimulated events among real participants. This may be an interesting avenue to look into.
RELATED MODELS
StockMarketPredictor Artificial Financial Market
CREDITS AND REFERENCES
Netlogo Documentation: http://ccl.northwestern.edu/netlogo/docs/ Options, Futures, and Other Financial Derivatives by John C. Hull
Comments and Questions
turtles-own [ confidence ;;confidence level of agent ] globals [ index-price ;;index price in the market previous-price ;;price of index in the previous period all-time-high ;;all time high price of index in market all-time-low ;;all time low price of index in market moving-average ;;50 tick moving average price-list ;;list of index prices in the previous 50 ticks volatility ;;annualized volatility using past 50 tick price data ] ;;setup to setup clear-all setup-turtles setup-patches setup-constants set-turtle-color check-bounds move-turtle reset-ticks end ;;run to go set-memory set-market-price change-turtle-confidence set-turtle-color check-bounds move-turtle set-price-list if moving-average? [ calculate-moving-average ] set-var tick end ;;setup turtles to setup-turtles set-default-shape turtles "person" crt 100 [ set size 3 ;; easier to see ] end ;;setup patches to setup-patches ask patches [ set pcolor black ] end ;;setup constants to setup-constants ask turtles [ ;;set each turtle's initial confidence to normal distribution let temp random-normal initial-confidence 10 set confidence temp if temp < -100 [ set confidence -100 ] if confidence > 100 [ set confidence 100 ] ] set index-price 1000 set all-time-high 1000 set all-time-low 1000 set price-list [] set volatility 0 end ;;set the colors of the turtles to set-turtle-color ask turtles [ ;;agent is bearish, so color set to red if confidence < 0 [set color red] ;;agent is bullish, so color is set to green if confidence > 0 [set color green] ;;agent is neutral, so color is white if confidence = 0 [set color white] ] end ;;sets the global variables to set-market-price let confidence-sum 0 ask turtles [ set confidence-sum (confidence-sum + confidence) ] ifelse index-price < 0 [set index-price 0] ;; 0 lower bound [set index-price (index-price + (confidence-sum / 10))] ;;set all-time-high level if index-price > all-time-high [set all-time-high index-price] ;;set all-time-low level if index-price < all-time-low [set all-time-low index-price] end ;;how the turtle confidence changes based on what happened in the previous tick to change-turtle-confidence ask turtles [ if previous-price > index-price [ ;; market trending up, maybe bull run, so buy? set confidence (confidence + random 10) ] if previous-price < index-price [ ;; market sliding down, maybe crash coming, so sell? set confidence (confidence - random 10) ] ;;effect of alltime highs/lows if ticks > 100 [ ;;need enough "historical" data if index-price = all-time-high [ ;;all time highs reached, sell off to realize profits if 3 < (random 10) [set confidence (confidence - 10)] ] if index-price = all-time-low [ ;;all time lows reached, good price to buy in if 3 < (random 10) [set confidence (confidence + 10)] ] ] if moving-average? [ ;;effect of 50-tick moving average, mean reversion strategy if ticks > 50 [ if (moving-average > index-price) [ ;;moving average is higher than index price, prompt agents to sell off to converage to mean if 1 < (random 10) [set confidence (confidence - 0.5)] ] if (moving-average < index-price) [ ;;moving averge is lower than index price, prompt agents to buy to converage to mean if 1 < (random 10) [set confidence (confidence + 0.5)] ] ] ] ] end ;;sets confidence bounds to check-bounds ask turtles [ ;; confidence bounds if confidence > 100 [ set confidence 100 ] if confidence < -100 [ set confidence -100 ] ] end ;;sets the memory of the turtles, tell them what happened in the previous turn to set-memory set previous-price index-price end ;;introduces a confidence shock in the market, e.g. a big economic news that came out to add-shock ask turtles [ set confidence (((shock / 100) * (abs confidence)) + confidence) ] end ;;moves the turtle according to it's confidence to move-turtle ask turtles [ setxy ((who - 50) + (who * 4)) (confidence / 2) ] end ;;calculates the 50-tick moving average to calculate-moving-average if (ticks > 50) [ let price-sum (sum price-list) set moving-average (price-sum / 50) ] end ;;updates the price-list to the 50 previous prices to set-price-list ifelse (ticks < 50) [ set price-list lput index-price price-list ;;adds in the newest price at the end ] [ set price-list but-first price-list ;;pops out the oldest price set price-list lput index-price price-list ;;adds in new price at the end ] end ;;calculates the variance to set-var let temp-var 0 ;;stores price variance for calculations if (ticks > 50) [ let i 49 ;;iterates through price-list to calcuate the variance of price changes while [i > 0] [ let m (item (49 - i) price-list) ;;last price let n (item (50 - i) price-list) ;;second-to-last price let j (ln (n / m)) ;;calculate price changes between ticks set temp-var (temp-var + (j * j)) ;;sums running total of price changes set i (i - 1) ;;decrement ] set temp-var (sqrt (temp-var / 49)) ;;standard deviation of price changes during 50 tick period set temp-var (temp-var * (sqrt 252)) ;;annualize the volatility, assuming 252 trading ticks/days in a year set volatility (temp-var * 100) ;;set global variable ] end
There are 7 versions of this model.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| Mark Xue Market Model.png | preview | Preview for 'Mark Xue Market Model' | over 12 years ago, by Mark Xue | Download |
| Xue_Mark_FinalPaper_v1.pdf | Final Project Paper v1 | almost 12 years ago, by Mark Xue | Download | |
| Xue_Mark_FinalPaper_v2.pdf | Final Project Paper v2 | almost 12 years ago, by Mark Xue | Download | |
| Xue_Mark_FinalPaper_v3.pdf | Final Project Paper v3 | almost 12 years ago, by Mark Xue | Download | |
| Xue_Mark_Poster.pdf | Final Project Poster Slides | over 12 years ago, by Mark Xue | Download | |
| XueMark_June3.pdf | progress report | over 12 years ago, by Mark Xue | Download | |
| XueMark_May13.pdf | XueMark_May13 | over 12 years ago, by Mark Xue | Download | |
| XueMark_May20.pdf | progress report | over 12 years ago, by Mark Xue | Download | |
| XueMark_May27.pdf | progress report | over 12 years ago, by Mark Xue | Download |
This model does not have any ancestors.
This model does not have any descendants.
Download this model
Doug Edmunds
run time error
(pertains to version 7 with description "changed graphs" 1. First run-time error: Can't take logarithm of -0.026. error while observer running LN called by procedure SET-VAR called by procedure GO called by Button 'go' This line is highlighted let j (ln (n / m)) ;;calculate price changes between ticks 2. in a different run, got a divide by zero run-time error on that same line
Posted over 11 years ago