Luca Gallorini Giulio Poggiaroni

Simulation models for economics

Project work on

"Comparative advantages."

 

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


Here you can find an introduction to the Comparative advantages application.


powered by NetLogo

view/download model file: comparative_advantages.nlogo

WHAT IS IT?

The model aims to reproduce some dynamics of international trade, such as comparative advantages, specialization and exchange-rate shocks (depreciation and appreciation). Given two communities of consumers/producers and two goods and a few additional conditions, we observe how the international trade will develop and so how agents will react to external changes.

HOW IT WORKS

Each agent is at the same time producer and consumer of both goods and has a certain level of “desire” (turtle variable). If the amount of wine and bread will be lower (after consumption) than the value of desire, the owner will be defined as a “potential-buyer”, in the opposite case he will be a “potential-seller” (this happens through the modification of the variable “status”). At this point Agents will start to trade within their own community, creating links between buyers and sellers; in this exchange sellers will transfer their surplus amount towards buyers that, according to their new amount of resources, will change their status or not.
If there are still “unsatisfied” buyers, international trade will take place and we will see buyers of both countries creating links with sellers of the other community. The same dynamic of exchange previously seen will take place but this time with more complicate features; also prices and exchange-rates will enter the relation.

HOW TO USE IT

First of all press “setup” to create the world with our two communities of agents, after this step set the amount of work-hours that we want to assign to our agents ( using the appositive slider) and then press the button “work-hours endowment”

Before starting the simulation set at your choice the sliders we have inserted in order to give different features to the situation and observe what you are interested in.

At last press “production-consumption” in order to start the simulation.

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

What we have tried to observe in our experiment is to observe what happens with different values of the exchange rate ( also modifyng values of productivity in the setup) and with higher values for basic needs and consumption propensions

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model’s URL on the web if it has one, as well as any other necessary credits, citations, and links)

CODE

turtles-own [ bread work-hours-B work-hours-A wine desire status exchange-amount bread-productivity wine-productivity satisfaction 
  whours_b_A whours_w_A whours_b_B whours_w_B offer-price-A offer-price-B reserve-price-A reserve-price-B ]
globals [ count_sellerA count_buyerA coll count_sellerB count_buyerB sat totResP CountsellerA CountsellerB ] 
breed [ Agents-of-A Agent-of-A ]
breed [ Agents-of-B Agent-of-B ]


to setup 
  ca  
  ask patches with [pxcor >= 0 and pycor > 0 ]  [ set pcolor green ]
  ask patches with [ pxcor >= 0 and pycor <= 0 ]  [ set pcolor green ]
  create-Agents-of-A Agent-CountryA [ setxy random-normal 8 1  random-ycor ]
  create-Agents-of-B Agent-CountryB [ setxy random-normal -7 1 random-ycor ]
  ask turtles [ set shape "person" ]
  ask Agents-of-A [ set color blue set bread-productivity 1 + random-normal 0.5 0.5  set wine-productivity 0.8 + random-normal 0.1 0.1  ]
  ask Agents-of-B [ set color red set bread-productivity 0.3 + random-normal 0.1 0.1 set wine-productivity 1 + random-normal 0.1 0.1  ]
  reset-ticks
  set coll 0
  set sat 0.061
end

; set work hours endowment

to work_hours_endowment
  ask Agents-of-A [ set work-hours-A work-hours-A-val set whours_w_A work-hours-A-val / 2 set whours_b_A work-hours-A-val / 2 ]
  ask Agents-of-B  [ set work-hours-B work-hours-B-val set whours_w_B work-hours-B-val / 2 set whours_b_B work-hours-A-val / 2 ]
end


