original_docstring: 
          Update the Pop's price model for the given resource
          good (Good)             The Good which was orderd
          order_type (OrderType)  Which kind of Order this was
          is_successful (bool)    whether or not the Order was successful
          clearing_price (float)  The price per unit of the good that was ordered
                                  as defined by the Pop which ordered it
          
docstring: Update the Pop's price model for the given resource
  good (Good)             The Good which was orderd
  order_type (OrderType)  Which kind of Order this was
  is_successful (bool)    whether or not the Order was successful
  clearing_price (float)  The price per unit of the good that was ordered
  as defined by the Pop which ordered it
docstring_tokens: Update the Pop ' s price model for the given resource good ( Good ) The Good which was orderd order_type ( OrderType ) Which kind of Order this was is_successful ( bool ) whether or not the Order was successful clearing_price ( float ) The price per unit of the good that was ordered as defined by the Pop which ordered it
code: def update_price_model(self, good, order_type, is_successful, clearing_price=0):
          """
          Update the Pop's price model for the given resource
          good (Good)             The Good which was orderd
          order_type (OrderType)  Which kind of Order this was
          is_successful (bool)    whether or not the Order was successful
          clearing_price (float)  The price per unit of the good that was ordered
                                  as defined by the Pop which ordered it
          """
  
          SIGNIFICANT = 0.25 # 25% more or less is "significant"
          SIG_IMBALANCE = 0.33
          LOW_INVENTORY = 0.1 # 10% of ideal inventory = "LOW"
          HIGH_INVENTORY = 2.0 # 200% of ideal inventory = "HIGH"
          MIN_PRICE = 0.01 # lowest allowed price of a Good
  
          if is_successful:
              # add this trade to the observed trading range
              self.observed_trading_range[good].append(clearing_price)
  
          public_mean_price = self.market.mean_price(good)
          belief = self.price_belief[good]
          mean = belief.mean()
          wobble = 0.05 # the degree which the Pop should bid outside the belief
  
          # how different the public mean price is from the price belief
          delta_to_mean = mean - public_mean_price
  
          if is_successful:
              if order_type is OrderType.buy_order and delta_to_mean > SIGNIFICANT:
                  # this Pop overpaid, shift belief towards mean
                  belief.low -= delta_to_mean / 2
                  belief.high -= delta_to_mean / 2
              elif order_type is OrderType.sell_order and delta_to_mean < -SIGNIFICANT:
                  # this Pop underpaid!, shift belief towards mean
                  belief.low -= delta_to_mean / 2
                  belief.high -= delta_to_mean / 2
  
              # increase the belief's certainty
              belief.low += wobble * mean
              belief.high -= wobble * mean
  
          else:
              # shift towards mean
              belief.low -= delta_to_mean / 2
              belief.high -= delta_to_mean / 2
  
              # check for inventory special cases
              stocks = self.inventory.get_amount(good)
              ideal = self.inventory.get_ideal(good)
  
              # if we're buying and inventory is too low
              # meaning we're desperate to buy
              if order_type is OrderType.buy_order and stocks < LOW_INVENTORY * ideal:
                  wobble *= 2
  
              # if we're selling and inventory is too high
              # meaning we're desperate to sell
              elif order_type is OrderType.sell_order and stocks > HIGH_INVENTORY * ideal:
                  wobble *= 2
              # all other cases
              else:
                  sells = self.market.history.sell_orders.average(good, 1)
                  buys = self.market.history.buy_orders.average(good, 1)
  
                  # TODO: figure out why this is sometimes 0
                  if sells + buys > 0:
  
                      supply_vs_demand = (sells - buys) / (sells + buys)
  
                      if supply_vs_demand > SIG_IMBALANCE or supply_vs_demand < -SIG_IMBALANCE:
                          # too much supply? lower bid lower to sell faster
                          # too much demand? raise price to buy faster
  
                          new_mean = public_mean_price * (1 - supply_vs_demand)
                          delta_to_mean = mean - new_mean
  
                          # shift the price belief to the new price mean
                          belief.low -= delta_to_mean / 2
                          belief.high -= delta_to_mean / 2
  
  
              # decrease belief's certainty since we've just changed it (we could be wrong)
              belief.low -= wobble * mean
              belief.high += wobble * mean
  
          # make sure the price belief doesn't decrease below the minimum
          if belief.low < MIN_PRICE:
              belief.low = MIN_PRICE
          elif belief.high < MIN_PRICE:
              belief.high = MIN_PRICE
