コード例 #1
0
def __evaluate_simulation_results(parameters, logdata_folder, graph_folder, generation_number, plot_name = None):
	assert logdata_folder, "Please specify where the logdata is located"
	data = empty_data_matrix(1)

	#ob_round_based = np.genfromtxt(logdata_folder + 'columnLog_roundBased_orderbook(0,0).csv', names=True, dtype=int, delimiter=',', usecols=(1,2))
	#stock_round_based = np.genfromtxt(logdata_folder + 'columnLog_roundBased_stock0.csv', names=True, dtype=int, delimiter=',', usecols=(0,1))
	trades = IO.load_trade_log_data(logdata_folder)

	

	
	fas = get_fundamental_after_shock()
	within_margin = get_number_of_rounds_within_stability_margin(trades['price'], trades['round'], fas)
	#data['n_simulation_rounds_within_stability_margin'] = within_margin['total_number_of_rounds']
	#data['n_seperate_intervals_within_stability_margin'] = within_margin['n_intervals']
	if 'longest_interval_within_margin' in data_for_failed_simulation.keys():
		data['longest_interval_within_margin'] = within_margin['longest_interval']
	if 'stdev' in data_for_failed_simulation.keys():
		data['stdev'] = get_tp_std_after_entering_margin(trades['price'], trades['round'])
	if 'overshoot' in data_for_failed_simulation.keys():
		data['overshoot'] = calculate_overshoot(fas, trades['price'], trades['round'])
	if 'time_to_reach_new_fundamental' in data_for_failed_simulation.keys():
		data['time_to_reach_new_fundamental'] = get_first_round_to_reach_new_fundamental(trades['price'], trades['round'])
	if 'round_stable' in data_for_failed_simulation.keys():
		data['round_stable'] = calculate_round_stable(trades['price'], trades['round'], fas)

	if np.random.random() <= PLOT_SAVE_PROB:
		data_id = 'gen%s_%s_%s'%(generation_number, get_epoch_time(), str(abs(hash(np.random.random()))))
		print graph_folder + data_id + '.npz'
		
		IO.save_tradeprice_data(trades['round'], trades['price'], data, parameters, graph_folder + data_id + '.npz')
		plotting.make_pretty_tradeprice_plot(trades['round'], trades['price'], graph_folder + data_id + '.png')
		#plotting.make_tradeprice_plot(trades['round'], trades['price'], data, parameters, graph_folder + data_id + '.png')
	else:
		data_id = None
		
	if not KEEP_SIMULATION_DATA: IO.delete_simulation_data(logdata_folder)
	return data, data_id
コード例 #2
0
def evaluate_simulation_results(graph_folder, generation_number, parameters = {}, reps = [0], autorun = False, plot_name = None):
	#print parameters
	assert parameters, "Please specify a dictionary with par_name:par_value as key:value sets"

	data = empty_data_matrix(len(reps))
	saved_simulation_data_ids = list()

	simulation_reps_to_run = []
	random_path = str(randint(0, 2**64))
	log_folders = IO.get_logfolders(parameters, reps, random_path)

	for r in reps:
		try:
			assert IO.check_simulation_complete(log_folders[r]), "Could not calculate data because simulation in folder %s was not finished"%log_folders[r]
		except AssertionError:
			simulation_reps_to_run.append(r)

	if simulation_reps_to_run: run_simulation(parameters, simulation_reps_to_run, random_path)

	for r in reps:
		data[r], data_id = __evaluate_simulation_results(parameters, log_folders[r], graph_folder, generation_number, plot_name)
		if data_id: saved_simulation_data_ids.append(data_id)

	return data, saved_simulation_data_ids