to production-consumption
  
  ask turtles [ set desire basic-needs + random-normal 1 0.5 ]
  
  ; production A
  
  set count_sellerA 0
  set count_buyerA 0
  ask Agents-of-A  [ set work-hours-A work-hours-A-val  set bread ( bread-productivity ) * ( whours_b_A ) set wine ( wine-productivity ) * ( whours_w_A ) ]
 
  ; production B 
   
  set count_sellerB 0
  set count_buyerB 0
  ask Agents-of-B  [ set work-hours-B work-hours-B-val set bread ( bread-productivity ) * ( whours_b_B ) set wine ( wine-productivity ) * ( whours_w_B ) ]
 
  ; consumption
  

  ask Agents-of-A [ set bread ( ( bread ) - ( bread )  *  ( mpcb ) ) set wine ( ( wine ) - ( wine )  *  ( mpcw ) )  ]
  ask Agents-of-B [ set bread ( ( bread ) - ( bread )  *  ( mpcb ) ) set wine ( ( wine ) - ( wine )  *  ( mpcw ) )  ]

  ;trade
  
  ask turtles [ set exchange-amount 0 ] 
  ask Agents-of-A [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerA count_sellerA + 1 ] [ if desire > wine + bread  [set status "potential-buyer" set count_buyerA count_buyerA + 1 ] ]]
  if  count_sellerA > 0 and count_buyerA > 0  
    [ ask Agents-of-A  with [  status = "potential-buyer"  ] [ create-link-to one-of Agents-of-A with [ status = "potential-seller" ] ] ]  
  if  count_buyerA > 0 and count_sellerA > 0 and count links > 0  
    [ ask Agents-of-A with [  status = "potential-seller"  ] [ set exchange-amount ( bread + wine ) - desire ]]
  if  count_sellerA > 0 and count_buyerA > 0 and count links > 0  
     [ ask one-of Agents-of-A with [ status = "potential-buyer" ] [ set exchange-amount  [ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]  
      ] set count_sellerA count_sellerA - 1]
  
  ask Agents-of-B [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerB count_sellerB + 1 ] [ if desire > wine + bread  [set status "potential-buyer" set count_buyerB count_buyerB + 1 ] ]]
  if  count_sellerB > 0 and count_buyerB > 0  
    [ ask Agents-of-B  with [  status = "potential-buyer"  ] [ create-link-to one-of Agents-of-B with [ status = "potential-seller" ] ] ]  
  if  count_buyerB > 0 and count_sellerB > 0 and count links > 0  
    [ ask Agents-of-B with [  status = "potential-seller"  ] [ set exchange-amount ( bread + wine ) - desire ]]
  if  count_sellerB > 0 and count_buyerB > 0 and count links > 0  
    [ ask one-of Agents-of-B with [ status = "potential-buyer" ] [ set exchange-amount  [ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]  
     ] set count_sellerB count_sellerB - 1 ]
  
  
  
  set coll count links 
  ask links [ die ]
 
  ask Agents-of-A with [ status = "potential-buyer" ] [ set reserve-price-A whours_w_A + random-normal 1 0.2  ifelse wine < bread [ set wine ( wine ) + exchange-amount ][ set bread ( bread ) + exchange-amount ] ]
  ask Agents-of-B with [ status = "potential-buyer" ] [ set reserve-price-B whours_b_B + random-normal 1 0.2  ifelse wine < bread [ set wine ( wine ) + exchange-amount ][ set bread ( bread ) + exchange-amount ] ]
 
 
  ask Agents-of-A with [ status = "potential-buyer" ] [ set exchange-amount 0 ]     ;AGGIUNTA 30/06
  ask Agents-of-B with [ status = "potential-buyer" ] [ set exchange-amount 0 ]     ;AGGIUNTA 30/06
  
  ask turtles with [ status = "potential-seller" ] [ set totResP sum [ reserve-price-A + reserve-price-B ] of turtles with [ status = "potential-buyer" ] ]  ; AGGIUNTA 02/07

  ask Agents-of-A with [ status = "potential-seller" ] [ set offer-price-A  0.9902 * (totResP / (10 + CountsellerA) ) - ( whours_b_A * 0.001  + random-normal 0.8 0.1  ) ifelse wine > bread 
    [ ifelse wine > exchange-amount [set wine ( wine ) - exchange-amount ] [set wine 0 ]][ ifelse bread > exchange-amount [set bread ( bread ) - exchange-amount ] [set bread 0]] set exchange-amount 0  ]
  ask Agents-of-B with [ status = "potential-seller" ] [ set offer-price-B 0.9902 * (totResP / (10 + CountsellerB) ) - ( whours_w_B * 0.001  + random-normal 0.8 0.1  ) ifelse wine > bread 
    [ ifelse wine > exchange-amount [set wine ( wine ) - exchange-amount ] [set wine 0 ]][ ifelse bread > exchange-amount [set bread ( bread ) - exchange-amount ] [set bread 0]] set exchange-amount 0  ]
 
 ask Agents-of-A with [ status = "potential-buyer" ] [ if  desire < wine + bread [ set status "sazio" ] ]

 ask Agents-of-B with [ status = "potential-buyer" ] [ if  desire < wine + bread [ set status "sazio" ] ]
   
   
   ; adaptive mechanism
  
  ask Agents-of-A [ ifelse  wine + bread < desire [ set satisfaction ( satisfaction + 0.06 ) ] [ set satisfaction ( satisfaction - 0.06 ) ] ]
  if ticks = 2000 [ ask Agents-of-A with [ satisfaction <= (ticks ) * sat ] [ set whours_b_A whours_b_A + 1 set whours_w_A whours_w_A - 1 ] ]
  if ticks = 4000 [ ask Agents-of-A with [ satisfaction <= (ticks ) * sat ] [ set whours_b_A whours_b_A + 1 set whours_w_A whours_w_A - 1 ] ]
  if ticks = 6000 [ ask Agents-of-A with [ satisfaction <= (ticks ) * sat ] [ set whours_b_A whours_b_A + 1 set whours_w_A whours_w_A - 1 ] ]
  if ticks = 8000 [ ask Agents-of-A with [ satisfaction <= (ticks ) * sat ] [ set whours_b_A whours_b_A + 1 set whours_w_A whours_w_A - 1 ] ]
  if ticks = 10000 [ ask Agents-of-A with [ satisfaction <= (ticks ) * sat ] [ set whours_b_A whours_b_A + 1 set whours_w_A whours_w_A - 1 ] ]
  
  ask Agents-of-B [ ifelse  wine + bread < desire [ set satisfaction ( satisfaction + 0.5 ) ] [ set satisfaction ( satisfaction - 0.6 ) ] ]
  if ticks = 2000 [ ask Agents-of-B with [ satisfaction <= (ticks ) * sat ] [ set whours_b_B whours_b_B - 1 set whours_w_B whours_w_B + 1 ] ]
  if ticks = 4000 [ ask Agents-of-B with [ satisfaction <= (ticks ) * sat ] [ set whours_b_B whours_b_B - 1 set whours_w_B whours_w_B + 1 ] ]
  if ticks = 6000 [ ask Agents-of-B with [ satisfaction <= (ticks ) * sat ] [ set whours_b_B whours_b_B - 1 set whours_w_B whours_w_B + 1 ] ]
  if ticks = 8000 [ ask Agents-of-B with [ satisfaction <= (ticks ) * sat ] [ set whours_b_B whours_b_B - 1 set whours_w_B whours_w_B + 1 ] ]
  if ticks = 10000 [ ask Agents-of-B with [ satisfaction <= (ticks ) * sat ] [ set whours_b_B whours_b_B - 1 set whours_w_B whours_w_B + 1 ] ]
  

