当前位置: 首页>>代码示例>>Python>>正文


Python Inventory.query方法代码示例

本文整理汇总了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
开发者ID:johny5w,项目名称:market_sim,代码行数:70,代码来源:agent.py


注:本文中的inventory.Inventory.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。