def run_evolution_simulation(n_trials,end_time, traders_spec, order_sched, knock_out,rnd): wipe_trader_files(evolution) tdump=open('output/avg_balance.csv','w') trader_types = [] counts = [] for (trader,count) in traders_spec['buyers']: trader_types.append(trader) counts.append(count) evolution_output = [counts] trial = 1 while (trial<(n_trials+1)): trial_id = 'trial%04d' % trial traders = market_session(trial_id, start_time, end_time, traders_spec, order_sched, tdump, dump_all,store_traders,store_profits,store_lob_orders,store_trader_orders) best_balance = -float('inf') worst_balance = float('inf') for trader in traders.values(): if trader.balance > best_balance: best_trader = trader.tid best_balance = trader.balance elif trader.balance < worst_balance: worst_trader = trader.tid worst_balance = trader.balance i = 0 counts = [] number_still_in = 0 for (trader,count) in traders_spec['buyers']: if not knock_out and trader == traders[best_trader].ttype: count += 1 if trader == traders[worst_trader].ttype: count -= 1 if count > 0: number_still_in += 1 traders_spec['buyers'][i] = (trader,count) counts.append(count) i += 1 evolution_output.append(counts) if number_still_in == 1: break traders_spec['sellers'] = traders_spec['buyers'] # traders_spec = {'sellers':sellers_spec, 'buyers':buyers_spec} # tdump.flush() print str(trial) + " done!" trial = trial + 1 simulation_utils.store_simulation_data(trader_types,evolution_output,rnd) tdump.close()
def run_standard_simulation(n_trials,end_time, traders_spec, order_sched,m): wipe_trader_files(evolution) tdump=open('output/avg_balance'+str(m)+'.csv','w') #tdump.write(end_time, order_sched['sup'][0]['stepmode'], order_sched['timemode']) trial = 1 while (trial<(n_trials+1)): trial_id = 'trial%04d' % trial market_session(trial_id, start_time, end_time, traders_spec, order_sched, tdump, dump_all,store_traders,store_profits,store_lob_orders,store_trader_orders) tdump.flush() trial = trial + 1 print trial_id + " done!" tdump.close()