; INTERNATIONAL TRADE
 
set count_sellerA 0
set count_buyerA 0
set count_sellerB 0
set count_buyerB 0
     
ask Agents-of-B [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerB count_sellerB + 1 ] [ ifelse desire > wine + bread  [set status "potential-buyer" set count_buyerB count_buyerB + 1 ] [set status "sazio"]]]
ask Agents-of-B with [ status = "potential-seller"] [set exchange-amount ( (wine + bread) - desire ) ]   ;AGGIUNTA 30/06
ask Agents-of-A [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerA count_sellerA + 1 ] [ ifelse desire > wine + bread  [set status "potential-buyer" set count_buyerA count_buyerA + 1 ] [set status "sazio"]]]
      
 
if  count_sellerB  > 0 and count_buyerA > 0 [ if international-trade [ ask Agents-of-A with [ desire > wine + bread and status = "potential-buyer" ] 
  [ create-link-to one-of Agents-of-B with [ status = "potential-seller" ] ] ] ]

if count_sellerB > 0 and count_buyerA > 0 and count links > 0 [ ask one-of Agents-of-A with [ desire > wine + bread and status = "potential-buyer" ] 
    [ if reserve-price-A > [offer-price-B] of [end2] of one-of links with [end1 = myself]
    [set exchange-amount  ( ([ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]) * exchange-rate )    ask  [end2]  of one-of links with [end1 = myself] [ set status "seller"   ] ]]]

