def determine_cascade_profile(zip_suffix, number_of_games, numberWE, numberWF, supply, demand, reserve=None): """ Given an initial number of games, number_of_games, cascades back to the first time the profile in file_location is found. This function iteratively halfs number_of_games until a profile is found OR we get below 200, in which case an error is thrown. """ while (number_of_games >= 100): zip_location = setup.get_zip_location(zip_suffix, number_of_games) zf = zipfile.ZipFile(zip_location) file_location = setup.get_agent_dir_location( number_of_games, supply, demand) + setup.get_file_location( numberWE, numberWF, reserve) if file_location in zf.namelist(): print( '\tFound! =', number_of_games, ', (WE, WF) = (', numberWE, ',', numberWF, ')', (' reserve = ' + str(reserve) if reserve is not None else '')) print('\t', zip_location) return number_of_games else: print('\tNot found for number_of_games = ', number_of_games, ', trying half') number_of_games = int(number_of_games / 2) raise ValueError( "******************* Could not find data for file_location ", file_location, ", in zip ", zip_location)
def plot_all_soft_expected_agents_pure_nash(number_of_games): """ Wrapper to plot all expected number of strategies. """ for (demand, supply) in setup.get_grid_demand_impressions(): print('Expected Pure Nash for (demand, supply) = (', demand, ',', supply, ')') dir_location = setup.get_agent_dir_location(number_of_games, supply, demand) plot_soft_expected_agents_pure_nash(number_of_games, dir_location, demand, supply)
def plot_all_proportion_pure_nash(number_of_games): """ Save all the best response graphs to an image and the image of the proportion of pure nash """ for (demand, supply) in setup.get_grid_demand_impressions(): print('Proportion Graphs Pure Nash for (demand, supply) = (', demand, ',', supply, ')') dir_location = setup.get_agent_dir_location(number_of_games, supply, demand) dict_of_pure_nash = mean_best_response_graphs.get_dict_of_pure_nash( number_of_games, demand, supply, dir_location) plot_proportion_pure_nash(number_of_games, demand, supply, dict_of_pure_nash)
def produce_agents_plots(number_of_games, demand_factor, impressions): """ Plots varying the composition of the game, i.e., type and number of agents. """ image_prefix = 'demand-factor-' + demand_factor.replace( '.', '_') + '-' + impressions + 'impressions-' agent_dir_location = setup.get_agent_dir_location(number_of_games, impressions, demand_factor) print('\t(games, demand, supply) = (', number_of_games, ',', demand_factor, ',', impressions, ')') for x in setup.get_two_agents_combinations(): for y in [True, False]: print('\t\tAgents Graph: ' + str(x) + (', Fix Agent ' + str(x[0]) if y else ', Fix Agent ' + str(x[1]))) plot_agent_group(number_of_games, agent_dir_location, image_prefix, demand_factor, impressions, x[0], x[1], y)
def get_profile_revenue(zip_suffix, number_of_games, numberWE, numberWF, supply, demand, reserve=None): """ Given the description of a profile, returns the mean revenue of the market maker. """ number_of_games = deviation_analysis.determine_cascade_profile( zip_suffix, number_of_games, numberWE, numberWF, supply, demand, reserve) zip_location = setup.get_zip_location(zip_suffix, number_of_games) file_location = setup.get_agent_dir_location( number_of_games, supply, demand) + setup.get_file_location( numberWE, numberWF, reserve) data = get_data.get_agent_data(zip_location, file_location) data = data.dropna() return get_data.mean_confidence_interval(data.wincost)
def get_specific_profile_data(zip_suffix, numberWE, numberWF, specific_number_of_games, supply, demand, reserve=None): """ Given numberWE, numberWF, specific_number_of_games, supply, demand; produces the profile data for numberWE playing numberWF specific_number_of_games times with supply and demand. """ zip_location = setup.get_zip_location(zip_suffix, specific_number_of_games) dir_location = setup.get_agent_dir_location(specific_number_of_games, supply, demand) file_location = setup.get_file_location(numberWE, numberWF, reserve) mix = get_data.get_agent_data(zip_location, dir_location + file_location) mix = mix.dropna() WEdata = mix[mix.agent.str.contains('WEAgent')] WFdata = mix[mix.agent.str.contains('WFAgent')] """print('get_specific_profile_data (1) = ', file_name) print('get_specific_profile_data (2) = ', dir_location) print('get_specific_profile_data (3) = ', reserve) print('get_specific_profile_data (4) = ', file_location)""" return ('WE' * numberWE + 'WF' * numberWF, { 'WE': { 'n': len(WEdata), 'mean': WEdata.profit.mean(), 'var': WEdata.profit.var() }, 'WF': { 'n': len(WFdata), 'mean': WFdata.profit.mean(), 'var': WFdata.profit.var() } })