1

I am trying to model a stock market. I am trying to give agents a certain kind of behaviour to base their prediction of the prices on. So basically, every agent predicts the price of the share. In the Setup procedure, a random predicted price is assigned to each agent. As the time passes, the predicted price is supposed to be calculated as follows: total of predicted price of the last 3 periods / 3

I don't know how to approach this issue. I tried using the last command but it does not work. I was thinking about making a sort of vector but I couldn't do so. Any leads?

This is what I have tried so far:

ask turtles [
set pre-price (pre-price + last [pre-price] of turtles + last [last [pre-price] of turtles] of turtles) / 3 ]
end

The last command does not work as I want it to work because I have tried to manually calculate the results and they don't reconcile with this command. Any idea on how to go about it?

Thank you!

Alea
  • 121
  • 3

1 Answers1

1

This is actually a very interesting bug.

The issue is that inside your turtle call, you assume all the turtles "pre-price" is static; however, with each agent, they are assigning the variable.

I'd suggest to introduce another variable which explicitly stores the pre-prices for each tick (using a matrix/nested list)

mattsap
  • 3,790
  • 1
  • 15
  • 36
  • Any idea on how to use a matrix? The expected price is a function and the matrix operator expects a literal value in it? – Alea Apr 12 '19 at 16:49
  • I assumed price was a number. Matrix only work with numbers. Seems like that options not valid. Instead, you may want to just do a nest list with a task for each element. However, I didn't think that your price was a function that changes over time (i.e. average of last 3 ticks may change to average of last 5 ticks). Why not just store the results of applying the function in the nest list? So each inner list represents the pre-prices for a particular tick for each agent. – mattsap Apr 12 '19 at 17:16
  • basically the pre-price is a variable that would change on each tick as it averages the values of itself in the last 3 periods. So, if pre-price in 1st period was 0, 2nd period was 2 and 3rd period was 6 then in the 4th period it should be 8/3. I am also unsure how to use the lists for this. The list command does not allow for functions and I can't input particular numbers in it? :/ – Alea Apr 12 '19 at 17:39