;if count_sellerB > 0 and count_buyerA > 0 and count links > 0 [ ask one-of Agents-of-A with [ desire > wine + bread and status = "potential-buyer" ] 
   ; [ if reserve-price-A > [offer-price-B] of [end2] of one-of links with [end1 = myself]
  ;  [set etrade  (([ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]) * exchange-rate ) ] ] ]    ;AGGIUNTA 01/07

  
set count_sellerA 0
set count_buyerA 0
set count_sellerB 0
set count_buyerB 0
     
ask Agents-of-B [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerB count_sellerB + 1 ] [ ifelse desire > wine + bread  [set status "potential-buyer" set count_buyerB count_buyerB + 1 ] [set status "sazio"]]]
     
ask Agents-of-A [ ifelse desire < wine + bread 
    [ set status "potential-seller" set count_sellerA count_sellerA + 1  ] [ ifelse desire > wine + bread  [set status "potential-buyer" set count_buyerA count_buyerA + 1 ] [set status "sazio"]]]
 
ask Agents-of-A with [ status = "potential-seller"] [set exchange-amount ( (wine + bread) - desire) ]  ;AGGIUNTA 30/06


ask links [ die ] 

   
 
if count_sellerA > 0 and count_buyerB > 0 [  if international-trade [ ask Agents-of-B with [ desire > wine + bread and status = "potential-buyer"  ]
  [ create-link-to one-of Agents-of-A with [ status = "potential-seller" ] ] set coll count links ] ]

if count_sellerA > 0 and count_buyerB > 0 and count links > 0 [ ask one-of Agents-of-B with [  desire > wine + bread and status = "potential-buyer"  ]
  [ if reserve-price-B > [offer-price-A] of [end2] of one-of links with [end1 = myself]
  [ set exchange-amount  (([ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]) * ( 1 / exchange-rate))     ask  [end2]  of one-of links with [end1 = myself] [ set status  "seller" ] ]]]


;if count_sellerA > 0 and count_buyerB > 0 and count links > 0 [ ask one-of Agents-of-B with [  desire > wine + bread and status = "potential-buyer"  ]
  ;[ if reserve-price-B > [offer-price-A] of [end2] of one-of links with [end1 = myself]
 ; [ set etrade  (([ exchange-amount ] of [ end2 ] of one-of links with [ end1 = myself ]) * ( 1 / exchange-rate))  ] ] ] ;AGGIUNTA 01/07



 
ask Agents-of-A with [ status = "potential-buyer" ] [  ifelse wine < bread [ set wine ( wine  + exchange-amount )][ set bread ( bread  + exchange-amount )] ]  ;show "eseguito"

ask Agents-of-B with [ status = "potential-buyer" ] [  ifelse wine < bread [ set wine ( wine  + exchange-amount )][ set bread ( bread  + exchange-amount )] ]
  
ask Agents-of-A with [ status = "seller" ] [ set exchange-amount (exchange-amount * ( 1 / exchange-rate)) ifelse wine > bread 
  [ ifelse wine > exchange-amount [set wine ( wine ) - exchange-amount ] [set wine 0 ]][ ifelse bread > exchange-amount [set bread ( bread ) - exchange-amount ] [set bread 0]]  ]
ask Agents-of-B with [ status = "seller" ] [ set exchange-amount (exchange-amount * ( exchange-rate))  ifelse wine > bread 
  [ ifelse wine > exchange-amount [set wine ( wine ) - exchange-amount ] [set wine 0 ]][ ifelse bread > exchange-amount [set bread ( bread ) - exchange-amount ] [set bread 0]]   ]
  
                                                                                                


ask links [ die ]


tick


end