code_tokens: def update_price_model ( self , good , order_type , is_successful , clearing_price = 0 ) : SIGNIFICANT = 0.25 SIG_IMBALANCE = 0.33 LOW_INVENTORY = 0.1 HIGH_INVENTORY = 2.0 MIN_PRICE = 0.01 if is_successful : self . observed_trading_range [ good ] . append ( clearing_price ) public_mean_price = self . market . mean_price ( good ) belief = self . price_belief [ good ] mean = belief . mean ( ) wobble = 0.05 delta_to_mean = mean - public_mean_price if is_successful : if order_type is OrderType . buy_order and delta_to_mean > SIGNIFICANT : belief . low -= delta_to_mean / 2 belief . high -= delta_to_mean / 2 elif order_type is OrderType . sell_order and delta_to_mean < - SIGNIFICANT : belief . low -= delta_to_mean / 2 belief . high -= delta_to_mean / 2 belief . low += wobble * mean belief . high -= wobble * mean else : belief . low -= delta_to_mean / 2 belief . high -= delta_to_mean / 2 stocks = self . inventory . get_amount ( good ) ideal = self . inventory . get_ideal ( good ) if order_type is OrderType . buy_order and stocks < LOW_INVENTORY * ideal : wobble *= 2 elif order_type is OrderType . sell_order and stocks > HIGH_INVENTORY * ideal : wobble *= 2 else : sells = self . market . history . sell_orders . average ( good , 1 ) buys = self . market . history . buy_orders . average ( good , 1 ) if sells + buys > 0 : supply_vs_demand = ( sells - buys ) / ( sells + buys ) if supply_vs_demand > SIG_IMBALANCE or supply_vs_demand < - SIG_IMBALANCE : new_mean = public_mean_price * ( 1 - supply_vs_demand ) delta_to_mean = mean - new_mean belief . low -= delta_to_mean / 2 belief . high -= delta_to_mean / 2 belief . low -= wobble * mean belief . high += wobble * mean if belief . low < MIN_PRICE : belief . low = MIN_PRICE elif belief . high < MIN_PRICE : belief . high = MIN_PRICE
short_docstring: Update the Pop's price model for the given resource
  good (Good)             The Good which was orderd
  order_type (OrderType)  Which kind of Order this was
  is_successful (bool)    whether or not the Order was successful
  clearing_price (float)  The price per unit of the good that was ordered
  as defined by the Pop which ordered it
short_docstring_tokens: Update the Pop ' s price model for the given resource good ( Good ) The Good which was orderd order_type ( OrderType ) Which kind of Order this was is_successful ( bool ) whether or not the Order was successful clearing_price ( float ) The price per unit of the good that was ordered as defined by the Pop which ordered it
comment: """
          Update the Pop's price model for the given resource
          good (Good)             The Good which was orderd
          order_type (OrderType)  Which kind of Order this was
          is_successful (bool)    whether or not the Order was successful
          clearing_price (float)  The price per unit of the good that was ordered
                                  as defined by the Pop which ordered it
          """$SEP$# 25% more or less is "significant"$SEP$# 10% of ideal inventory = "LOW"$SEP$# 200% of ideal inventory = "HIGH"$SEP$# lowest allowed price of a Good$SEP$# add this trade to the observed trading range$SEP$# the degree which the Pop should bid outside the belief$SEP$# how different the public mean price is from the price belief$SEP$# this Pop overpaid, shift belief towards mean$SEP$# this Pop underpaid!, shift belief towards mean$SEP$# increase the belief's certainty$SEP$# shift towards mean$SEP$# check for inventory special cases$SEP$# if we're buying and inventory is too low$SEP$# meaning we're desperate to buy$SEP$# if we're selling and inventory is too high$SEP$# meaning we're desperate to sell$SEP$# all other cases$SEP$# TODO: figure out why this is sometimes 0$SEP$# too much supply? lower bid lower to sell faster$SEP$# too much demand? raise price to buy faster$SEP$# shift the price belief to the new price mean$SEP$# decrease belief's certainty since we've just changed it (we could be wrong)$SEP$# make sure the price belief doesn't decrease below the minimum