FinalModel Jean van Haperen
Model was written in NetLogo 5.0.5
•
Viewed 178 times
•
Downloaded 21 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
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
breed [fundamentals fundamental] breed [feedbacks feedback] breed [opportunists opportunist] breed [randomnists randomnist] breed [learners learner] fundamentals-own [ ] feedbacks-own [ ] opportunists-own [ ] learners-own [ groupie ] turtles-own [ donottakeintoaccountinvaluationself pricepaid pricereceived profit valuation stock ;new in this model bidprice askprice bidyet askyet option traded? counttraded correctedforilliquidity? money valueself ] globals [ runtime pricet pricetmedian pricet-1 pricet-2 pricet-3 dividendpaid NumberOfTradersWhoTradedThisTurn NumberOfStocksTradedThisTurn tradesthisperiod tradeslastperiod numberofturnsnotrade fundamentalvalue dividendlist dividend dividendlastperiod sumdividends chanceofopportunism testvariablereducingopportunism LastTradesLessOpportunism sdevinpricespaid ] to setup clear-all set-default-shape fundamentals "house" set-default-shape feedbacks "person" set-default-shape opportunists "pentagon" set-default-shape randomnists "arrow" set-default-shape opportunists "x" create-ordered-fundamentals Numberoffundamentals [setxy random-ycor random-xcor set color white] create-ordered-randomnists Numberofrandomnists [setxy random-ycor random-xcor set color white] create-ordered-feedbacks Numberoffeedbacks [setxy random-ycor random-xcor set color white] create-ordered-opportunists Numberofopportunists [setxy random-ycor random-xcor set color white] create-ordered-learners Numberoflearners [setxy random-ycor random-xcor set color white] setup1 set runtime 0 set tradesthisperiod 1 set NumberOfTradersWhoTradedThisTurn 0 set NumberOfStocksTradedThisTurn 0 ask turtles [set valuation 360 set stock noStocksperTrader] if record? = 1 [ let file user-new-file if is-string? file [ ;; If the file already exists, we begin by deleting it, otherwise ;; new data would be appended to the old contents. if file-exists? file [ file-delete file ] file-open file file-type trendvalue file-type "," file-type numberoffundamentals file-type "," file-type numberoffeedbacks file-type "," file-type numberofopportunists file-type "," file-type numberofrandomnists file-type "," file-type numberoflearners file-type "," file-type changeinfundamentalvalue file-type "," file-type dividendfunction file-type "," file-type bidspread file-type "," file-type noStockspertrader file-type "," file-type Dividendpayout file-type "," file-type timePeriods file-type "," file-print "-" file-print " " ;; record the initial turtle data ]] end to setup1 reset-ticks set sumdividends 0 set runtime runtime + 1 set pricet 360 ; changed in v10 set pricet-1 360; changed in v10 set pricet-2 360 set pricet-3 360 ask turtles [set donottakeintoaccountinvaluationself 0] ask learners [set donottakeintoaccountinvaluationself 1] set fundamentalvalue 360 set numberofturnsnotrade 0 ask turtles [set correctedforilliquidity? 0] ask turtles [set valuation 360 set stock noStocksperTrader set money 10000 set valueself money ] set dividendpaid 1 ask turtles [set profit 0 ] set dividendlist [36 4 -16 -24 ] if dividendpayout = 1 [set dividendpaid dividendpaid * -1] if dividendpayout = 2 [set dividendpaid 0] ifelse dividendpaid = 1 [set dividend one-of dividendlist] [set dividend 0] setup-plots ; changed in v10 update-plots ; changed in v10 end to go if ticks >= timePeriods and runtime >= 999 [stop] if ticks >= timePeriods [setup1] ask turtles [set correctedforilliquidity? 0 set pricepaid 0 ] ask learners [set groupie 0] set sdevinpricespaid 0 ifelse tradesthisperiod = 0 [set numberofturnsnotrade numberofturnsnotrade + 1][set numberofturnsnotrade 0] set tradesthisperiod 0 set tradeslastperiod tradesthisperiod set tradesthisperiod 0 ask turtles [set traded? 0 set counttraded 0] set NumberOfTradersWhoTradedThisTurn 0 set NumberOfStocksTradedThisTurn 0 set dividendlastperiod dividend timedevelopprices if ticks > 0 [set sumdividends sumdividends + dividend] set fundamentalvalue fundamentalvalue + changeinfundamentalvalue ask fundamentals [valuatefundamental] ask feedbacks [valuatefeedback] ask randomnists [valuaterandomnists] ask opportunists [valuateopportunist] ask learners [valuatelearners] ask turtles[if tradeslastperiod = 0 [correctvaluationforliquidity]] ask turtles [recolor] if dividendpayout = 1 [set dividendpaid dividendpaid * -1] ifelse dividendpaid = 1 [set dividend one-of dividendlist] [set dividend 0] ;new in this model ask turtles [set bidyet 0 set askyet 0] remove-links ask-concurrent turtles [if valuation > pricet-1 [without-interruption [bidp]]] ask-concurrent turtles [if valuation < pricet-1 and stock > 0 [without-interruption [askp]]] ; ask-concurrent turtles [if valuation = pricet-1 ; [ifelse random-float 1 <= 0.5 [without-interruption[bidp]][if stock > 0 [without-interruption[askp]]]]] ;foreach sort-by [[valuation] of ?1 > [size] of ?2] turtles with [bidyet = 1] ; without-interruption [ask-concurrent turtles [ without-interruption [trade] ] ] ; giving the initiative to those who want to buy, with the highest valuation first if tradesthisperiod > 1 [set sdevinpricespaid standard-deviation [pricepaid] of turtles with [pricepaid != 0]] ask turtles [if ticks > 0 [set profit profit + dividend * stock]] remove-links setprice ask turtles [determinevalue] if record? = 1 [ record ] tick end to timedevelopprices set pricet-3 pricet-2 set pricet-2 pricet-1 set pricet-1 pricet end to valuateopportunist Chancify ifelse pricet-1 - pricet-2 > 0 and pricet-1 > fundamentalvalue [ifelse random-float 1 < ChanceOfOpportunism [set valuation pricet-1 + random-normal 50 20] [set valuation fundamentalvalue + random-normal 0 SDEV]] [set valuation fundamentalvalue + random-normal 0 SDEV] if NoOpportunists? = 1 [set valuation fundamentalvalue + random-normal 0 SDEV] end to valuaterandomnists set valuation pricet-1 + random-normal 0 2 * SDEV if NoRandomnists? = 1 [set valuation fundamentalvalue + random-normal 0 SDEV] end to valuatelearners if [valueself] of max-one-of opportunists [valueself] = max [valueself] of turtles with [donottakeintoaccountinvaluationself = 0] [valuateopportunist set groupie 1 set shape "pentagon" ] if [valueself] of max-one-of randomnists [valueself] = max [valueself] of turtles with [donottakeintoaccountinvaluationself = 0] [valuaterandomnists set groupie 2 set shape "arrow" ] if [valueself] of max-one-of feedbacks [valueself] = max [valueself] of turtles with [donottakeintoaccountinvaluationself = 0] [valuatefeedback set groupie 3 set shape "person" ] if [valueself] of max-one-of fundamentals [valueself] = max [valueself] of turtles with [donottakeintoaccountinvaluationself = 0] [valuatefundamental set groupie 4 set shape "house"] if NoLearners? = 1 [set valuation fundamentalvalue + random-normal 0 SDEV] end to Chancify if ticks > 10 [set testvariablereducingopportunism testvariablereducingopportunism + 1] set LastTradesLessOpportunism 1 - 0.25 * testvariablereducingopportunism let profitfromcapitalgains (pricet-1 - pricet-3) let profitfromdividends dividend + dividendlastperiod if profitfromdividends > profitfromcapitalgains [set ChanceOfOpportunism 0 * LastTradesLessOpportunism] ifelse profitfromdividends != 0 [if profitfromdividends <= profitfromcapitalgains [set ChanceOfOpportunism (profitfromcapitalgains / profitfromdividends - 1) * LastTradesLessOpportunism]] [set ChanceOfOpportunism 0] if ChanceOfOpportunism > 0.8 [set ChanceOfOpportunism 0.8 * LastTradesLessOpportunism] end to valuatefundamental set valuation fundamentalvalue + dividend * dividendfunction + random-normal 0 SDEV if NoFundamentals? = 1 [set valuation fundamentalvalue + random-normal 0 SDEV] end to valuatefeedback set valuation trendvalue * (pricet-1 - pricet-2) + pricet-1 + random-normal 0 SDEV if NoFeedbacks? = 1 [set valuation fundamentalvalue + random-normal 0 SDEV] end to remove-links ask-concurrent links [die] end to bidp set bidprice bidspread * (valuation - pricet-1) + pricet-1 set bidyet 1 set pricepaid 0 end to askp set askprice bidspread * (valuation - pricet-1) + pricet-1 set askyet 1 set pricepaid 0 end to trade set option random 2 let valuationself valuation if option = 1 [if traded? = 0[ if any? turtles with [askyet = 1 and askprice < valuationself and stock > 0 and self != myself] [buyfromasker exchangewithasker determinepricewithasker removeask]] ] if option = 1 [ if traded? = 0 [ if any? turtles with [bidyet = 1 and bidprice > valuationself and stock > 0 and self != myself] [selltobidder exchangewithbidder determinepricewithbidder removebid]] ] if option = 0 [if traded? = 0 [ if any? turtles with [bidyet = 1 and bidprice > valuationself and stock > 0 and self != myself] [selltobidder exchangewithbidder determinepricewithbidder removebid]] ] if option = 0 [if traded? = 0 [if any? turtles with [askyet = 1 and askprice < valuationself and stock > 0 and self != myself] [buyfromasker exchangewithasker determinepricewithasker removeask]] ] ; create-links ;if not notlinked? [exchange-stocks] ;if notlinked? [set pricepaid 0] ;remove-links end to buyfromasker let valuationself valuation create-link-with one-of turtles with [askyet = 1 and askprice < valuationself and stock > 0 and self != myself] end to selltobidder let valuationself valuation create-link-with one-of turtles with [bidyet = 1 and bidprice > valuationself and self != myself] end to create-links without-interruption [ask turtles with [bidyet = 1 and notlinked?] [if any? turtles with [askyet = 1 and notlinked?] [create-link-with one-of turtles with [askyet = 1 and notlinked?]]]] end to exchangewithasker set stock stock + 1 set tradesthisperiod tradesthisperiod + 1 ask link-neighbors [set stock stock - 1 set counttraded 1] set traded? 1 set counttraded 1 set NumberOfTradersWhoTradedThisTurn NumberOfTradersWhoTradedThisTurn + 2 set NumberOfStocksTradedThisTurn NumberOfStocksTradedThisTurn + 1 end to exchangewithbidder set stock stock - 1 set tradesthisperiod tradesthisperiod + 1 ask link-neighbors [set stock stock + 1 set counttraded 1] set traded? 1 set counttraded 1 set NumberOfTradersWhoTradedThisTurn NumberOfTradersWhoTradedThisTurn + 2 set NumberOfStocksTradedThisTurn NumberOfStocksTradedThisTurn + 1 end to determinepricewithasker let pricedeterminant [askprice] of one-of link-neighbors with [self != myself];one-of link-neighbors set pricepaid pricedeterminant set money money - pricepaid ask one-of link-neighbors with [self != myself] [set money money + askprice] calculate-profits end to determinepricewithbidder let pricedeterminant [bidprice] of one-of link-neighbors with [self != myself];one-of link-neighbors set pricepaid pricedeterminant set money money + pricepaid ask one-of link-neighbors with [self != myself] [set money money - bidprice] calculate-profits end to removeask ask one-of link-neighbors [set askyet 0] ask one-of links [die] end to removebid ask one-of link-neighbors [set bidyet 0] ask one-of links [die] end to calculate-profits set profit profit + 360 - pricepaid ask one-of link-neighbors with [self != myself] [set profit profit + [pricepaid] of one-of link-neighbors with [self != myself] - 360] end to-report notlinked? report (count link-neighbors < 1) end to setprice ifelse tradesthisperiod != 0 [set pricet mean [pricepaid] of turtles with [traded? = 1]][set pricet mean [valuation] of turtles with [stock > 0]] ; check this ifelse command! ifelse tradesthisperiod != 0 [set pricetmedian median [pricepaid] of turtles with [traded? = 1]][set pricetmedian median [valuation] of turtles with [stock > 0]] end to correctvaluationforliquidity if stock > 0 [set valuation 0.2 * numberofturnsnotrade * fundamentalvalue + (1 - (numberofturnsnotrade * 0.2)) * valuation set correctedforilliquidity? 1] end to determinevalue if ticks > 0 [set money money + stock * dividend] set valueself money + pricet * stock end to recolor if valuation > pricet-1 [set color blue] if valuation < pricet-1 [set color red] if valuation = pricet-1 [set color white] end to record file-type ticks file-type "," file-type pricet file-type "," file-type mean [valuation] of fundamentals file-type "," file-type mean [valuation] of feedbacks file-type "," file-type mean [valuation] of opportunists file-type "," file-type mean [valuation] of learners file-type "," file-type mean [valuation] of randomnists file-type "," file-type dividend file-type "," file-type numberofturnsnotrade file-type "," file-type NumberOfTradersWhoTradedThisTurn file-type "," file-type NumberOfStocksTradedThisTurn file-type "," file-type sum [valueself] of fundamentals file-type "," file-type sum [valueself] of feedbacks file-type "," file-type sum [valueself] of opportunists file-type "," file-type sum [valueself] of learners file-type "," file-type sum [valueself] of randomnists file-type "," file-type mean [groupie] of learners file-type "," file-type count turtles with [counttraded = 1] file-type "," file-type count turtles with [bidyet = 1] file-type "," file-type count turtles with [askyet = 1] file-type "," file-type fundamentalvalue file-type "," file-type sdevinpricespaid file-type "," file-type pricetmedian file-type "," file-print SDEV end
There is only one version of this model, created over 10 years ago by Jean van Haperen.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
FinalModel Jean van Haperen.png | preview | Preview for 'FinalModel Jean van Haperen' | over 10 years ago, by Jean van Haperen | Download |
This model does not have any ancestors.
This model does not have any descendants.