NETLOGO: Storing and using the value of a variable in the last 3 ticks

一世执手 提交于 2019-12-24 10:24:47

问题


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!


回答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)



来源:https://stackoverflow.com/questions/55652441/netlogo-storing-and-using-the-value-of-a-variable-in-the-last-3-ticks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!