def setUp(self): mongo_connstr = 'mongodb://localhost:27017/' mongo_db_name = 'tmldb' assetindex = AssetIndexMongo(mongo_connstr, mongo_db_name) self.date = datetime(2014, 1, 6, 10, 15, 0) futures_limit = 3 options_limit = 10 self.datasource = DataSourceMongo(mongo_connstr, mongo_db_name, assetindex, self.date, futures_limit, options_limit) server = 'h9ggwlagd1.database.windows.net' user = '******' password = '******'
def test_real_world_debug(self): return assetindex = AssetIndexMongo(MONGO_CONNSTR, MONGO_EXO_DB) storage = EXOStorage(MONGO_CONNSTR, MONGO_EXO_DB) # datasource = DataSourceSQL(SQL_HOST, SQL_USER, SQL_PASS, assetindex, futures_limit=10, options_limit=10) datasource = DataSourceMongo(MONGO_CONNSTR, MONGO_EXO_DB, assetindex, futures_limit=10, options_limit=10, exostorage=storage) exmgr = ExecutionManager(MONGO_CONNSTR, datasource, dbname=MONGO_EXO_DB) positions = exmgr.account_positions_process(write_to_db=False)
] if __name__ == "__main__": mongo_connstr = 'mongodb://*****:*****@10.0.1.2/tmldb?authMechanism=SCRAM-SHA-1' mongo_db_name = 'tmldb' assetindex = AssetIndexMongo(mongo_connstr, mongo_db_name) exostorage = EXOStorage(mongo_connstr, mongo_db_name) base_date = datetime(2014, 1, 13, 12, 45, 0) futures_limit = 3 options_limit = 10 DEBUG = '.' datasource = DataSourceMongo(mongo_connstr, mongo_db_name, assetindex, futures_limit, options_limit, exostorage) server = 'h9ggwlagd1.database.windows.net' user = '******' password = '******' datasource = DataSourceSQL(server, user, password, assetindex, futures_limit, options_limit, exostorage) enddate = datetime.combine(datetime.now().date(), dttime(12, 45, 0)) currdate = base_date instruments = ['CL', 'ES'] directions = [1, -1] # for i in range(100): while currdate <= enddate:
except ImportError: pass pass mongo_db_name = 'tmldb' assetindex = AssetIndexMongo(MONGO_CONNSTR, mongo_db_name) exostorage = EXOStorage(MONGO_CONNSTR, mongo_db_name) base_date = datetime(2011, 3, 1, 10, 15, 0) futures_limit = 3 options_limit = 10 DEBUG = '.' datasource = DataSourceMongo(MONGO_CONNSTR, mongo_db_name, assetindex, futures_limit, options_limit, exostorage) server = 'h9ggwlagd1.database.windows.net' user = '******' password = '******' datasource = DataSourceSQL(server, user, password, assetindex, futures_limit, options_limit, exostorage) enddate = datetime.combine(datetime.now().date(), dttime(10, 15, 0)) currdate = base_date #for i in range(100): while currdate <= enddate: start_time = time.time() #date = base_date + timedelta(days=i) date = currdate
def main(args, loglevel): if args.logfile == '': logging.basicConfig( stream=sys.stdout, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=loglevel) else: logging.basicConfig( filename=args.logfile, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=loglevel) signalapp = SignalApp("AlphaRebalancer", APPCLASS_ALPHA, RABBIT_HOST, RABBIT_USER, RABBIT_PASSW) signalapp.send(MsgStatus('INIT', 'Initiating alpha rebalancer script')) #exo_names = get_exo_names_mat() logging.getLogger("pika").setLevel(logging.WARNING) logging.info("Starting...") exo_storage = EXOStorage(MONGO_CONNSTR, MONGO_EXO_DB) exo_names = exo_storage.exo_list() for exo in exo_names: logging.info("Processing EXO: " + exo) # Load alpha modules to process for module in os.listdir('alphas'): # # Custom EXO folder found # swm = None context = None if module.lower() == exo.lower() and os.path.isdir( os.path.join('alphas', module)): for custom_file in os.listdir(os.path.join('alphas', module)): if 'alpha_' in custom_file and '.py' in custom_file: logging.debug( 'Processing custom module: ' + os.path.join('alphas', module, custom_file)) try: m = importlib.import_module( 'scripts.alphas.{0}.{1}'.format( module, custom_file.replace('.py', ''))) context = m.STRATEGY_CONTEXT context['strategy']['exo_name'] = exo context['strategy'][ 'suffix'] = m.STRATEGY_SUFFIX + 'custom' context['strategy']['exo_storage'] = exo_storage logging.info( 'Running CUSTOM alpha: ' + Swarm.get_name( m.STRATEGY_CONTEXT, m.STRATEGY_SUFFIX)) if 'exo_name' in context['strategy'] and context[ 'strategy']['exo_name'] != exo: logging.error( "Custom strategy context exo_name != current EXO name (folder mismatch?)" ) raise ValueError( "Custom strategy context exo_name != current EXO name (folder mismatch?)" ) swm = Swarm(context) swm.run_swarm() swm.pick() # # Saving last EXO state to online DB # swmonline = SwarmOnlineManager( MONGO_CONNSTR, MONGO_EXO_DB, m.STRATEGY_CONTEXT) logging.debug('Saving: {0}'.format(swm.name)) swmonline.save(swm) except: logging.exception('Exception occurred:') signalapp.send( MsgStatus('ERROR', 'Exception in {0}'.format( Swarm.get_name( m.STRATEGY_CONTEXT, m.STRATEGY_SUFFIX)), notify=True)) elif 'alpha_' in module and '.py' in module: logging.debug('Processing generic module: ' + module) try: m = importlib.import_module('scripts.alphas.{0}'.format( module.replace('.py', ''))) for direction in [-1, 1]: context = m.STRATEGY_CONTEXT context['strategy']['exo_name'] = exo context['strategy']['opt_params'][0] = OptParamArray( 'Direction', [direction]) context['strategy']['suffix'] = m.STRATEGY_SUFFIX context['strategy']['exo_storage'] = exo_storage logging.info('Running alpha: ' + Swarm.get_name(m.STRATEGY_CONTEXT) + ' Direction: {0}'.format(direction)) swm = Swarm(context) swm.run_swarm() swm.pick() # # Saving last EXO state to online DB # swmonline = SwarmOnlineManager(MONGO_CONNSTR, MONGO_EXO_DB, m.STRATEGY_CONTEXT) logging.debug('Saving: {0}'.format(swm.name)) swmonline.save(swm) except: logging.exception('Exception occurred:') signalapp.send( MsgStatus('ERROR', 'Exception in {0}'.format( Swarm.get_name(m.STRATEGY_CONTEXT, m.STRATEGY_SUFFIX)), notify=True)) logging.info("Processing accounts positions") assetindex = AssetIndexMongo(MONGO_CONNSTR, MONGO_EXO_DB) datasource = DataSourceMongo(MONGO_CONNSTR, MONGO_EXO_DB, assetindex, futures_limit=10, options_limit=10, exostorage=exo_storage) exmgr = ExecutionManager(MONGO_CONNSTR, datasource, dbname=MONGO_EXO_DB) exmgr.account_positions_process(write_to_db=True) signalapp.send(MsgStatus('DONE', 'Alpha rebalancer script', notify=True)) logging.info("Done.")