# Basic2FundTypesModel

Model was written in NetLogo 6.0.2
•
Viewed 132 times
•
Downloaded 10 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

globals [ price-change bid-volume ask-volume history ;; list of past prices ] breed [investors investor] breed [traders trader] breed [equities equity] turtles-own [money share buy? sell? wealth strategies ;; list of strategies best-strategy ;; index of the current best strategy prediction ;; prediction whether stock will go up or down based on trend ] to setup clear-all ;; set background color ask patches [set pcolor yellow] ;; mark investors and traders with color create-investors investor-number [set color orange] create-traders trader-number [set color blue] create-equities 1 [set color green] ;; initialize the past prices randomly so that traders have a history set history n-values(memory-size * 2) [random 10] ask investors [ set shape "circle" set money 100 set share 10 set wealth money + share * share-price fd 10] ask traders [ set shape "square" set money 100 set share 10 set strategies n-values number-strategies [random-strategy] set best-strategy first strategies set wealth money + share * share-price update-strategies fd 15] ask equities [ set shape "circle" set size 1.5] reset-ticks end to go ask traders [ set prediction predict-share-price best-strategy sublist history 0 memory-size set buy? (prediction >= share-price) set sell? (prediction <= share-price) ] ask investors [ if money > share-price[ set buy? (share-price < true-value and -10 < price-change and price-change < 10) ] ] ask investors[ set sell? (price-change < -10) ] ask traders with [buy?][ set share share + 1 set money money - share-price set bid-volume bid-volume + 1 ] ask traders with [sell?][ set share share - 1 set money money + share-price set ask-volume ask-volume + 1 ] ask investors with [buy?][ set share share + 1 set money money - share-price set bid-volume bid-volume + 1 ] ask investors with [sell?][ set share share - 1 set money money + share-price set ask-volume ask-volume + 1 ] ask traders[ set wealth share-price * share set color scale-color blue wealth (max[wealth] of traders + 1) 0 ] ask investors[ set wealth share-price * share set color scale-color orange wealth (max[wealth] of traders + 1) 0 ] ;; update price set price-change bid-volume - ask-volume set share-price share-price + price-change ;; update share-price history set history fput share-price but-last history ;; have the traders decide what the new best strategy is ask traders [update-strategies] tick end ;; determine which strategy would have predicted the best results had it been used ;; the best strategy is the one that resulted in the most price-change gain to update-strategies let best-score memory-size * 100 + 1 foreach strategies [ the-strategy -> let score 0 let day 1 repeat memory-size [ set prediction predict-share-price the-strategy sublist history day (day + memory-size) set score score + abs(price-change) set day day + 1 ] if (score >= best-score)[ set best-score score set best-strategy the-strategy ] ] end ;; reports an agent's prediction of the current price. The agent puts a set of weight for each time period ;; strategy described by formula p(t) = p(t-1) * a(t-1) + p(t-2) * a(t-2) +...+ p(t-memory-size) * a(t-memory-size) + c * 100 ;; p(t) is the price at time t, a is the weight for time t, c is a constant, memory-size is how far the agents look back. to-report predict-share-price [strategy subhistory] ;;the first element of the strategy is the constant c, the price prediction in the absence of any other data. ;; then we multiply each day in the history by its respective weight. report 100 * first strategy + sum(map[[weight day] -> day * weight] butfirst strategy subhistory) end ;; this reports a random strategy, which is a set of weights from -1.0 to 1.0. to-report random-strategy report n-values (memory-size + 1)[1.0 - random-float 2.0] end

There is only one version of this model, created about 3 years ago by Nam Bui.

This model does not have any ancestors.

This model does not have any descendants.