Oligopoly Bid Price

No preview image

1 collaborator

Default-person Steven Kimbrough (Author)

Tags

"probe and adjust" 

Tagged by Steven Kimbrough over 8 years ago

markets 

Tagged by Steven Kimbrough over 8 years ago

oligopoly 

Tagged by Steven Kimbrough over 8 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.4 • Viewed 579 times • Downloaded 53 times • Run 0 times
Download the 'Oligopoly Bid Price' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


NOTE WELL

The documentation below is incomplete. It is in draft form only. What is here, however, is correct (or so I think).

HOW TO RUN THE MODEL

  1. Set values for the various sliders and switches (in green) on the Interface tab.

The default values should be OK, so you can skip this step at first.

  1. Click the Setup button.

  2. Click the Go button.

The Go button is an "always" button, so the run will continue until you stop it, which you can do by clicking the Go button again.

WHAT DO YOU SEE WHEN YOU RUN THE MODEL?

Most prominently you see an active plot entitled "Current Bid Price". The simulated market proceeds in episodes in which each participating firm offers to supply the entire demand of the market at a bid price. The market selects the price of the lowest bidder, and a new episode begins.

What you see plotted are two things. In black is the monopolist's price, given the (linear) demand curve specified via a number of sliders (discussed below), PROVIDING THE MONOPOLIST HAS 0 COSTS. This is just: m-price = quantityIntercept / (2 * dSlope). quantityIntercept is given initially by the qIBase slider on the Interface tab. dSlope is given by the dSlope slider.

In red on the plot is the lowest price bid in the episode. Also plotted are the monopoly price of Firm0 (agent 0) given its costs (this is in cyan) and the monopoly price of Firm1 (agent 1) given its costs (this is in magenta).

In addition to the "Current Bid Price" plot there are several monitors that report information during a run ...

  1. Monopoly Price for firm 0

This is the numerical value of the cyan line in the above plot.

  1. Monopoly Price for firm(s) 1

This is the numerical value of the magenta line in the above plot.

  1. avgWinningBid

This is the running average over all the episodes in the run of the (price) value of the winning bid.

  1. runningAverageBid

This is the average of the (price) value of the winning bid for the last N episodes. N is set by the slider runningAvgLength. (At the inception of the run, before N episodes have been completed, runningAverageBid is just the average winnng price of the episodes that have been completed.)

WHAT ARE THE UPDATETYPE CHOOSERS ABOUT?

On the Interface tab you will find two choosers for selecting update policies to be used by the agents. "updateTypeFirm0" sets the policy for firm (agent) 0. "updateTypeFirm1" sets the policy for all higher-numbered firms (agents).

See the procedure Postpare-Episode for the implementation of these policies. The procedure Observe-and-Record is also important.

In brief, "Own Returns" is a myopic and selfish policy. At the end of the agent's epoch the agent raises or lowers its current price (about which it bids randomly using Probe and Adjust) in the direction of its own returns exclusively. In particular, if the agent fails to win the bid during an episode, it records a 0 reward for that episode. Then, if its bids during the epoch about its current price returned on average more than its bids below the current price, then the agent raises its price; and similarly for lowering the price.

Using the "Market Returns" policy, the agent takes the industry view and records what it would have received had it won the bid. Then, if its bids during the epoch about its current price would have returned on average (had it won each of them) more than its bids below the current price, then the agent raises its price; and similarly for lowering the price.

Using the "Market Returns and Own Returns" policy, the agent first determines whether it has won any bids during the epoch. If not, it lowers its current price. If it has won some bids, then the agent applies the "Market Returns" policy.

WHAT DO THE MONITORS REPORT?

The monitor labelled "Agent0 Epoch Ave. Reward" displays the average reward per episode received by firm 0 (agent 0) during the agent's previous epoch. During an epoch, each agent records the reward it achieved for each episode. If the agent did not win the bid, the reward is 0, otherwise it is the usual: price * quantity - cost * quantity. See the procedure Observe-and-Record. At the end of an epoch, the agent averages its rewards over the episodes in the epoch and this is what is reported in the monitor for agent 0. See the procedure Postpare-Episode.

The monitor labelled "Agent1 Epoch Ave. Reward" works just like "Agent0 Epoch Ave. Reward", but for firm (agent) 1.

