Exemplo n.º 1
0
def test_basic_experiment():
	
	pa=os.getcwd()
	config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	config_path=os.path.join(pa,config_name)
	
	environ_dic=yamlLoad(config_path)
	#environ_dic['trade_file']=os.path.join(pa,'UCLSE\\test\\output\\avg_balance.csv')
	sess=Market_session(**environ_dic)
	sess.simulate(sess.trade_stats_df3)
Exemplo n.º 2
0
def test_forwards_multi_leg():
	pa=os.getcwd()
	config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	config_path=os.path.join(pa,config_name)
	
	environ_dic=yamlLoad(config_path)
	environ_dic['end_time']=50
	
	sess=Market_session(**environ_dic)
	sess1=copy.deepcopy(sess)
	#sess1.process_order=sess1.exchange.process_order3w
	try:
		side_by_side_period_by_period_difference_checker(sess,sess1)
	except AssertionError:
		print('sess1 uses new process order,sess old')
		raise
Exemplo n.º 3
0
def test_replay_for_same_results():
	pa=os.getcwd()
	config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	config_path=os.path.join(pa,config_name)
	
	environ_dic=yamlLoad(config_path)
	environ_dic['end_time']=50
	
	sess=Market_session(**environ_dic)
	sess1=copy.deepcopy(sess)
	sess.simulate(sess.trade_stats_df3,recording=True)
	
	reset_trader_class_variables(sess1)
	
	sess1.simulate(sess1.trade_stats_df3,replay_vars=sess.replay_vars,recording=True)
	
	assert identical_replay_vars(sess,sess1)=={}
	assert (sess1.df.fillna(0)==sess.df.fillna(0)).all().all()
Exemplo n.º 4
0
def build_df_from_yaml(path):
    ## builds a df from a yaml file containing any number of sub dictionaries
    #of the form {'tid':[],'otype':[],'price':[],'qty':[],'time':[],'qid':[]}
    #typically but not necessarily one dictionary for bids, one for asks.

    necessary_cols = ['tid', 'otype', 'price', 'qty', 'time', 'qid']

    dic = yamlLoad(path)

    try:
        for _, k in dic.items():
            for col in necessary_cols:
                assert col in k
    except AssertionError:
        print('All of ', necessary_cols, ' must be in each sub dictionary')

    order_df = build_df_from_dic_dic(dic)
    order_df = order_df[necessary_cols]

    return order_df
Exemplo n.º 5
0
def test_multi_q_exchange():
	pa=os.getcwd()
	config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	config_path=os.path.join(pa,config_name)
	
	environ_dic=yamlLoad(config_path)
	environ_dic['end_time']=50
	environ_dic['trader_record']=True 
	
	def geometric_q():
		return np.random.geometric(0.6)
		
	environ_dic['quantity_f']=geometric_q
	
	sess=Market_session(**environ_dic)
	
	sess1=copy.deepcopy(sess)
	try:
		side_by_side_period_by_period_difference_checker(sess,sess1)
	except AssertionError:
		print('multi q exchange failure')
		raise
		
	_test_trader_attributes(sess)
Exemplo n.º 6
0
def test_multi_q_exchange_order_quantity():
	#this one checks that no trades are executed more than the original order specified
	pa=os.getcwd()
	config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	config_path=os.path.join(pa,config_name)
	
	environ_dic=yamlLoad(config_path)
	environ_dic['end_time']=50
	
	def geometric_q():
		return np.random.geometric(0.6)
		
	environ_dic['quantity_f']=geometric_q
	
	sess=Market_session(**environ_dic)
	
	
	sess.simulate()
		
	listy=[]
	for t in sess.traders:
		listy=listy+sess.traders[t].blotter

	#listy[0]
		
	df=pd.DataFrame(listy).groupby(['tid','oid']).agg({'order qty':'max','qty':'sum'})
	assert (df.qty<=df['order qty']).all()
	
	

		
		
	
# def test_trade_stats_methods():
	# #checks to see if the df is the same as the old fashioned csv print method
	# pa=os.getcwd()
	# config_name='UCLSE\\test\\fixtures\\mkt_cfg.yml'
	# config_path=os.path.join(pa,config_name)
	
	# environ_dic=yamlLoad(config_path)
	# environ_dic['end_time']=50


	# sess=Market_session(**environ_dic)
	# sess1=copy.deepcopy(sess)

	# sess.simulate(sess.trade_stats_df3,recording=True)
	# reset_trader_class_variables(sess1)
	# sess1.simulate(sess1.trade_stats,replay_vars=sess.replay_vars,recording=True)

	# cols=pd.MultiIndex(levels=[['GVWY', 'SHVR', 'ZIC', 'ZIP', 'best_ask', 'best_bid', 'expid', 'time'], ['', 'balance_sum', 'n', 'pc']],
			   # codes=[[6, 7, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 5, 4], [0, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0, 0]])
	# d=pd.read_csv(environ_dic['trade_file'],header=None,usecols=[0,1,3,4,5,7,8,9,11,12,13,15,16,17,18,19])
	# d.columns=cols
	# #the csv method truncates accuracy of time value
	# d.set_index(sess.df.index,inplace=True)


	# cols=pd.MultiIndex(levels=[['GVWY', 'SHVR', 'ZIC', 'ZIP', 'best_ask', 'best_bid'], ['', 'balance_sum', 'n', 'pc']],
			   # codes=[[ 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 5, 4], [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 0, 0]])

	# #check the data is the same
	# assert (d[cols].replace(' N',0).astype('float64')==sess.df[cols].fillna(0)).all().all()

	# #check the time periods are the same
	# assert np.allclose(d.index.values-sess.df.index.values,np.zeros(d.index.values.shape))