def set_initial_holdings(self, user_holdings): """ Initialize each bot with the same base endowment + additional endowment in U[0, 5]. All bots have the same cash holding. :param user_holdings: :return: """ try: markets = [] for item in self.market_items: markets.append(Market.get_by_item(item)) for email, holdings in user_holdings.items(): for market in markets: if email not in self.endow: holdings.assets[market].units_initial = 0 else: holdings.assets[market].units_initial = int( self.endow[email][market.item][0]) holdings.cash_initial = self.base_cash except Exception as e: self.error(e) try: self.update_holdings(user_holdings, self.initial_holdings_updated_callback) except Exception as e: self.error(e)
def set_initial_holdings(self, user_holdings): """ Initialize each bot with the same base endowment + additional endowment in U[0, 5]. All bots have the same cash holding. :param user_holdings: :return: """ self.inform( "I have received old holdings. I will now calculate the initial holdings." ) markets = [] for item in self.market_items: markets.append(Market.get_by_item(item)) # Calculate the base endowment for the next round round_endow = random.randint(0, self.upper_endow) self.inform("Base endowment for round 1 is: {}".format(round_endow)) for email, holdings in user_holdings.items(): for market in markets: holdings.assets[ market].units_initial = round_endow + random.randint( 0, self.upper_endow) holdings.cash_initial = self.base_cash try: self.update_holdings(user_holdings, self.initial_holdings_updated_callback) except Exception as e: self.error(e)
def set_initial_holdings(self, user_holdings): """ Initialize each bot with the same base endowment + additional endowment in U[0, 5]. All bots have the same cash holding. :param user_holdings: :return: """ self.inform("Starting run " + str(self.label) + " of simulations.") try: market = Market.get_by_item(MARKET_1) for email, holdings in user_holdings.items(): print(email) if email not in self.endow: holdings.assets[market].units_initial = 0 else: holdings.assets[market].units_initial = int( self.endow[email][0]) holdings.cash_initial = self.base_cash except Exception as e: self.inform(e) try: self.update_holdings(user_holdings, self.initial_holdings_updated_callback) except Exception as e: self.inform(e)