WHAT DO THE SLIDERS, SWITCHES, AND CHOOSERS DO?

They set parameters, global variables, for the run of the model.

numPandAFirms

This model, oligopolyBidPrice.nlogo, is about markets in which there are a few firms competing to supply the entire demand in a winner-take-all-by-episode market. This chooser lets the user set the number of firms in the market who will be using Probe and Adjust (explained below) to arrive at their bids.

Note that the firm-specific parameters, set by sliders to the left of the plot, all end in ...Firm0 or ...Firm1. If there are two firms in the run, i.e., if numPandAFirms is set to 2, they are called firm 0 and firm 1, and are assigned the parameter values as indicated. If there is one firm in the model, it gets the parameter values ...Firm0. Finally, if there are 3 or more firms in the model, they ALL get the parameter values ...Firm0.

/* more to do here*/

WHAT IS IT?

This model explores how oligopolists might discover their prices in the face of, here, a linear demand function. The discovery process does not allow explicit coordination or collusion between the duopolists. Instead, a main purpose of this model is to investigate the potential for tacit collusion by the duopolists, using information gained from repeated interactions in the market.

In this model, the firms adjust prices. During each market episode, each firm announces its unit price. The market satisfies its entire demand at the lower of the two prices (or randomly in the case of a tie). This is, then, a winner-take-all market during each episode.

Prices are being adjusted and price is a continuous variable. The firms in this program use what I call a "Probe and Adjust" model, and a very simple one at that.

1.  set

Each agent begins with a current value, here currentPriceFirmX (X = 1, 2), set by initialPriceFirmX in the Interface tab. Play is organized by epochs, each containing a number of episodes. In each episode, the agent probes its market by offering a price in the range [currentPriceFirmX - deltaFirmX, currentPriceFirmX + deltaFirmX]. The agent records the revenue it gets from the probe, classifying the revenue as coming from a price offered that is either above or below its current price. When the epoch is over (a number of episodes, set by epochLengthFirmX in the Interface tab), the agent determines whether on average it did better by offering more than its current price or less. Depending on the results, it increases its currentPriceFirmX by epsilonFirmX or decreases it by epsilonFirmX. Then a new epoch begins. Both deltaFirmX and epsilonFirmX are set in the Interface. The key point about this model is that neither agent has access to the demand function, except as it responds to prices placed to the market.

MONOPOLY PRICE-SETTING

Introductory textbooks in microeconomics will tell a story roughly as follows. The market's demand, Q (think: quantity demanded), for our product is a linear function of its price, P:

(1) Q(P) = Q = c - dSlope*P

Here, c is a constant, representing the quantity demanded when price is 0 and, since we are linear, the price point at which demand disappears when the price is too high (when dSlope*P = c). (We assume that c, dSlope > 0, so -dSlope < 0.)

Let us assume that the cost of production (for the monopolist) is k*Q

The profit, pi, made by the monopolist is PQ (since the cost of production is 0, we need only account for revenue, which is defined here as PQ).

(3) pi = PQ = (a - dSlopeQ)Q = aQ - dSlopeQ*2

The monopolist will seek to maximize pi, which can be done by a simple exercise with the calculus.

(4) dpi/dQ = a - 2dSlopeQ

Setting a - 2dSlopeQ to zero and solving for Q yields

(5) Q = a/(2*dSlope)

So Q in (5) is Q*, the optimal quantity for the monopolist to put on the market.

(Checking that d2 pi/dQ2 = -2*dSlope < 0 verifies that we indeed have found a maximum.)

See, for example, IntermediateMicroeconomics:AModernApproach, 6th ed., by Hal. R. Varian. I draw explicitly on MicroeconomicTheory, 2nd ed., 1978, The Dryden Press, Hinsdale, Illinois, by Walter Nicholson. See "Appendix to Chapter 13: Models of Interdependent Output Decisions," pp. 389-398. Nicholson's is the more advanced text. My treatment generalizes his discussion. Kreps's _ACourseinMicroeconomicTheory, 1990, is excellent and more advanced.

HOW IT WORKS

There are two key passages from the code. First this:

