本文整理汇总了Python中inventory.Inventory.query方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.query方法的具体用法?Python Inventory.query怎么用?Python Inventory.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Agent
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import query [as 别名]
#.........这里部分代码省略.........
trade_range = self.observed_trading_range[good]
if trade_range:
return{'min': min(trade_range), 'max': max(trade_range)}
return None
def update_price_model(self, market, action, good, success, unit_price=0):
public_mean_price = market.history.prices.average(good, 1) # TODO: this line sucks
belief = self.price_beliefs[good]
mean = sum(belief.values()) / 2 # Average of min and max
wobble = .05
delta_mean = mean - public_mean_price
if success:
self.observed_trading_range[good].append(unit_price)
if action == 'buy' and delta_mean > Agent.SIGNIFICANT:
belief['min'] -= delta_mean / 2 # Over paid, shift towards mean
belief['max'] -= delta_mean / 2
elif action == 'sell' and delta_mean < -Agent.SIGNIFICANT:
belief['min'] -= delta_mean / 2 # Undersold, shift towards mean
belief['max'] -= delta_mean / 2
belief['min'] += wobble * mean #increase the belief's certainty
belief['max'] -= wobble * mean
else:
belief['min'] -= delta_mean / 2 # SHIFT towards the mean
belief['max'] -= delta_mean / 2
special_case = False
stocks = self.inventory.query(good)
ideal = self.inventory.ideal_amounts[good]
if action == 'buy' and stocks < (Agent.LOW_INVENTORY * ideal):
# Very low on inventory AND can't buy
wobble *= 2 #bid more liberally
special_case = True
elif action == 'sell' and stocks > (Agent.HIGH_INVENTORY * ideal):
# Very high on inventory AND can't sell
wobble *= 2 #ask more liberally
special_case = True
#if not special_case:
# # Don't know what else to do? Check supply vs demand
# asks = bazaar.history.asks.average(good, 1)
# bids = bazaar.history.bids.average(good, 1)
#
# # Supply vs demand: 0 =balance, 1 = all supply, -1= all demand
# supply_vs_demand = (asks - bids) / (asks + bids)
#
# # too much supply, or too much demand
# if supply_vs_demand > self.SIG_IMBALANCE or supply_vs_demand < -self.SIG_IMBALANCE:
# # too much supply: lower price
# # too much demand: raise price
# new_mean = public_mean_price * (1 - supply_vs_demand)
# delta_mean = mean - new_mean
#
# belief.x -= delta_mean / 2 # shift towards anticipated new mean
# belief.y -= delta_mean / 2
belief['min'] += wobble * mean # decrease the belief's certainty
belief['max'] -= wobble * mean