; 4. All of the turtles observe the winning bid (daWinningBid)
; and the resulting quantity demanded (daQuantityDemanded).
; All of the turtles record the profit they would have had (or did have
; in the case of the winner) as either upProfits or downProfits, profits they
; got or could have gotten by bidding high or low.  More carefully put,
; each firm observes the winning bid and resulting demand, then calculates
; the reward/profit it would have had had it won with that bid. This reward
; is recorded in the list of upRewards or downRewards depending on whether
; daWinningBid is > or <= currentPrice. Now all this applies only to turtles
; of breed pAndA.
ask turtles [observe-and-record(daWinningBid)(daQuantityDemanded)(daWinner)]

and this:

to Observe-And-Record [price quantity daWinner]
  if (is-pAndA? self) [
    let reward price * quantity - cost * quantity
    ifelse (price > currentPrice)
      [set upRewards lput reward upRewards]
      [set downRewards lput reward downRewards]
    ifelse (priceBid > currentPrice)
      [ifelse (daWinner = self)
       [set ownUpRewards lput reward ownUpRewards]
       [set ownUpRewards lput 0 ownUpRewards]
       ]
      [ifelse (daWinner = self)
       [set ownDownRewards lput reward ownDownRewards]
       [set ownDownRewards lput 0 ownDownRewards]
       ]
   ] ; end of if is-pAndA?
end ; of observe-and-record

Second, is this:

to Postpare-Episode
  if (is-pAndA? self) [
    let meanUp 0
    let meanDown 0
    if (episodeCount >= epochLength) ; then update and reset
      [if (updateType = "Market Returns") [
       ifelse (upRewards = [])
         [set meanUp 0]
         [set meanUp mean upRewards]
       ifelse (downRewards = [])
         [set meanDown 0]
         [set meanDown mean downRewards]
       ifelse (meanUp > meanDown)
         [set currentPrice currentPrice + epsilon]
         [set currentPrice currentPrice - epsilon]
       ] ; end of if (updateType = "Market Returns")
       if (updateType = "Own Returns") [
       ifelse (ownUpRewards = [])
         [set meanUp 0]
         [set meanUp mean ownUpRewards]
       ifelse (ownDownRewards = [])
         [set meanDown 0]
         [set meanDown mean ownDownRewards]
       ifelse (meanUp > meanDown)
         [set currentPrice currentPrice + epsilon]
         [set currentPrice max (list delta (currentPrice - epsilon))]
       ] ; end of if (updateType = "Own Returns")
       set upRewards []
       set downRewards []
       set ownUpRewards []
       set ownDownRewards []
       set episodeCount 0
      ] ; of if episodeCount = epochLength
   ] ; end of if is-pAndA?
end ; of postpare-episode

Something to add would be an analog of the cautious policy in oligopolyBidQuantity.nlogo. Here, the firm needs to protect itself from others continually giving low bids. So this needs to be added.

The runs, and the players' learning regimes, are organized into epochs, which consist of a number of episodes or rounds of play. Each agent keeps its own epochLength. When an epoch begins, a probe-and-adjust player has a currentPrice which stays constant throughout the epoch.

After each episode (round) of play, the Postpare-Episode procedure is called for each agent. For a given agent, its epoch continues until its episodeCount reaches the agent's epochLength. If the agent's epoch is in fact over, the code in Postpare-Episode comes into play for updating the agent's currentPrice and resetting the epoch accumulators.

THINGS TO NOTICE

With two firms (agents), i.e. duopoly and the standard setting (see THINGS TO TRY) and both agents using the policy of "Market Returns", the price converges to the monopoly price of the lower cost agent.

How robust is this result? What does it take to change it?

What does this suggest about business stragey?

THINGS TO TRY

Here's a nice standard setting: kFirm0=10, kFirm1=5, epochLengthFirm0 = epochLengthFirm1 = 30. initialPriceFirm0 = 193, initialPriceFirm1 = 220. dSlope=0.5, qIBase=200. variableStarts=On. variableFactor=0.10. Try this with numPandAFirms = 1, 2, 3, 4, 5, 6, 8, 10. What happens? Try varying epoch lengths. What happens? Be sure to mix up "Market Returns" and "Own Returns".

EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

Created 2007-03-25 from oligopolyProbeAndAdjust.nlogo.

CREDITS AND REFERENCES

This model was created and written by Steven O. Kimbrough: kimbrough at wharton.upenn.edu and http://opim.wharton.upenn.edu/~sok/. The model is freely downloadable at: http://opim.wharton.upenn.edu/~sok/AGEbook/nlogo/OligopolyBidPrice.nlogo

Please give me credit if you use this model or program.

To refer to this model in academic publications, please use: Kimbrough, Steven O. (2011). Oligopoly Bid Price model. http://opim.wharton.upenn.edu/~sok/AGEbook/nlogo/OligopolyBidPrice.nlogo University of Pennsylvania, Philadelphia, PA 19004, USA. In other publications, please use: Copyright 2011 Steven O. Kimbrough. All rights reserved.

Version information: $Id: OligopolyBidPrice.nlogo 4440 2014-11-12 04:53:59Z sok $

Comments and Questions

Error while running the model (Question)

When I try to run the code in NetLogo Web, it gives me error saying 'Nothing named SETUP has been defined', if I use Setup button and similarly for 'Go' button. If I try the code in NetLogo software then it gives me error saying 'Nothing named daRandomSeed has been defined'. Can someone please explain if I am doing something wrong?

Posted almost 6 years ago

Not sure why

Will look into this. I suspect it's because it's in 5.3 and not compatible with 6.+ . Give me a few days.

Posted almost 6 years ago

Converted it to 6.0.4

Sorry this took so long. I converted the model to NetLogo 6.0.4 and it seems to work fine now. Be sure you run it in NetLogo 6 or later.

Posted almost 6 years ago

Click to Run Model

globals [pstar current-price-firm-1 priceIntercept m-price m-price-at0cost m-quantity m-quantity-at0cost
         m-price-firm0 m-price-firm1
         epochOver
         up-data down-data total-revenue-firm-1 probe-count history quantityIntercept
         up-prices down-prices monop-prices m-up-prices m-dn-prices m-up-revs m-dn-revs
         up-as down-as current-price-firm-2 total-revenue-firm-2
         up-revs-firm-2 down-revs-firm-2 win-count-firm-1 win-count-firm-2
         firm-1-bid firm-2-bid
         episodeAbsoluteCount avgWinningBid runningAverageBidList runningAverageBid
         totalUnitProductionCost
         version
         episodeBids ; a list to hold all price bids in this episode
         ]

breed [pAndAers pAndA]     ; Probe-and-Adjust

turtles-own [priceBid totalReward bidsWon unitProductionCost]
pAndAers-own [epsilon delta cost epochLength episodeCount
              currentPrice upRewards downRewards updateType
              ownUpRewards ownDownRewards runningAverageReward
              myEpisodeReward ; what the pAndAer gets in the current episode
              myPricesBid industryPricesBid ; these are lists of prices bid during an epoch
              patience
              ]

;;;;;;;;;;;;;;;;;;;;;;;;;
;; ShowVersion  ;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;

to ShowVersion
  set version "$Id: OligopolyBidPrice.nlogo 4440 2014-11-12 04:53:59Z sok $"
end 

;;;;;;;;;;;;;;;;;;;;;;;;;
;; setup  ;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;

to Setup
;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  ;__clear-all-and-reset-ticks
  clear-all
set version "$Id: OligopolyBidPrice.nlogo 4440 2014-11-12 04:53:59Z sok $"
if (daRandomSeed != "system clock")
  [random-seed daRandomSeed]
set episodeAbsoluteCount 0
set runningAverageBidList []
set  quantityIntercept qIBase
;set current-price-firm-1 initialPriceFirm0
;set current-price-firm-2 initialPriceFirm1
; set pstar intercept / (2 * slope)
; show random-float 2 * delta
set priceIntercept quantityIntercept / dSlope ; the price when the quantity is 0
; This is the monopolist's price when the monopolist has 0 costs.
; Otherwise, it is m-price = (quantityIntercept + k*dSlope)/(2*dSlope)
set m-price-at0cost quantityIntercept / (2 * dSlope)
; This is the monopolist's quantity given m-price as the monopolist's price
set m-quantity-at0cost (quantityIntercept - (dSlope * m-price-at0cost))
clear-all-plots
; This plots the demand curve, and the monopoly price and
; quantity for that demand curve, assuming 0 costs for the
; monopolist.
plot-quantity-price ; note that this is hidden, so the user doesn't actually see it, by default

create-pAndAers numPandAFirms
ask turtles [set totalReward 0
             set bidsWon 0]
ask pAndAers [setxy -4 who
     set upRewards []
     set downRewards []
     set ownUpRewards []
     set ownDownRewards [] ]
; ok, from the Information tab:
;|numPandAFirms
;If set to 1, we have the monopoly case and the firm uses the Firm0 parameter values.
;If set to 2, we have the duopoly case. Firm 0 uses the Firm0 parameter values and
;Firm 1 uses the Firm1 values. If set to 3 or more, Firm 0 uses the Firm0
;parameter values and all other firms use the Firm1 parameter values.
;(Later I can have a randomized option for parameter values.)

; First, then, I'll set ALL firms with the Firm1 parameter values.
; Then I'll set Firm 0 with the Firm0 values.
ask pAndAers
    [set epsilon epsilonFirm1
     set delta deltaFirm1
     set currentPrice initialPriceFirm1
     set cost kFirm1
     set epochLength epochLengthFirm1
     set episodeCount 0
     set unitProductionCost kFirm1
     set updateType updateTypeFirm1
     set myEpisodeReward 0
     set myPricesBid []
     set industryPricesBid []
     set patience patienceFirm1
    ]
  ; Now do firm 0
  ;set [epsilon] of pAndA 0 epsilonFirm0
  ask pAndA 0 [set epsilon epsilonFirm0]
  ;set [delta] of pAndA 0 deltaFirm0
  ask pAndA 0 [set delta deltaFirm0]
  ;set [currentPrice] of pAndA 0 initialPriceFirm0
  ask pAndA 0 [set currentPrice initialPriceFirm0]
  ;set [cost] of pAndA 0 kFirm0
  ask pAndA 0 [set cost kFirm0]
  ;set [epochLength] of pAndA 0 epochLengthFirm0
  ask pAndA 0 [set epochLength epochLengthFirm0]
  ;set [episodeCount] of pAndA 0 0
  ask pAndA 0 [set episodeCount 0]
  ;set [unitProductionCost] of pAndA 0 kFirm0
  ask pAndA 0 [set unitProductionCost kFirm0]
  ;set [updateType] of pAndA 0 updateTypeFirm0
  ask pAndA 0 [set updateType updateTypeFirm0]
  ;set [patience] of pAndA 0 patienceFirm0
  ask pAndA 0 [set patience  patienceFirm0]

  if (variableStarts = True)
   [ask pAndAers
     [set currentPrice (random-float 2 * (variableFactor * currentPrice)) + (currentPrice - (variableFactor * currentPrice))
      print (word "Starting currentPrice for agent "  self  " is "  currentPrice  ".")
   ]
   ] ; end of if (variableStarts = True)

  set m-price-firm0 (quantityIntercept + [unitProductionCost] of pAndA 0 * dSlope) / (2 * dSlope)
  if (numPandAFirms > 1)
    [set m-price-firm1 (quantityIntercept + [unitProductionCost] of pAndA 1 * dSlope) / (2 * dSlope)]
  ;;;;;;;;;;
  if (reporting)
    [write "episode"
     write "ID"
     write "breed"
     write "currentPrice"
     write "bidsWon"
     write "totalReward"
     print " "]
  if (reporting)
     [turtle-report]
  ; Now get the total unit production cost
  set totalUnitProductionCost 0
  ask turtles
    [set totalUnitProductionCost (totalUnitProductionCost + unitProductionCost)]
  ; m-price = (quantityIntercept + k*dSlope)/(2*dSlope)
  set m-price (quantityIntercept + totalUnitProductionCost * dSlope) / (2 * dSlope)
  reset-ticks
end  ; of setup

;;;;;;;;;;;;;;;;;;;;
;; go ;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;

to Go
  tick
  ;if ticks >= numEpisodesToRun [stop]
; See the documentation in the Information tab.
set episodeAbsoluteCount episodeAbsoluteCount + 1
set episodeBids [] ; a list to hold all price bids in this episode
; 0. Perturb the demand curve if we're doing random-walk-as
if (random-walk-as)
   [set quantityIntercept (random-float 2 * aDelta) - aDelta + quantityIntercept
   set priceIntercept quantityIntercept / dSlope
   ; This is the monopolist's price when the monopolist has 0 costs.
   ; Otherwise, it is m-price = (quantityIntercept + k*dSlope)/(2*dSlope)
   set m-price-at0cost quantityIntercept / (2 * dSlope)
   ; This is the monopolist's quantity given m-price as the monopolist's price
   set m-quantity-at0cost (quantityIntercept - (dSlope * m-price))
   set m-price (quantityIntercept + totalUnitProductionCost * dSlope) / (2 * dSlope)
   set m-price-firm0 (quantityIntercept + [unitProductionCost] of pAndA 0 * dSlope) / (2 * dSlope)
   if (numPandAFirms > 1)
     [set m-price-firm1 (quantityIntercept + [unitProductionCost] of pAndA 1 * dSlope) / (2 * dSlope)]
   ] ; if of if (random-as)

; 1. All of the turtles are asked to determine a bid price. Each records his own, in bidPrice.
ask turtles [
  Set-PriceBid
]
;print "in Go... episodeBids = " + episodeBids
;ask turtles [set industryPricesBid episode
; 2. We figure out the lowest bid and take it.
; daWinner is the winning turtle, with the or a lowest bid.
let daWinner min-one-of turtles [priceBid]
let daWinnersID [who] of daWinner
;print daWinnersID

let daWinningBid [priceBid] of daWinner
;write " " + daWinner + " " + daWinningBid
;print " "
let daQuantityDemanded Quantity-Demanded(daWinningBid)
;print daQuantityDemanded
let daCost [cost] of daWinner
;print who-of daWinner
; 3. The turtle with the lowest bid gets a reward, gets all the business.
let tempReward [totalReward] of daWinner
;set [totalReward] of daWinner tempReward + (daWinningBid * daQuantityDemanded - daCost * daQuantityDemanded)
ask daWinner [set totalReward (tempReward + (daWinningBid * daQuantityDemanded - daCost * daQuantityDemanded))]
;set [bidsWon] of daWinner [bidsWon] of daWinner + 1
ask daWinner [set bidsWon (bidsWon + 1)]

; 4. All of the turtles observe the winning bid (daWinningBid)
; and the resulting quantity demanded (daQuantityDemanded).
; All of the turtles record the profit they would have had (or did have
; in the case of the winner) as either upProfits or downProfits, profits they
; got or could have gotten by bidding high or low.  More carefully put,
; each firm observes the winning bid and resulting demand, then calculates
; the reward/profit it would have had had it won with that bid. This reward
; is recorded in the list of upRewards or downRewards depending on whether
; daWinningBid is > or <= currentPrice. Now all this applies only to turtles
; of breed pAndA.
ask turtles [observe-and-record(daWinningBid)(daQuantityDemanded)(daWinner)]
; 5. Plot monopoly price and winning bid price.
plot-prices(m-price)(daWinningBid)
; This completes the episode. We ask the turtles to do any
; appropriate housekeeping.
ask turtles [postpare-episode]

ifelse (episodeAbsoluteCount > 1)
  [set avgWinningBid (avgWinningBid * (episodeAbsoluteCount - 1) + daWinningBid) / episodeAbsoluteCount ]
  [set avgWinningBid daWinningBid]

set runningAverageBidList lput daWinningBid runningAverageBidList
if (length runningAverageBidList > runningAvgLength)
  [set runningAverageBidList but-first runningAverageBidList]
set runningAverageBid mean runningAverageBidList

if (episodeAbsoluteCount mod reportEveryNEpisodes = 0 and reporting)
  [turtle-report]
end  ; of go

to Set-PriceBid
 if (is-pAndA? self) [
  set priceBid max (list cost ((random-float 2 * delta) - delta + currentPrice))
  set episodeBids lput priceBid episodeBids
  set myPricesBid lput priceBid myPricesBid
  set episodeCount episodeCount + 1
  ;write who-of self + " " + priceBid
 ]
end  ; of set-priceBid

to Observe-And-Record [price quantity daWinner]
  if (is-pAndA? self) [
    let reward price * quantity - cost * quantity
    ifelse (price > currentPrice)
      [set upRewards lput reward upRewards]
      [set downRewards lput reward downRewards]
    ifelse (priceBid > currentPrice)
      [ifelse (daWinner = self)
       [set ownUpRewards lput reward ownUpRewards]
       [set ownUpRewards lput 0 ownUpRewards]
       ]
      [ifelse (daWinner = self)
       [set ownDownRewards lput reward ownDownRewards]
       [set ownDownRewards lput 0 ownDownRewards]
       ]
    ;print "In observe-and-record, episodeBids=" + episodeBids
    foreach episodeBids [ ?1 -> set industryPricesBid lput ?1 industryPricesBid ]
   ] ; end of if is-pAndA?
end  ; of observe-and-record

to plot-prices [monopolyPrice winningBid]
set-current-plot "Current Bid Price"
set-current-plot-pen "Winning Bid"
plot winningBid
; I no longer think this makes any sense, so I'm deleting it.
;set-current-plot-pen "Monopoly Price"
;plot monopolyPrice
set-current-plot-pen "Monopoly Price at 0 Costs"
plot m-price-at0cost
set-current-plot-pen "Monopoly Price, Firm 0"
plot m-price-firm0
set-current-plot-pen "Monopoly Price, Firm(s) 1"
plot m-price-firm1
set-current-plot "Current Base Prices"
let numToPlot min (list 10 numPandAFirms)
foreach n-values numToPlot [ ?1 -> ?1 ]
[ ?1 -> set-current-plot-pen (word "Agent"  ?1)
plot [currentPrice] of pAndA ?1
 ]
;if (numPandAFirms > 1)
 ; [set-current-plot-pen "Agent1"
 ;  plot currentPrice-of pAndA 1]
end  ; of plot-prices

to Postpare-Episode
  if (is-pAndA? self) [
    ;if (who-of self = 0)
    ;[print "about to postpare turtle 0. updateType is " + updateType-of self]
    ;[print "My episode count is " + episodeCount]
    let meanUp 0
    let meanDown 0
    if (episodeCount >= epochLength) ; then update and reset
      [
      ; first, collect statistics
      set runningAverageReward (sum ownUpRewards + sum ownDownRewards) / epochLength
      if (updateType = "Market Returns") [
       ifelse (upRewards = [])
         [set meanUp 0]
         [set meanUp mean upRewards]
       ifelse (downRewards = [])
         [set meanDown 0]
         [set meanDown mean downRewards]
       ifelse (meanUp > meanDown)
         [set currentPrice currentPrice + epsilon]
         [set currentPrice max (list (cost + delta) (currentPrice - epsilon))]
       ] ; end of if (updateType = "Market Returns")
       ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       if (updateType = "Own Returns") [
       ifelse (ownUpRewards = [])
         [set meanUp 0]
         [set meanUp mean ownUpRewards]
       ifelse (ownDownRewards = [])
         [set meanDown 0]
         [set meanDown mean ownDownRewards]
       ifelse (meanUp > meanDown)
         [set currentPrice currentPrice + epsilon]
         ; I think the delta below is a bug and should be cost 2007-5-1
         ;[set currentPrice max (list delta (currentPrice - epsilon))]
         [set currentPrice max (list (cost + delta) (currentPrice - epsilon))]
       ;write self + " " + ownUpRewards + " " + ownDownRewards + " " + meanUp + " " + meanDown
       ;print " "
       ] ; end of if (updateType = "Own Returns")
       ;;;;;;;;;;;;;;;;;;;;;;;;  Dropping this: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       if (updateType = "Market Returns and Own Returns") [
       ; See if you've won ANY bids. If not, reduce your price, but don't go lower than your costs,
       ; else follow the Market Returns rule
       ;if (who-of self = 0)
       ;[
       ;print "about to postpare turtle 0. updateType is " + updateType-of self
       ;print ownUpRewards + " " + ownDownRewards
       ;]
       ifelse ((ownUpRewards = [] and ownDownRewards = []) or (sum ownUpRewards = 0 and sum ownDownRewards = 0))
         [set currentPrice max (list (cost + delta) (currentPrice - epsilon))
          ;print "My new currentPrice is " + currentPrice + "My episodeCount is " + episodeCount
          ]
         [ ; now the else
       ifelse (upRewards = [])
         [set meanUp 0]
         [set meanUp mean upRewards]
       ifelse (downRewards = [])
         [set meanDown 0]
         [set meanDown mean downRewards]
       ifelse (meanUp > meanDown)
         [set currentPrice currentPrice + epsilon]
         [set currentPrice max (list (cost + delta) (currentPrice - epsilon))]
         ] ; end of the else
       ] ; end of if (updateType = "Market Returns and Own Returns")
       ;;;;;;;;;;;;;;;;;; <== dropped the above ;;;;;;;;;;;;;;;;;;;;;;
       if (updateType = "Market Returns s.t. Own Returns") [
         ; if my price bids have been higher than the industry average by delta,
         ; set my currentPrice to the mean of the industry's prices bid in the
         ; epoch; epsilon is too impatient
         ifelse ((mean myPricesBid) - (delta * patience) > (mean industryPricesBid))
           [;print "Hello!!!!!"
            set currentPrice (mean industryPricesBid) - delta] ; aggressively reduce price
           ; else behave as a Market Returns guy
           [ifelse (upRewards = [])
             [set meanUp 0]
             [set meanUp mean upRewards]
           ifelse (downRewards = [])
             [set meanDown 0]
             [set meanDown mean downRewards]
            ifelse (meanUp > meanDown)
             [set currentPrice currentPrice + epsilon]
             [set currentPrice max (list (cost + delta) (currentPrice - epsilon))]
       ] ;

       ] ; end of if (updateType = "Market Returns s.t. Own Returns")
       set upRewards []
       set downRewards []
       set ownUpRewards []
       set ownDownRewards []
       set myPricesBid []
       set industryPricesBid []
       set episodeCount 0
      ] ; of if episodeCount = epochLength
   ] ; end of if is-pAndA?
end  ; of postpare-episode

to turtle-report
ask turtles [
write episodeAbsoluteCount
write who
write [breed] of self
write currentPrice
write bidsWon
write totalReward
print " "
]
end  ; of turtle-report

;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; plot-quantity-price  ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;

to plot-quantity-price
set-current-plot "Demand and Monopoly Quantity & Price at 0 Costs"
clear-plot
set-plot-y-range 0 priceIntercept
set-plot-x-range 0 quantityIntercept
set-current-plot-pen "demand-curve"
plot-pen-up
plotxy 0 priceIntercept
plot-pen-down
plotxy quantityIntercept 0
set-current-plot-pen "monopoly-quantity"
plot-pen-up
plotxy m-quantity-at0cost 0
plot-pen-down
plotxy m-quantity-at0cost m-price-at0cost
set-current-plot-pen "monopoly-price"
plot-pen-up
plotxy 0 m-price-at0cost
plot-pen-down
plotxy m-quantity-at0cost m-price-at0cost
end 

to-report daRevenue [daPrice]
  report daPrice * (quantityIntercept - (dSlope * daPrice))
end 

to plot-price [daPrice daPrice-firm-2 mono-price]
set-current-plot "Current Bid Price"
set-current-plot-pen "Bid Price Firm 1"
plot daPrice ; daRevenue(daPrice)
set-current-plot-pen "Bid Price Firm 2"
plot daPrice-firm-2
set-current-plot-pen "Monopoly Price"
plot mono-price ; daRevenue(mono-price)
end 

to debug
let probe 0


set probe (random-float 2 * deltaFirm0) - deltaFirm0 + current-price-firm-1
show (word "a = "  quantityIntercept)
show (word "price intercept = "  priceIntercept)
show (word "slope = " dSlope)
show (word "monopoly price = "  m-price)
show (word "monopoly demand = "  (quantityIntercept - dSlope * m-price))
show (word "monopoly revenue = " daRevenue(m-price))
show (word "current-price = " current-price-firm-1)
show (word "probe = " probe)
show (word "probe revenue = " daRevenue(probe))
end 




;; New for oligopoly, price setting

to-report Quantity-Demanded [daPrice]
  ; if the price is too high, demand is zero
  let bob  quantityIntercept - (dSlope * daPrice)
  let carol (list 0 bob)
  ;print max carol
  report max carol
end  ; of Quantity-Demanded

There are 2 versions of this model.

Uploaded by When Description Download
Steven Kimbrough almost 6 years ago Converted to NetLogo 6.0.4 Download this version
Steven Kimbrough over 8 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.